[PR #5765] fix(middlewares): allow API clients (Postman/cURL) to work with cookie-based authentication #31812

Open
opened 2026-04-17 22:41:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5765
Author: @okisdev
Created: 11/5/2025
Status: 🔄 Open

Base: mainHead: fix(middlewares)/identify-simple-request


📝 Commits (3)

  • ad1824a fix(middlewares): identify simple request
  • a78c179 fix(middlewares): identify simple request
  • bb6146c Merge branch 'canary' into fix(middlewares)/identify-simple-request

📊 Changes

2 files changed (+124 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/api/middlewares/origin-check.test.ts (+109 -0)
📝 packages/better-auth/src/api/middlewares/origin-check.ts (+15 -7)

📄 Description

This PR adds isSimpleRequest check for headers to avoid api clients like Postman/cURL are rejected.

After PR #5411, all POST requests with cookies are required to have an Origin header, regardless of whether they are simple requests or not. This breaks API clients like Postman, cURL, and mobile apps that don't send Origin headers by default.

Current behavior:

  • Sign in/sign out via Postman → 403 MISSING_OR_NULL_ORIGIN
  • API calls with cookies but no Origin header → Rejected

Expected behavior:

  • Browser-based simple requests → Require Origin (CSRF protection)
  • API clients with non-simple requests → Allow without Origin (CORS-protected)

This PR fixes #5573

If this approach is intentional, please feel free to close this PR at any time.


Summary by cubic

Allow cookie-based API calls from Postman/cURL without an Origin header when the request is non-simple. Keep CSRF protection by requiring Origin only for browser simple requests.

  • Bug Fixes
    • Use isSimpleRequest to require Origin only for simple requests when CSRF is enabled.
    • Validate Origin only if present and not "null"; still return 403 for invalid origins.
    • Add tests for sign-in/sign-out with cookies and no Origin, and for rejecting bad Origin.

Written for commit bb6146cf06. Summary will update automatically on new commits.


🔄 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/5765 **Author:** [@okisdev](https://github.com/okisdev) **Created:** 11/5/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix(middlewares)/identify-simple-request` --- ### 📝 Commits (3) - [`ad1824a`](https://github.com/better-auth/better-auth/commit/ad1824ac2d837e42e375f4edd94dc39996b5c79a) fix(middlewares): identify simple request - [`a78c179`](https://github.com/better-auth/better-auth/commit/a78c179eca7e86a45661b9870e3c917d5815b39d) fix(middlewares): identify simple request - [`bb6146c`](https://github.com/better-auth/better-auth/commit/bb6146cf06e6fce177a364c8b82f50021b13d2fa) Merge branch 'canary' into fix(middlewares)/identify-simple-request ### 📊 Changes **2 files changed** (+124 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/middlewares/origin-check.test.ts` (+109 -0) 📝 `packages/better-auth/src/api/middlewares/origin-check.ts` (+15 -7) </details> ### 📄 Description This PR adds `isSimpleRequest` check for headers to avoid api clients like Postman/cURL are rejected. After PR #5411, all POST requests with cookies are required to have an `Origin` header, regardless of whether they are simple requests or not. This breaks API clients like Postman, cURL, and mobile apps that don't send `Origin` headers by default. **Current behavior:** - Sign in/sign out via Postman → ❌ `403 MISSING_OR_NULL_ORIGIN` - API calls with cookies but no Origin header → ❌ Rejected **Expected behavior:** - Browser-based simple requests → ❌ Require Origin (CSRF protection) - API clients with non-simple requests → ✅ Allow without Origin (CORS-protected) This PR fixes #5573 If this approach is intentional, please feel free to close this PR at any time. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allow cookie-based API calls from Postman/cURL without an Origin header when the request is non-simple. Keep CSRF protection by requiring Origin only for browser simple requests. - **Bug Fixes** - Use isSimpleRequest to require Origin only for simple requests when CSRF is enabled. - Validate Origin only if present and not "null"; still return 403 for invalid origins. - Add tests for sign-in/sign-out with cookies and no Origin, and for rejecting bad Origin. <sup>Written for commit bb6146cf06e6fce177a364c8b82f50021b13d2fa. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-04-17 22:41:08 -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#31812