fix: ステートレスAPIリクエストでUnexpectedSessionUsageExceptionが発生する問題を修正#6760
fix: ステートレスAPIリクエストでUnexpectedSessionUsageExceptionが発生する問題を修正#6760kurozumi wants to merge 1 commit into
Conversation
stateless: trueのファイアウォール(/api)で認証失敗が発生した際、 SecurityListenerのonAuthenticationFailureがセッションに書き込もうとするため Symfony\Component\HttpKernel\Exception\UnexpectedSessionUsageExceptionが発生し 500エラーになる問題を修正する。 セッションが未開始の場合はスキップすることで、Bearer token認証の APIリクエストが401を正しく返すようにした。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.3 #6760 +/- ##
============================================
- Coverage 78.65% 78.65% -0.01%
- Complexity 6825 6827 +2
============================================
Files 476 476
Lines 27080 27082 +2
============================================
+ Hits 21300 21301 +1
- Misses 5780 5781 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@kurozumi |
概要
stateless: trueのファイアウォール(/api)に対して認証失敗が発生した際、SecurityListener::onAuthenticationFailure()がセッションに書き込もうとするためUnexpectedSessionUsageExceptionが発生し、500エラーになる問題を修正します。問題の詳細
EC-CUBE の Api42 プラグインは
/apiルートをstateless: trueで設定しています。このため、Bearer トークン認証に失敗した場合(例:トークン期限切れ)、本来 401 を返すべきところが 500 になります。エラーログ:
原因:
SecurityListener::onAuthenticationFailure()は、フロント用ログインフォームの「ログイン状態を保持する」チェックボックスの値をセッションに保存するために書かれたコードです。しかしこのリスナーは API からの認証失敗でも呼ばれるため、ステートレスリクエストでセッションに書き込もうとして例外が発生します。修正内容
セッションが未開始の場合(=ステートレスリクエスト)は早期リターンすることで、API リクエストが正しく 401 を返すようにしました。
影響範囲