Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HEAD requests for no authorization routes #1203

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/api/middlewares/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const NO_AUTHORIZATION_ROUTES = [
"POST /auth/reset",
"GET /invites/",
// Routes with a seperate auth system
/POST \/webhooks\/\d+\/\w+\/?/, // no token requires auth
/^(POST|HEAD) \/webhooks\/\d+\/\w+\/?/, // no token requires auth
// Public information endpoints
"GET /ping",
"GET /gateway",
Expand All @@ -51,11 +51,11 @@ export const NO_AUTHORIZATION_ROUTES = [
// Oauth callback
"/oauth2/callback",
// Asset delivery
/GET \/guilds\/\d+\/widget\.(json|png)/,
/^(GET|HEAD) \/guilds\/\d+\/widget\.(json|png)/,
// Connections
/POST \/connections\/\w+\/callback/,
/^(POST|HEAD) \/connections\/\w+\/callback/,
// Image proxy
/GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
/^(GET|HEAD) \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
];

export const API_PREFIX = /^\/api(\/v\d+)?/;
Expand All @@ -82,6 +82,12 @@ 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(" "));
return x.test(req.method + " " + url);
}

if (typeof x === "string")
return (req.method + " " + url).startsWith(x);
return x.test(req.method + " " + url);
Expand Down
Loading