forked from angular-app/angular-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(server): move protectJSON middleware into its own file
- Loading branch information
1 parent
0bce177
commit 8166a7a
Showing
2 changed files
with
25 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// JSON vulnerability protection | ||
// we prepend the data with ")]},\n", which will be stripped by $http in AngularJS | ||
module.exports = function(req, res, next) { | ||
var _send = res.send; | ||
res.send = function(body) { | ||
var contentType = res.getHeader('Content-Type'); | ||
if ( contentType && contentType.indexOf('application/json') !== -1 ) { | ||
if (2 == arguments.length) { | ||
// res.send(body, status) backwards compat | ||
if ('number' != typeof body && 'number' == typeof arguments[1]) { | ||
this.statusCode = arguments[1]; | ||
} else { | ||
this.statusCode = body; | ||
body = arguments[1]; | ||
} | ||
} | ||
body = ")]}',\n" + body; | ||
return _send.call(res, body); | ||
} | ||
_send.apply(res, arguments); | ||
}; | ||
next(); | ||
}; |
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