From d257d4c17816cd2875afe91e4c7d46eed9c87f16 Mon Sep 17 00:00:00 2001 From: Jafar Akhondali Date: Fri, 26 Jul 2024 05:32:44 +0200 Subject: [PATCH] Block malicious looking requests to prevent path traversal attacks. --- static.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/static.js b/static.js index e9f69e6..93e12d6 100755 --- a/static.js +++ b/static.js @@ -30,6 +30,11 @@ if (allowSave) console.warn("writing files from browser is enabled"); http.createServer(function(req, res) { + if (path.normalize(unescape(req.url)) !== unescape(req.url)) { + res.statusCode = 403; + res.end(); + return; + } var uri = unescape(url.parse(req.url).pathname); var filename = path.join(process.cwd(), uri);