diff --git a/package.json b/package.json index 069e0e7..86b9169 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-core", - "version": "0.10.23", + "version": "0.10.24", "description": "Node web framework", "repository": "git@gitlab.com:ArisuOngaku/wms-core.git", "author": "Alice Gaudon ", diff --git a/src/components/CsrfProtectionComponent.ts b/src/components/CsrfProtectionComponent.ts index 780d299..5650a57 100644 --- a/src/components/CsrfProtectionComponent.ts +++ b/src/components/CsrfProtectionComponent.ts @@ -4,8 +4,18 @@ import crypto from "crypto"; import {BadRequestError} from "../HttpError"; export default class CsrfProtectionComponent extends ApplicationComponent { + private static readonly routeExcluders: ((path: string) => boolean)[] = []; + + public static addRouteExcluder(excluder: (path: string) => boolean) { + this.routeExcluders.push(excluder); + } + public async start(app: Express, router: Router): Promise { router.use(async (req, res, next) => { + for (const excluder of CsrfProtectionComponent.routeExcluders) { + if (excluder(req.path)) return next(); + } + if (!req.session) { throw new Error('Session is unavailable.'); }