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

Open
opened 2026-04-13 09:29:05 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5765

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5765 **State:** open **Merged:** No --- 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:29:05 -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#14458