Skip to content

[V3] CookieFrom request and TokenFromRequest doesn't have the same form #88

Closed
@chemisax

Description

@chemisax

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions