From b2391abd578bfec04fba2f15480e36717e177221 Mon Sep 17 00:00:00 2001 From: Jafar Akhondali Date: Tue, 30 Jul 2024 18:41:21 +0200 Subject: [PATCH] Block malicious looking requests to prevent path traversal attacks. --- server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server.js b/server.js index 62601c4..88fbe8a 100644 --- a/server.js +++ b/server.js @@ -24,6 +24,11 @@ var config = require("./config.js"), // static http server var httpServer = http.createServer(function(request, response) { + if (path.normalize(decodeURI(request.url)) !== decodeURI(request.url)) { + response.statusCode = 403; + response.end(); + return; + } var uri = url.parse(request.url).pathname , filename = path.join(process.cwd(), 'public', uri);