Add protection against directory traversal attacks
This commit is contained in:
parent
1cb7cc9bf4
commit
64cb8c6b98
@ -80,7 +80,11 @@ WebServer.prototype = {
|
|||||||
_handler: function (req, res) {
|
_handler: function (req, res) {
|
||||||
var url = req.url.replace(/\/\//g, '/');
|
var url = req.url.replace(/\/\//g, '/');
|
||||||
var urlParts = /([^?]*)((?:\?(.*))?)/.exec(url);
|
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 verbose = this.verbose;
|
||||||
|
|
||||||
var methodHooks = this.hooks[req.method];
|
var methodHooks = this.hooks[req.method];
|
||||||
|
Loading…
Reference in New Issue
Block a user