Created
January 21, 2017 08:22
-
-
Save arafathusayn/979451ce7ebf4372149ce7a76905d125 to your computer and use it in GitHub Desktop.
A note for NodeJS & Ajax against Cross-site Request Forgery (CSRF) using EJS & jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csrf_token = '<%= token_value %>'; // Between <%= %> is the EJS object property passed from server. | |
$("body").bind("ajaxSend", function (elm, xhr, s) { | |
if (s.type == "POST") { | |
xhr.setRequestHeader('X-CSRF-Token', csrf_token); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment