[PR #197] [MERGED] fix: csrf token verification #3153

Closed
opened 2026-03-13 10:41:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/197
Author: @matserix
Created: 10/16/2024
Status: Merged
Merged: 10/16/2024
Merged by: @Bekacru

Base: mainHead: csrf-token-verification


📝 Commits (2)

  • 38132ae fix: csrf endpoint returning wrong token
  • 4105357 fix: csrf wrong token validation

📊 Changes

2 files changed (+5 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/api/middlewares/csrf.ts (+1 -1)
📝 packages/better-auth/src/api/routes/csrf.ts (+4 -3)

📄 Description

Current endpoint returns a token or a token with hash (current cookie). This leads to different csrf tokens being set on the client. Also the current middleware compares the current cookie (token + hash) with only the token (or token + hash if /csrf is called separately).

This pr aims to return the correct token on every /csrf call and to compare the correct tokens in the middleware


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/197 **Author:** [@matserix](https://github.com/matserix) **Created:** 10/16/2024 **Status:** ✅ Merged **Merged:** 10/16/2024 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `csrf-token-verification` --- ### 📝 Commits (2) - [`38132ae`](https://github.com/better-auth/better-auth/commit/38132aee1cdbcdae93412764176dc40b38d7f4f5) fix: csrf endpoint returning wrong token - [`4105357`](https://github.com/better-auth/better-auth/commit/410535798c664d06e0f1ec49ad0f33c9fb963aaa) fix: csrf wrong token validation ### 📊 Changes **2 files changed** (+5 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/middlewares/csrf.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/csrf.ts` (+4 -3) </details> ### 📄 Description Current endpoint returns a token or a token with hash (current cookie). This leads to different csrf tokens being set on the client. Also the current middleware compares the current cookie (token + hash) with only the token (or token + hash if /csrf is called separately). This pr aims to return the correct token on every `/csrf` call and to compare the correct tokens in the middleware --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 10:41:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#3153