1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-08 11:52:55 +01:00

Merge pull request #1203 from DEVTomatoCake/fix/no-auth-routes-head-requests

Fix HEAD requests for no authorization routes
This commit is contained in:
Puyodead1 2024-08-30 08:52:40 -04:00 committed by GitHub
commit efd3816a59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,7 +32,7 @@ export const NO_AUTHORIZATION_ROUTES = [
"POST /auth/reset", "POST /auth/reset",
"GET /invites/", "GET /invites/",
// Routes with a seperate auth system // 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 // Public information endpoints
"GET /ping", "GET /ping",
"GET /gateway", "GET /gateway",
@ -51,11 +51,11 @@ export const NO_AUTHORIZATION_ROUTES = [
// Oauth callback // Oauth callback
"/oauth2/callback", "/oauth2/callback",
// Asset delivery // Asset delivery
/GET \/guilds\/\d+\/widget\.(json|png)/, /^(GET|HEAD) \/guilds\/\d+\/widget\.(json|png)/,
// Connections // Connections
/POST \/connections\/\w+\/callback/, /^(POST|HEAD) \/connections\/\w+\/callback/,
// Image proxy // 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+)?/; export const API_PREFIX = /^\/api(\/v\d+)?/;
@ -82,6 +82,12 @@ export async function Authentication(
const url = req.url.replace(API_PREFIX, ""); const url = req.url.replace(API_PREFIX, "");
if ( if (
NO_AUTHORIZATION_ROUTES.some((x) => { 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") if (typeof x === "string")
return (req.method + " " + url).startsWith(x); return (req.method + " " + url).startsWith(x);
return x.test(req.method + " " + url); return x.test(req.method + " " + url);