Repository navigation
fix(router): アクションの CSRF・署名の検証失敗を error.psx の 403 で応答する - #138
Merged
Merged
Conversation
CSRF トークンが不正なとき、またはアクショントークンの署名を検証できない とき、FunctionPage / PageComponent の dispatchActionFromRequest() は http_response_code(403) を設定して return するだけで、そのまま通常の ページ(新しい CSRF トークン付きのフォーム)を 403 で描画していた。 $ctx->abort(403) と同じく HttpException(403) を投げ、RequestDispatch の 既存の経路で ErrorResponder::respond(403, ...)(error.psx、無ければ 組み込みの表示)から応答する。 Closes #132 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r-page # Conflicts: # README.ja.md # README.md
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.
Closes #132
Summary
FunctionPage::dispatchActionFromRequest()/PageComponent::dispatchActionFromRequest()はhttp_response_code(403)を設定してreturnするだけで、通常のページ(新しい CSRF トークン付きのフォーム)をそのまま 403 で描画していました。$ctx->abort(403)と同じくHttpException(403)を投げるようにしました。RequestDispatchが既存のhandleHttpException()で受け、ErrorResponder::respond(403, ...)(error.psx、無ければ組み込みの表示)で応答します。新しい仕組みは足していません。renderAroundAction)でも、拒否はディスパッチの時点で例外になるため、応答のための再描画は走りません。テスト
tests/Router/ActionForbiddenErrorPageTest.phpを追加: 関数ページ / クラスページそれぞれで、CSRF 不正・改ざんトークンの POST が 403 でerror.psxの本文になり、通常のページ本文や_rosanna_csrfを含まず、ハンドラも実行されないことを確認。error.psxが無い場合は組み込みの表示になることも確認。修正前のコードでは 5 件とも失敗します。FunctionPageActionDispatchTest/PageComponentActionDispatchTest)はhttp_response_code()ではなくHttpException(403)を確認するように変更。RenderableChildActionDispatchTest::testABadCsrfFieldNeitherRendersTwiceNorRunsは、ページを一度も描画せずエラーページで応答することを確認するように変更。ドキュメント
README.md/README.ja.md: CSRF 不正の 403 がerror.psx(または組み込みの表示)で応答されること、error.psxの対象にアクションの 403 を含むことを追記。🤖 Generated with Claude Code