Merge pull request #10447 from timvandermeij/bad-request
Handle malformed URIs as bad requests in the development webserver
This commit is contained in:
commit
5efc902fb8
@ -80,10 +80,19 @@ WebServer.prototype = {
|
||||
_handler: function (req, res) {
|
||||
var url = req.url.replace(/\/\//g, '/');
|
||||
var urlParts = /([^?]*)((?:\?(.*))?)/.exec(url);
|
||||
// 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]));
|
||||
try {
|
||||
// Guard against directory traversal attacks such as
|
||||
// `/../../../../../../../etc/passwd`, which let you make GET requests
|
||||
// for files outside of `this.root`.
|
||||
var pathPart = path.normalize(decodeURI(urlParts[1]));
|
||||
} catch (ex) {
|
||||
// If the URI cannot be decoded, a `URIError` is thrown. This happens for
|
||||
// malformed URIs such as `http://localhost:8888/%s%s` and should be
|
||||
// handled as a bad request.
|
||||
res.writeHead(400);
|
||||
res.end('Bad request', 'utf8');
|
||||
return;
|
||||
}
|
||||
var queryPart = urlParts[3];
|
||||
var verbose = this.verbose;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user