summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2025-09-05 17:47:42 -0400
committerPuyodead1 <puyodead@proton.me>2025-09-05 17:47:42 -0400
commit5fafb6d156c539f6a99c0f4f8ce1f9c2820efe53 (patch)
tree564a9788969ccd2f9ce782168c0df50d5c74f58f /src/api
parentAdd automod migration (diff)
downloadserver-ts-5fafb6d156c539f6a99c0f4f8ce1f9c2820efe53.tar.xz
fix an issue with NO_AUTHENTICATE routes
Diffstat (limited to 'src/api')
-rw-r--r--src/api/middlewares/Authentication.ts23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts

index f0f01252d..b297a40c1 100644 --- a/src/api/middlewares/Authentication.ts +++ b/src/api/middlewares/Authentication.ts
@@ -82,15 +82,26 @@ export async function Authentication( const url = req.url.replace(API_PREFIX, ""); if ( NO_AUTHORIZATION_ROUTES.some((x) => { - if (req.method == "HEAD") { - if (typeof x === "string") - return url.startsWith(x.split(" ").slice(1).join(" ")); + if (typeof x !== "string") { return x.test(req.method + " " + url); } - if (typeof x === "string") - return (req.method + " " + url).startsWith(x); - return x.test(req.method + " " + url); + const fullRoute = req.method + " " + url; + + if (req.method === "HEAD") { + const urlPart = x.split(" ").slice(1).join(" "); + if (urlPart.endsWith("/")) { + return url.startsWith(urlPart); + } else { + return url === urlPart; + } + } + + if (x.endsWith("/")) { + return fullRoute.startsWith(x); + } else { + return fullRoute === x; + } }) ) return next();