From 86842546a8aad3d5fb43e614a795d62e2c13e657 Mon Sep 17 00:00:00 2001 From: Mhykol Date: Sun, 12 Jan 2025 23:48:54 -0500 Subject: Fixed decoding for malformed URLs --- app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app.js') diff --git a/app.js b/app.js index 68ca3cf..d027f05 100644 --- a/app.js +++ b/app.js @@ -59,6 +59,18 @@ class App { app.use(helmet()) app.use(limiter) } + app.use((req, res, next) => { + let err = null + try { + decodeURIComponent(req.path) + } catch(e) { + err = e + } + if (err){ + return res.redirect(['http://', req.get('Host'), '/404'].join('')) + } + next() + }) app.route('*') .get(this.#ValidateCookie, this.#Logger, (req, res) => { @@ -169,6 +181,9 @@ class App { } }) }) + .all((req, res, next) => { + res.send('Other requests called'); + }) app.listen(3000) } -- cgit v1.2.3-70-g09d2