Created
January 11, 2013 16:37
-
-
Save edinella/4512106 to your computer and use it in GitHub Desktop.
A JSON Vulnerability (http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx) allows third party web-site to turn your JSON resource URL into JSONP request under some conditions. To counter this your http://expressjs.com/ server can allow only xhr requisitions with this middleware.
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
app.all('/path/to/api/*', function xhrOnly(req, res, next) { | |
if (req.xhr) next(); | |
else res.send(403, 'XHR requests only, please'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment