Skip to content

Commit

Permalink
Merge pull request #10304 from april/master
Browse files Browse the repository at this point in the history
Add protection against directory traversal attacks
  • Loading branch information
timvandermeij authored Dec 10, 2018
2 parents 45c0197 + 64cb8c6 commit 2f4c7e0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ WebServer.prototype = {
_handler: function (req, res) {
var url = req.url.replace(/\/\//g, '/');
var urlParts = /([^?]*)((?:\?(.*))?)/.exec(url);
var pathPart = decodeURI(urlParts[1]), queryPart = urlParts[3];
// guard against directory traversal attacks,
// e.g. /../../../../../../../etc/passwd
// which let you make GET requests for files outside of this.root
var pathPart = path.normalize(decodeURI(urlParts[1]));
var queryPart = urlParts[3];
var verbose = this.verbose;

var methodHooks = this.hooks[req.method];
Expand Down

0 comments on commit 2f4c7e0

Please sign in to comment.