csrf-lite
CSRF protection utility for framework-free node sites.
Usage
var csrf = ;var Cookies = ;var qs = ; http { res;} { // note: this won't work for req; var data = ''; req; req;}
csrf(token)
If a token is supplied, then returns it. If not, then it generates a 192-bit random string and returns that.
Make sure that you stash the token somewhere like a session or something, so that it can be retrieved later.
csrf.html(token)
Returns an <input>
field containing the token, for csrf validation
in forms.
If no token is provided, then it returns nothing.
csrf.validate(data, token)
Validates that the x-csrf-token
field is equal to the token. Call this
with the parsed form data on the other side. Can also be used on
request headers, query string, or any other random data.