未認証でのブログ・カスタムコンテンツ非公開記事の閲覧(preview/status)を修正 - #4504
Merged
Conversation
未認証のフロント/公開APIリクエストで preview / status パラメータを 悪用すると、非公開(下書き・承認待ち等)の記事が閲覧できていた。 preview は本来、認証済みのプレビュー機能(PreviewController 経由)でのみ 利用される想定だが、フロントルートや公開APIを直接叩くと未認証のまま 同じ処理が動作していた。 - AppController に restrictNonPublicAccess() を追加し beforeFilter で呼ぶ - フロント・管理画面(デフォルト実装): 未認証時に preview/status を除去し公開データに強制 - 公開API(BcApiController でオーバーライド): preview を ForbiddenException で拒否 - 認証済み(正規のプレビュー機能を含む)は従来どおり許可する - preview/status が無いリクエストでは認証判定(loginUser)を行わず、 全リクエストでの不要なDBアクセスによる副作用を避ける - フロント除去・API 403 を検証する統合テストと、メソッド単体テストを追加 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
未認証のフロント/公開APIリクエストで preview / status クエリを悪用し、非公開(下書き等)データを閲覧できていた経路を塞ぐために、AppController に制限用テンプレートメソッドを追加し、API では preview を 403 で拒否するよう統一するPRです。
Changes:
AppController::beforeFilter()からrestrictNonPublicAccess()を呼び出し、未認証時にpreview/statusをクエリから除去BcApiController側でpreviewクエリを検知したらForbiddenExceptionを投げるようオーバーライド- ブログ/カスタムコンテンツ/コアで、未認証アクセス時の挙動を検証するテストを追加
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/baser-core/src/Controller/AppController.php | 未認証時の preview / status 制限メソッド追加・beforeFilter から適用 |
| plugins/baser-core/src/Controller/Api/BcApiController.php | API では preview を 403 で拒否するためのオーバーライド追加 |
| plugins/baser-core/tests/TestCase/Controller/AppControllerTest.php | restrictNonPublicAccess() の単体テスト追加 |
| plugins/baser-core/tests/TestCase/Controller/Api/BcApiControllerTest.php | API版 restrictNonPublicAccess() の単体テスト追加 |
| plugins/bc-blog/tests/TestCase/Controller/BlogControllerTest.php | フロント未認証で preview/status を悪用しても非公開記事に到達できないことの統合テスト追加 |
| plugins/bc-blog/tests/TestCase/Controller/Api/BlogPostsControllerTest.php | 公開APIで preview 指定が 403 になることのテスト追加 |
| plugins/bc-custom-content/tests/TestCase/Controller/Api/CustomEntriesControllerTest.php | 公開APIで preview 指定が 403 になることのテスト追加 |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
__cleanupQueryParams() が amp;preview → preview にキーを正規化するため、 restrictNonPublicAccess() が先に実行される順序では ?amp;preview=1 の形で 未認証でも制限を回避できていた(GitHub Copilot レビューの指摘)。 preview/status に加え amp;preview/amp;status も除去・拒否対象にし、 実行順序に依存せず塞ぐ。 - AppController/BcApiController の restrictNonPublicAccess で amp; 付きキーも対象化 - amp; バイパスの回帰テスト(AppController/BcApiController 単体、フロント/公開API 統合)を追加 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
概要
未認証のフロント/公開APIリクエストで
preview/statusパラメータを悪用すると、非公開(下書き・承認待ち等)の記事が閲覧できていた問題を修正します。ブログ・カスタムコンテンツの両方が対象です。原因
previewは本来、認証済みのPreviewController(BcAdminAppController継承)経由でフロントを内部描画する設計ですが、フロントルートや公開APIを直接叩くと未認証のまま同じ処理が動作していました。公開APIはstatus/containをForbiddenExceptionで弾いていましたが、previewは素通しでした。?preview=1:archives / tags / single 全経路で非公開記事が閲覧可能?status=0:非公開記事だけを列挙?preview=1が getIndex に届き、非公開記事が返る修正
AppController::restrictNonPublicAccess()を新設しbeforeFilterから呼びます(テンプレートメソッド+オーバーライドで責務分担。AppController は API の存在を知りません)。preview/statusをクエリから除去し、公開データのみに強制BcApiControllerでオーバーライド):previewが指定されたらForbiddenException(403)で拒否BcUtil::loginUser()で判定)preview/statusが指定されていないリクエストでは認証判定(loginUser())を行わず、全リクエストでの不要なDBアクセスによる副作用を回避変更ファイル
plugins/baser-core/src/Controller/AppController.phpplugins/baser-core/src/Controller/Api/BcApiController.phpテスト
restrictNonPublicAccessのメソッド単体テスト(AppControllerTest / BcApiControllerTest)🤖 Generated with Claude Code