Created
June 21, 2018 19:57
-
-
Save JhonatanHern/3efa2d5e51532d2f00fdcd94fca083af to your computer and use it in GitHub Desktop.
Prevention of CSRF attacks. Module intended to be used with express.js
This file contains hidden or 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
const url = require('url') | |
module.exports = (request,domainName) => { | |
console.log(request.headers) | |
if (request.headers.referer) { | |
const parsedURL = url.parse(request.headers.referer) | |
return parsedURL.hostname === domainName || | |
parsedURL.hostname === '127.0.0.1' || | |
parsedURL.hostname === 'localhost' | |
} | |
if (request.headers.origin) { | |
const parsedURL = url.parse(request.headers.origin) | |
return parsedURL.hostname === domainName || | |
parsedURL.hostname === '127.0.0.1' || | |
parsedURL.hostname === 'localhost' | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment