summary refs log tree commit diff
path: root/src/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'src/middlewares')
-rw-r--r--src/middlewares/Authentication.ts9
-rw-r--r--src/middlewares/CORS.ts2
-rw-r--r--src/middlewares/GlobalRateLimit.ts2
3 files changed, 7 insertions, 6 deletions
diff --git a/src/middlewares/Authentication.ts b/src/middlewares/Authentication.ts

index 0ecc1bc0..630a45ff 100644 --- a/src/middlewares/Authentication.ts +++ b/src/middlewares/Authentication.ts
@@ -1,13 +1,13 @@ import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; -import { checkToken } from "@fosscord/server-util"; +import { checkToken, Config } from "@fosscord/server-util"; export const NO_AUTHORIZATION_ROUTES = [ "/api/v8/auth/login", "/api/v8/auth/register", "/api/v8/webhooks/", "/api/v8/gateway", - "/api/v8/experiments", + "/api/v8/experiments" ]; declare global { @@ -24,10 +24,11 @@ export async function Authentication(req: Request, res: Response, next: NextFunc if (req.url.startsWith("/api/v8/invites") && req.method === "GET") return next(); if (NO_AUTHORIZATION_ROUTES.some((x) => req.url.startsWith(x))) return next(); if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401)); - // TODO: check if user is banned/token expired try { - const decoded: any = await checkToken(req.headers.authorization); + const { jwtSecret } = Config.get().security; + + const decoded: any = await checkToken(req.headers.authorization, jwtSecret); req.token = decoded; req.user_id = decoded.id; diff --git a/src/middlewares/CORS.ts b/src/middlewares/CORS.ts
index e6cc5544..88e90a4b 100644 --- a/src/middlewares/CORS.ts +++ b/src/middlewares/CORS.ts
@@ -9,7 +9,7 @@ export function CORS(req: Request, res: Response, next: NextFunction) { "Content-security-policy", "default-src * data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';" ); - res.set("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers")); + res.set("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers") || "*"); next(); } diff --git a/src/middlewares/GlobalRateLimit.ts b/src/middlewares/GlobalRateLimit.ts
index fc121911..7260d1a2 100644 --- a/src/middlewares/GlobalRateLimit.ts +++ b/src/middlewares/GlobalRateLimit.ts
@@ -1,5 +1,5 @@ import { NextFunction, Request, Response } from "express"; -import Config from "../util/Config"; +import { Config } from "@fosscord/server-util"; // TODO: use mongodb ttl index // TODO: increment count on serverside