Skip to content

Commit 563132a

Browse files
authored
Merge pull request #123 from polishdeveloper/token_rename
Fix #120 by renaming the csrfp-token to conform to header rules
2 parents 0865487 + 1c5f157 commit 563132a

8 files changed

+13
-13
lines changed

js/csrfprotector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var CSRFP_FIELD_TOKEN_NAME = 'csrfp_hidden_data_token';
1515
var CSRFP_FIELD_URLS = 'csrfp_hidden_data_urls';
1616

1717
var CSRFP = {
18-
CSRFP_TOKEN: 'csrfp_token',
18+
CSRFP_TOKEN: 'CSRFP-Token',
1919
/**
2020
* Array of patterns of url, for which csrftoken need to be added
2121
* In case of GET request also, provided from server
@@ -130,7 +130,7 @@ var CSRFP = {
130130
// Trigger the functions
131131
var result = fun.apply(this, [event]);
132132

133-
// Now append the csrfp_token back
133+
// Now append the CSRFP-Token back
134134
obj.appendChild(CSRFP._getInputElt());
135135

136136
return result;

libs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CSRFProtector configuration
22
==========================================
33

4-
- `CSRFP_TOKEN`: name of the csrf nonce, used for cookie or posting as argument. default: `csrfp_token` (if left blank)
4+
- `CSRFP_TOKEN`: name of the csrf nonce, used for cookie or posting as argument. default: `CSRFP-Token` (if left blank)
55
- `logDirectory`: location of the directory at which log files will be saved, either **relative** to the default `config.php` file location or an **absolute** path. This is required for file based logging (default), Not needed, in case you override logging function to implement your logging logic. (View [Overriding logging function](https://github.com/mebjas/CSRF-Protector-PHP/wiki/Overriding-logging-function))
66
<br>**Default value:** `../log/`
77
- `failedAuthAction`: Action code (integer) for action to be taken in case of failed validation. Has two different values for bot `GET` and `POST`. Different action codes are specified as follows, (<br>**Default:** `0` for both `GET` & `POST`):

libs/csrf/csrfprotector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
define('__CSRF_PROTECTOR__', true); // to avoid multiple declaration errors
1212

1313
// name of HTTP POST variable for authentication
14-
define("CSRFP_TOKEN","csrfp_token");
14+
define("CSRFP_TOKEN","CSRFP-Token");
1515

1616
// We insert token name and list of url patterns for which
1717
// GET requests are validated against CSRF as hidden input fields

test/config.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* ---- tokenLength
99
*/
1010
return array(
11-
"CSRFP_TOKEN" => "csrfp_token",
11+
"CSRFP_TOKEN" => "CSRFP-Token",
1212
"logDirectory" => "../log",
1313
"failedAuthAction" => array(
1414
"GET" => 0,

test/config.testInit_incompleteConfigurationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* ---- tokenLength
99
*/
1010
return array(
11-
"CSRFP_TOKEN" => "csrfp_token",
11+
"CSRFP_TOKEN" => "CSRFP-Token",
1212
// "logDirectory" => "../log",
1313
// "failedAuthAction" => array(
1414
// "GET" => 0,

test/config.testInit_withoutInjectedCSRFGuardScript.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* ---- tokenLength
99
*/
1010
return array(
11-
"CSRFP_TOKEN" => "csrfp_token",
11+
"CSRFP_TOKEN" => "CSRFP-Token",
1212
"logDirectory" => "../log",
1313
"failedAuthAction" => array(
1414
"GET" => 0,

test/csrfprotector_test.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function setUp()
9696
{
9797
$this->logDir = __DIR__ .'/logs';
9898

99-
csrfprotector::$config['CSRFP_TOKEN'] = 'csrfp_token';
99+
csrfprotector::$config['CSRFP_TOKEN'] = 'CSRFP-Token';
100100
csrfprotector::$config['cookieConfig'] = array('secure' => false);
101101
csrfprotector::$config['logDirectory'] = '../test/logs';
102102

@@ -144,7 +144,7 @@ public function testRefreshToken()
144144
$this->assertTrue(strcmp($val, $_SESSION[csrfprotector::$config['CSRFP_TOKEN']][1]) != 0);
145145

146146
$this->assertTrue(csrfP_wrapper::checkHeader('Set-Cookie'));
147-
$this->assertTrue(csrfP_wrapper::checkHeader('csrfp_token'));
147+
$this->assertTrue(csrfP_wrapper::checkHeader('CSRFP-Token'));
148148
$this->assertTrue(csrfp_wrapper::checkHeader($_SESSION[csrfprotector::$config['CSRFP_TOKEN']][1]));
149149
}
150150

@@ -398,7 +398,7 @@ public function testAuthorisePost_success()
398398
csrfprotector::authorizePost(); //will create new session and cookies
399399
$this->assertFalse($temp == $_SESSION[csrfprotector::$config['CSRFP_TOKEN']][0]);
400400
$this->assertTrue(csrfp_wrapper::checkHeader('Set-Cookie'));
401-
$this->assertTrue(csrfp_wrapper::checkHeader('csrfp_token'));
401+
$this->assertTrue(csrfp_wrapper::checkHeader('CSRFP-Token'));
402402
// $this->assertTrue(csrfp_wrapper::checkHeader($_SESSION[csrfprotector::$config['CSRFP_TOKEN']][0])); // Combine these 3 later
403403

404404
// For get method
@@ -412,7 +412,7 @@ public function testAuthorisePost_success()
412412
csrfprotector::authorizePost(); //will create new session and cookies
413413
$this->assertFalse($temp == $_SESSION[csrfprotector::$config['CSRFP_TOKEN']]);
414414
$this->assertTrue(csrfp_wrapper::checkHeader('Set-Cookie'));
415-
$this->assertTrue(csrfp_wrapper::checkHeader('csrfp_token'));
415+
$this->assertTrue(csrfp_wrapper::checkHeader('CSRFP-Token'));
416416
// $this->assertTrue(csrfp_wrapper::checkHeader($_SESSION[csrfprotector::$config['CSRFP_TOKEN']][0])); // Combine these 3 later
417417
}
418418

@@ -439,7 +439,7 @@ public function testAuthorisePost_success_2()
439439
csrfprotector::authorizePost(); //will create new session and cookies
440440
$this->assertFalse($temp == $_SESSION[csrfprotector::$config['CSRFP_TOKEN']][0]);
441441
$this->assertTrue(csrfp_wrapper::checkHeader('Set-Cookie'));
442-
$this->assertTrue(csrfp_wrapper::checkHeader('csrfp_token'));
442+
$this->assertTrue(csrfp_wrapper::checkHeader('CSRFP-Token'));
443443
// $this->assertTrue(csrfp_wrapper::checkHeader($_SESSION[csrfprotector::$config['CSRFP_TOKEN']][0])); // Combine these 3 later
444444

445445
}

test/csrfprotector_test_customlogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class csrfp_test_customLogger extends PHPUnit_Framework_TestCase
2424
protected $config = array();
2525

2626
public function setUp() {
27-
csrfprotector::$config['CSRFP_TOKEN'] = 'csrfp_token';
27+
csrfprotector::$config['CSRFP_TOKEN'] = 'CSRFP-Token';
2828
csrfprotector::$config['cookieConfig'] = array('secure' => false);
2929
csrfprotector::$config['logDirectory'] = '../test/logs';
3030
$_SERVER['REQUEST_URI'] = 'temp'; // For logging

0 commit comments

Comments
 (0)