Skip to content

fix: 想定外の入力値で 500 になる箇所を 400 や入力エラーにする - #68

Open
nanasess wants to merge 2 commits into
EC-CUBE:4.4from
nanasess:fix/zap-500-errors
Open

nanasess wants to merge 2 commits into
EC-CUBE:4.4from
nanasess:fix/zap-500-errors

Conversation

@nanasess

@nanasess nanasess commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

概要

OWASP ZAP のスキャン (EC-CUBE/ec-cube#7190) で見つかった、想定外の値を送ると 500 (システムエラー) になる箇所を、400 または入力エラーにします。クエリはパラメータ化されており、インジェクションの形跡はありません。入力値の型を確かめないまま、DB やエンティティへ渡していたことが原因です。スキャンで見つかった箇所に加え、同じ形 (送信されたかを確かめずに isValid() を呼ぶ、null を受けないセッターに null が渡るフォーム) をプラグイン全体から洗い出しています (前者は該当なし)。

本体側の同種の修正は EC-CUBE/ec-cube#7227 です。

変更内容

ファイル 内容
Controller/RecommendSearchModelController.php 商品検索の category_id を整数の ID として検証し、不正な値は 400 にする。ページ送り (GET) で、セッションに残った以前の検索条件の不正な ID は条件から外す
Controller/RecommendController.php 並び替え (sort_no/move) で、おすすめ商品の ID と並び順を integer として検証し、数値以外や範囲外は 400 にする。数値以外の並び順は RecommendProduct::setSortno(?int) の型宣言で、数値以外の ID は DB の型エラーで 500 になっていた
Form/Type/RecommendProductType.php 登録・編集画面の表示だけの ID の項目を disabled にし、送られた値でおすすめ商品の ID を書き換えない。数値以外は RecommendProduct::setId(?int) の型宣言で 500 になっていた
Entity/RecommendProduct.php setProduct() が null も受け付けるようにする。編集で商品を送らない・空の値を送ると、フォームが商品を null に変換し、setProduct(Product) の型宣言で 500 になっていた。商品が無いことは従来どおりフォームの POST_SUBMIT で入力エラー (「商品を追加してください。」) にし、編集画面を表示する。プロパティと getProduct() はもともと null を許している

整数の範囲は、DB の integer に合わせて 2147483647 までとしています。

ID の項目は readonly の表示用で、これまでも送られた値を使う処理はありません (更新は URL の ID で読み込んだおすすめ商品に対して行う)。disabled にすると、送られた値はフォームに反映されず、読み込んだおすすめ商品の ID がそのまま残ります。

テスト

  • 追加したテスト: 不正な ID・並び順 (文字列・範囲外・負の数・配列) で 400 になること、ID の項目に数値以外を送っても保存でき ID が変わらないこと、並び替えの正常系、編集で商品を送らない・空の値を送ると入力エラーの画面 (200) を表示し、おすすめ商品を更新しないこと
  • 修正を外した状態では、追加したテストのうち正常系以外がすべて失敗することを確認しました (500、または 200 で受け付けてしまう)
  • Tests/ 全体: 37 件成功 (PostgreSQL 18、EC-CUBE 4.4 の最新)
  • php-cs-fixer・PHPStan: 差分・エラーなし
  • Rector: EC-CUBE 4.4 の最新の依存では、Resource/rector.php が参照する SymfonySetList::SYMFONY_74 が定義されておらず、設定の読み込みで止まります (この PR の変更を入れる前から同じ)

🤖 Generated with Claude Code

- 商品検索のモーダル: category_id を整数の ID として検証し、不正な値は 400 にする。
  セッションに残った以前の検索条件の不正な ID は条件から外す
- 並び替え: おすすめ商品の ID と並び順を integer として検証し、数値以外や範囲外は
  400 にする (型エラーで 500 になっていた)
- 登録・編集: 表示だけの ID の項目を disabled にし、送られた値で ID を書き換えない
  (数値以外は RecommendProduct::setId() の型宣言で 500 になっていた)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d84fd6fa-b168-423e-9cb0-f8c1a32d6faa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

おすすめ商品の編集で商品を送らない、または空の値を送ると、フォームが商品を null に
変換し、RecommendProduct::setProduct() (Product 型) への書き込みで例外になっていた。

setProduct() を null も受け付けるようにする。商品が無いことは従来どおりフォームの
POST_SUBMIT で入力エラーにし、編集画面を表示する (おすすめ商品は更新しない)。
プロパティと getProduct() はもともと null を許している。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nanasess nanasess changed the title fix: 想定外の入力値で 500 になる箇所を 400 にする fix: 想定外の入力値で 500 になる箇所を 400 や入力エラーにする Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant