Skip to content

feat(auth): add CSRF token generation and validation#14

Merged
halvaradop merged 5 commits intomasterfrom
feat/implement-csrf-tokens
Nov 25, 2025
Merged

feat(auth): add CSRF token generation and validation#14
halvaradop merged 5 commits intomasterfrom
feat/implement-csrf-tokens

Conversation

@halvaradop
Copy link
Copy Markdown
Member

@halvaradop halvaradop commented Nov 24, 2025

Description

This pull request introduces full support for CSRF (Cross-Site Request Forgery) tokens across the authentication flows.
CSRF tokens are cryptographically strong, randomized, and unpredictable values designed to protect users from unauthorized actions attempted by attackers. These tokens ensure that critical operations, especially those triggered via POST, DELETE, or PATCH requests, cannot be executed without explicit user intent.

By validating CSRF tokens, the library prevents attackers from forcing users to perform unwanted actions such as signing out or modifying account data.

CSRF Token Management

To support secure generation and validation of CSRF tokens, a new endpoint has been introduced:

  • /csrfToken
    This endpoint is responsible for issuing and verifying CSRF tokens:
    • If the user does not yet have a CSRF token, the endpoint generates a new one.
    • If the user already has a CSRF token, the endpoint verifies whether it is valid.
      • If valid -> the token is returned.
      • If invalid -> a new token is generated.

These tokens are then used internally by routes that require strong CSRF protection.

Endpoints Using CSRF Tokens

  • /callback/:oauth
    Generates the CSRF token for the authenticated session after a successful OAuth callback.

  • /signOut
    Validates the CSRF token before revoking the active session.

    • If the token is valid -> the session is closed.
    • If invalid -> the sign out operation is rejected.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Nov 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
auth Ready Ready Preview Comment Nov 25, 2025 9:59pm

@halvaradop halvaradop merged commit ae37687 into master Nov 25, 2025
2 checks passed
@halvaradop halvaradop deleted the feat/implement-csrf-tokens branch November 25, 2025 22:00
@halvaradop halvaradop added the feature New functionality label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant