Skip to content

Missing CSRF protection on stateful cookie-based authentication endpoints #379

Description

@anshul23102

Summary

The refresh token is stored in an httpOnly cookie. However, the /auth/refresh and /auth/logout endpoints do not verify a CSRF token. A malicious page on another origin can trigger a cross-site POST that causes the browser to send the httpOnly cookie automatically, allowing:

  • Forced logout (CSRF on /logout)
  • Unauthorized token refresh if the response leaks the new access token in a CORS-permitted response

Impact

  • Denial-of-service via forced logout.
  • Potential token leakage if CORS Access-Control-Allow-Origin is overly permissive.

Suggested Fix

Add SameSite=Strict (or Lax) to the refresh token cookie, and additionally validate a X-CSRF-Token header on state-changing endpoints:

res.cookie('refreshToken', token, {
  httpOnly: true,
  secure: true,
  sameSite: 'Strict',
});

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