Skip to content

Instantly share code, notes, and snippets.

@arafathusayn
Created January 21, 2017 08:22
Show Gist options
  • Save arafathusayn/979451ce7ebf4372149ce7a76905d125 to your computer and use it in GitHub Desktop.
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
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