-
Notifications
You must be signed in to change notification settings - Fork 88
Documentation CSRF Protector php library
Purpose:
This class contains all functions (static) needed to validate incoming requests and inject scripts to ongoing HTML output.
Uses/Interactions:
This class is invoked at the beginning of each php file, in which user expects to implement CSRF protection.
Dependencies:
The library requires a configuration file at a location relative to location of the library file. No other dependency!.
Note:All following methods will be static as we do not need to create an object of this class!
public static $cookieExpiryTime
expiry time for cookie @var int
private static $isSameOrigin
flag for cross origin/same origin request @var bool
private static $isValidHTML
flag to check if output file is a valid HTML or not @var bool
protected static $requestType
Varaible to store weather request type is post or get @var string
public static $config
config file for CSRFProtector @var int Array, length = 6 Property: #1: failedAuthAction (int) => action to be taken in case autherisation fails Property: #2: logDirectory (string) => directory in which log will be saved Property: #3: customErrorMessage (string) => custom error message to be sent in case of failed authentication Property: #4: jsFile (string) => location of the CSRFProtector js file Property: #5: tokenLength (int) => default length of hash Property: #6: disabledJavascriptMessage (string) => error message if client’s js is disabled
public static function init( $length = null,
$action = null )
function to initialise the csrfProtector work flow
$length length of CSRF_AUTH_TOKEN to be generated
$action int array, for different actions to be taken in case of failed validation
void
configFileNotFoundException when configuration file is not found
public static function useCachedVersion()
function to check weather to use cached version of js file or not
void
bool -- true if cacheversion can be used -- false otherwise
public static function createNewJsCache()
Function to create new cache version of js
void
void
baseJSFileNotFoundExceptio if baseJsFile is not found
public static function authorisePost()
function to authorise incoming post requests
void
void
logDirectoryNotFoundException if log directory is not found
private static function failedValidationAction()
function to be called in case of failed validation performs logging and take appropriate action
void
void
public static function refreshToken()
Function to set auth cookie
void
void
public static function generateAuthToken()
function to generate random hash of length as given in parameter max length = 128
length to hash required, int
string, token
public static function ob_handler( $buffer,
$flags )
Rewrites <form> on the fly to add CSRF tokens to them. This can also inject our JavaScript library.
$buffer output buffer to which all output are stored
$flag INT
string, complete output buffer
private static function logCSRFattack()
Functio to log CSRF Attack
void
void
logFileWriteError if unable to log an attack
private static function getCurrentUrl()
Function to return current url of executing page
void
string current url
public static function isURLallowed()
Function to check if a url mataches for any urls Listed in config file
void
boolean true is url need no validation, false if validation needed
PS: wiki still under development. Please create a Github issue for any correction.