diff --git a/.gitignore b/.gitignore index 21484c4..685b296 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ phpunit.phar -coverage/* \ No newline at end of file +coveralls.phar + +coverage/ +vendor/ +build/ +log/*.log diff --git a/js/csrfprotector.js b/js/csrfprotector.js index 0d22955..b339c56 100644 --- a/js/csrfprotector.js +++ b/js/csrfprotector.js @@ -20,16 +20,16 @@ var CSRFP = { * Array of patterns of url, for which csrftoken need to be added * In case of GET request also, provided from server * - * @var string array + * @var {Array} */ checkForUrls: [], /** * Function to check if a certain url is allowed to perform the request * With or without csrf token * - * @param: string, url + * @param {string} url * - * @return: boolean, true if csrftoken is not needed + * @return {Boolean} true if csrftoken is not needed * false if csrftoken is needed */ _isValidGetRequest: function(url) { @@ -41,12 +41,12 @@ var CSRFP = { } return true; }, - /** - * function to get Auth key from cookie Andreturn it to requesting function + /** + * Function to get Auth key from cookie and return it to requesting function * * @param: void * - * @return: string, csrftoken retrieved from cookie + * @return {string|Boolean} csrftoken retrieved from cookie */ _getAuthKey: function() { var re = new RegExp(CSRFP.CSRFP_TOKEN +"=([^;]+)(;|$)"); @@ -60,9 +60,9 @@ var CSRFP = { /** * Function to get domain of any url * - * @param: string, url + * @param {string} url * - * @return: string, domain of url + * @return {string} domain of url */ _getDomain: function(url) { if (url.indexOf("http://") !== 0 @@ -72,11 +72,11 @@ var CSRFP = { }, /** * Function to create and return a hidden input element - * For stroing the CSRFP_TOKEN + * For storing the CSRFP_TOKEN * - * @param void + * @param: void * - * @return input element + * @return {HTMLInputElement} input element */ _getInputElt: function() { var hiddenObj = document.createElement("input"); @@ -88,11 +88,11 @@ var CSRFP = { }, /** * Returns absolute path for relative path - * - * @param base, base url - * @param relative, relative url * - * @return absolute path (string) + * @param {string} base base url + * @param {string} relative relative url + * + * @return {string} absolute path */ _getAbsolutePath: function(base, relative) { var stack = base.split("/"); @@ -102,22 +102,22 @@ var CSRFP = { stack.pop(); for (var i = 0; i < parts.length; i++) { - if (parts[i] == ".") + if (parts[i] === ".") continue; - if (parts[i] == "..") + if (parts[i] === "..") stack.pop(); else stack.push(parts[i]); } return stack.join("/"); }, - /** - * Remove jcsrfp-token run fun and then put them back + /** + * Remove jcsrfp-token run fun and then put them back * - * @param function - * @param reference form obj + * @param {function} fun + * @param {object} obj reference form obj * - * @retrun function + * @return function */ _csrfpWrap: function(fun, obj) { return function(event) { @@ -139,7 +139,7 @@ var CSRFP = { /** * Initialises the CSRFProtector js script * - * @param void + * @param: void * * @return void */ @@ -169,7 +169,7 @@ var CSRFP = { function csrfprotector_init() { - // Call the init funcion + // Call the init function CSRFP._init(); // definition of basic FORM submit event handler to intercept the form request @@ -181,7 +181,7 @@ function csrfprotector_init() { //modify token to latest value event.target[CSRFP.CSRFP_TOKEN].value = CSRFP._getAuthKey(); } - } + }; //================================================================== // Adding csrftoken to request resulting from
tag + $buffer = preg_replace("/]*>/", "$0 ", $buffer); + + $hiddenInput = '' .PHP_EOL; + + $hiddenInput .= ''; + + //implant hidden fields with check url information for reading in javascript + $buffer = str_ireplace('', $hiddenInput . '', $buffer); + + if (self::$config['jsUrl']) { + //implant the CSRFGuard js file to outgoing script + $script = ''; + $buffer = str_ireplace('