Skip to content

Commit 3e5313d

Browse files
committed
build(dev-app): prevent directory traversal
1 parent fd1593d commit 3e5313d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tools/dev-server/dev-server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DevServer {
2727
port: this.port,
2828
notify: false,
2929
ghostMode: false,
30-
server: true,
30+
server: false,
3131
middleware: (req, res) => this._bazelMiddleware(req, res),
3232
};
3333

@@ -59,7 +59,14 @@ export class DevServer {
5959
*/
6060
private _bazelMiddleware(req: http.IncomingMessage, res: http.ServerResponse) {
6161
if (!req.url) {
62-
res.end('No url specified. Error');
62+
res.end('Error: No url specified');
63+
return;
64+
}
65+
66+
// Throw an error if the requested URL contains two consecutive `.` characters
67+
// (%2e is `.` url-encoded).
68+
if (/(\.|%2e){2,}/.test(req.url)) {
69+
res.end('Error: Detected directory traversal');
6370
return;
6471
}
6572

0 commit comments

Comments
 (0)