From 4b02efdebaa47f792e45d6c27183e6c237025f12 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 25 Aug 2024 12:37:14 +0200 Subject: [PATCH] Add proxySafe flag to middleware. --- src/handlers/requestHandler.js | 3 +++ src/middleware/blocklist.js | 2 ++ src/middleware/checkForbiddenPaths.js | 2 ++ src/middleware/defaultHandlerChecks.js | 2 ++ src/middleware/nonStandardCodesAndHttpAuthentication.js | 2 ++ src/middleware/redirectTrailingSlashes.js | 2 ++ src/middleware/redirects.js | 2 ++ src/middleware/responseHeaders.js | 2 ++ src/middleware/rewriteURL.js | 2 ++ src/middleware/staticFileServingAndDirectoryListings.js | 2 ++ src/middleware/status.js | 2 ++ src/middleware/urlSanitizer.js | 2 ++ src/middleware/webRootPostfixes.js | 2 ++ 13 files changed, 27 insertions(+) diff --git a/src/handlers/requestHandler.js b/src/handlers/requestHandler.js index 59e041e..395e311 100644 --- a/src/handlers/requestHandler.js +++ b/src/handlers/requestHandler.js @@ -710,6 +710,9 @@ function requestHandler(req, res) { // Call the next middleware function const next = () => { const currentMiddleware = middleware[index++]; + while (req.isProxy && currentMiddleware && !currentMiddleware.proxySafe) { + currentMiddleware = middleware[index++]; + } if (currentMiddleware) { try { currentMiddleware(req, res, logFacilities, config, next); diff --git a/src/middleware/blocklist.js b/src/middleware/blocklist.js index 4859f9b..e421a2d 100644 --- a/src/middleware/blocklist.js +++ b/src/middleware/blocklist.js @@ -51,3 +51,5 @@ module.exports.commands = { } }, }; + +module.exports.proxySafe = true; diff --git a/src/middleware/checkForbiddenPaths.js b/src/middleware/checkForbiddenPaths.js index 0923a86..ed50dec 100644 --- a/src/middleware/checkForbiddenPaths.js +++ b/src/middleware/checkForbiddenPaths.js @@ -111,3 +111,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/defaultHandlerChecks.js b/src/middleware/defaultHandlerChecks.js index 8939a5e..5958cb5 100644 --- a/src/middleware/defaultHandlerChecks.js +++ b/src/middleware/defaultHandlerChecks.js @@ -37,3 +37,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index b57bed5..9f8f8ad 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -462,3 +462,5 @@ module.exports.commands = { passCommand(args, log); }, }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/redirectTrailingSlashes.js b/src/middleware/redirectTrailingSlashes.js index e36b0cc..c20dc61 100644 --- a/src/middleware/redirectTrailingSlashes.js +++ b/src/middleware/redirectTrailingSlashes.js @@ -32,3 +32,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); } }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/redirects.js b/src/middleware/redirects.js index b65ff0b..14d8ca2 100644 --- a/src/middleware/redirects.js +++ b/src/middleware/redirects.js @@ -79,3 +79,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/responseHeaders.js b/src/middleware/responseHeaders.js index 4cf6346..3b89fc7 100644 --- a/src/middleware/responseHeaders.js +++ b/src/middleware/responseHeaders.js @@ -12,3 +12,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/rewriteURL.js b/src/middleware/rewriteURL.js index 5038e6b..96c0817 100644 --- a/src/middleware/rewriteURL.js +++ b/src/middleware/rewriteURL.js @@ -153,3 +153,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/staticFileServingAndDirectoryListings.js b/src/middleware/staticFileServingAndDirectoryListings.js index b7da8bd..d184360 100644 --- a/src/middleware/staticFileServingAndDirectoryListings.js +++ b/src/middleware/staticFileServingAndDirectoryListings.js @@ -990,3 +990,5 @@ module.exports = (req, res, logFacilities, config, next) => { } }); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/status.js b/src/middleware/status.js index d275e0f..f36bba8 100644 --- a/src/middleware/status.js +++ b/src/middleware/status.js @@ -134,3 +134,5 @@ module.exports = (req, res, logFacilities, config, next) => { } next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/urlSanitizer.js b/src/middleware/urlSanitizer.js index 3acb72e..68dcab8 100644 --- a/src/middleware/urlSanitizer.js +++ b/src/middleware/urlSanitizer.js @@ -52,3 +52,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file diff --git a/src/middleware/webRootPostfixes.js b/src/middleware/webRootPostfixes.js index 7031a23..ee6dfdd 100644 --- a/src/middleware/webRootPostfixes.js +++ b/src/middleware/webRootPostfixes.js @@ -140,3 +140,5 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; + +module.exports.proxySafe = true; \ No newline at end of file