Skip to content

Commit 1ab010e

Browse files
committed
Merge pull request #25 from mebjas/master-dev
Adopted hidden data field insertion, rather than creating new JS code upon config update
2 parents 242587a + fff8121 commit 1ab010e

File tree

5 files changed

+33
-433
lines changed

5 files changed

+33
-433
lines changed

js/csrfprotector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* =================================================================
1212
*/
1313

14+
var CSRFP_FIELD_TOKEN_NAME = 'csrfp_hidden_data_token';
15+
var CSRFP_FIELD_URLS = 'csrfp_hidden_data_urls';
16+
1417
var CSRFP = {
1518
CSRFP_TOKEN: 'csrfp_token',
1619
/**
@@ -140,6 +143,14 @@ var CSRFP = {
140143
* @return void
141144
*/
142145
_init: function() {
146+
CSRFP.CSRFP_TOKEN = document.getElementById(CSRFP_FIELD_TOKEN_NAME).value;
147+
try {
148+
CSRFP.checkForUrls = JSON.parse(document.getElementById(CSRFP_FIELD_URLS).value);
149+
} catch (err) {
150+
console.error(err);
151+
console.error('[ERROR] [CSRF Protector] unable to parse blacklisted url fields.');
152+
}
153+
143154
//convert these rules received from php lib to regex objects
144155
for (var i = 0; i < CSRFP.checkForUrls.length; i++) {
145156
CSRFP.checkForUrls[i] = CSRFP.checkForUrls[i].replace(/\*/g, '(.*)')
@@ -314,3 +325,7 @@ function csrfprotector_init() {
314325
}
315326

316327
}
328+
329+
window.addEventListener("DOMContentLoaded", function() {
330+
csrfprotector_init();
331+
}, false);

libs/config.sample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
Cross-Site Request Forgeries </a> attacks. In order to do so, you must have JavaScript enabled in your web browser otherwise this site will fail to work correctly for you.
2424
See details of your web browser for how to enable JavaScript.",
2525
"verifyGetFor" => array()
26-
);
26+
);

libs/csrf/csrfpJsFileBase.php

Lines changed: 0 additions & 316 deletions
This file was deleted.

0 commit comments

Comments
 (0)