fix: include frontend origin in SANCTUM_STATEFUL_DOMAINS / Sanctumのstateful対象にフロントのオリジンを追加#545
Merged
zigzagdev merged 1 commit intoJul 20, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/cors-credentials #545 +/- ##
=======================================================
Coverage 62.21% 62.21%
Complexity 1604 1604
=======================================================
Files 135 135
Lines 8252 8252
=======================================================
Hits 5134 5134
Misses 3118 3118 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / 目的
Fixing CORS
supports_credentialsalone is not enough for the frontend's cookie-based Sanctum auth to work. Sanctum'sEnsureFrontendRequestsAreStatefulmiddleware only treats a request as session/cookie-based if its origin is listed inconfig('sanctum.stateful'). The frontend'slocalhost:3876was missing from that list, so requests from it were never routed through the session guard and instead fell back to bearer-token authentication — which the frontend never sends (it is fully cookie-based, confirmed insrc/app/features/auth/apis/auth-api.ts). This caused authenticated requests to fail with 401 even after the CORS fix.CORSの
supports_credentialsを直すだけでは、Cookieベースのフロントで認証は動きません。SanctumのミドルウェアはリクエストのOriginがconfig('sanctum.stateful')に載っている場合のみセッション(Cookie)方式で認証し、載っていない場合はBearerトークン方式にフォールバックします。フロントのlocalhost:3876がこの一覧に無かったため、CORS修正後も401のままでした。What I have done / 実施内容
config/sanctum.phpのstatefulに、既存のFRONTEND_URL環境変数からホスト:ポートを導出して追加FRONTEND_URLを再利用Test Results / テスト結果
docker exec heritage-app php artisan tinker --execute="print_r(config('sanctum.stateful'));"でlocalhost:3876が一覧に含まれることを確認LoginTest/LogoutTestの回帰なしを確認済み