Skip to content

Commit af70bab

Browse files
committed
feat: removed CSRF support (deprecated as we use SameSite lax, see <https://scotthelme.co.uk/csrf-is-dead/>)
1 parent 80c46ee commit af70bab

File tree

2 files changed

+0
-35
lines changed

2 files changed

+0
-35
lines changed

index.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const path = require('node:path');
55
const util = require('node:util');
66
const zlib = require('node:zlib');
77

8-
const Boom = require('@hapi/boom');
9-
const CSRF = require('koa-csrf');
108
const Cabin = require('cabin');
119
const CacheResponses = require('@ladjs/koa-cache-responses');
1210
const I18N = require('@ladjs/i18n');
@@ -65,8 +63,6 @@ const reportUri = isSANB(process.env.WEB_URL)
6563
? `${process.env.WEB_URL}/report`
6664
: null;
6765

68-
const INVALID_TOKEN_MESSAGE = 'Invalid CSRF token.';
69-
7066
class Web {
7167
// eslint-disable-next-line complexity
7268
constructor(config, Users) {
@@ -81,19 +77,6 @@ class Web {
8177
extension: 'pug'
8278
}
8379
},
84-
csrf: {
85-
...sharedWebConfig.csrf,
86-
ignoredPathGlobs: ['/report'],
87-
errorHandler(ctx) {
88-
return ctx.throw(
89-
Boom.forbidden(
90-
typeof ctx.request.t === 'function'
91-
? ctx.request.t(INVALID_TOKEN_MESSAGE)
92-
: INVALID_TOKEN_MESSAGE
93-
)
94-
);
95-
}
96-
},
9780
rateLimit: {
9881
...sharedWebConfig.rateLimit,
9982
ignoredPathGlobs: ['/report']
@@ -368,22 +351,6 @@ class Web {
368351
if (this.config.methodOverride)
369352
app.use(methodOverride(...this.config.methodOverride));
370353

371-
// csrf (with added localization support)
372-
if (this.config.csrf && process.env.NODE_ENV !== 'test') {
373-
const csrf = new CSRF(this.config.csrf);
374-
app.use(async (ctx, next) => {
375-
try {
376-
await csrf(ctx, next);
377-
} catch (err) {
378-
let error = err;
379-
if (err.name && err.name === 'ForbiddenError')
380-
error = Boom.forbidden(err.message);
381-
382-
ctx.throw(error);
383-
}
384-
});
385-
}
386-
387354
// passport
388355
if (this.passport) {
389356
app.use(this.passport.initialize());

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"Nick Baugh <[email protected]> (http://niftylettuce.com/)"
1212
],
1313
"dependencies": {
14-
"@hapi/boom": "^10.0.0",
1514
"@koa/router": "^12.0.0",
1615
"@ladjs/i18n": "^8.0.1",
1716
"@ladjs/koa-better-static": "^2.0.1",
@@ -38,7 +37,6 @@
3837
"koa-compress": "^5.1.0",
3938
"koa-conditional-get": "^3.0.0",
4039
"koa-connect": "^2.1.0",
41-
"koa-csrf": "^5.0.1",
4240
"koa-etag": "^4.0.0",
4341
"koa-favicon": "^2.1.0",
4442
"koa-generic-session": "^2.3.0",

0 commit comments

Comments
 (0)