Skip to content

Commit efd3816

Browse files
authored
Merge pull request #1203 from DEVTomatoCake/fix/no-auth-routes-head-requests
Fix HEAD requests for no authorization routes
2 parents 8c3eec8 + 860e636 commit efd3816

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/api/middlewares/Authentication.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const NO_AUTHORIZATION_ROUTES = [
3232
"POST /auth/reset",
3333
"GET /invites/",
3434
// Routes with a seperate auth system
35-
/POST \/webhooks\/\d+\/\w+\/?/, // no token requires auth
35+
/^(POST|HEAD) \/webhooks\/\d+\/\w+\/?/, // no token requires auth
3636
// Public information endpoints
3737
"GET /ping",
3838
"GET /gateway",
@@ -51,11 +51,11 @@ export const NO_AUTHORIZATION_ROUTES = [
5151
// Oauth callback
5252
"/oauth2/callback",
5353
// Asset delivery
54-
/GET \/guilds\/\d+\/widget\.(json|png)/,
54+
/^(GET|HEAD) \/guilds\/\d+\/widget\.(json|png)/,
5555
// Connections
56-
/POST \/connections\/\w+\/callback/,
56+
/^(POST|HEAD) \/connections\/\w+\/callback/,
5757
// Image proxy
58-
/GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
58+
/^(GET|HEAD) \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
5959
];
6060

6161
export const API_PREFIX = /^\/api(\/v\d+)?/;
@@ -82,6 +82,12 @@ export async function Authentication(
8282
const url = req.url.replace(API_PREFIX, "");
8383
if (
8484
NO_AUTHORIZATION_ROUTES.some((x) => {
85+
if (req.method == "HEAD") {
86+
if (typeof x === "string")
87+
return url.startsWith(x.split(" ").slice(1).join(" "));
88+
return x.test(req.method + " " + url);
89+
}
90+
8591
if (typeof x === "string")
8692
return (req.method + " " + url).startsWith(x);
8793
return x.test(req.method + " " + url);

0 commit comments

Comments
 (0)