Closed
Description
Hello,
It took me a lot of time to debug why my implementation was failing.
I've found that in the validateRequest function, the cookie is being split into token and hash, but the header content its not. I don't know if this is intentional or should I send the header without the hash from the front.
https://github.com/Psifi-Solutions/csrf-csrf/blob/v3.x.x/src/index.ts#L160
I've fixed with this configuration:
doubleCsrf({
getSecret: () => configService.getOrThrow('csrf.secret'),
getTokenFromRequest: (request) => {
return String(request.headers['x-xsrf-token']).split('|')[0];
},
cookieName: 'XSRF-TOKEN',
cookieOptions: {
sameSite: 'lax',
httpOnly: false,
path: '/',
secure: configService.getOrThrow('csrf.cookie.secure'),
maxAge: configService.getOrThrow('csrf.cookie.maxAge'),
},
});
But using String(request.headers['x-xsrf-token']).split('|')[0];
doesn't feel right.
Is this intentional or am I missing something?
Metadata
Metadata
Assignees
Labels
No labels