fix: Chart.js を本体同梱の 4.x に切り替え、CSV に数式インジェクションガードを適用 (#91, #92) - #93
Open
ttokoro20240902 wants to merge 3 commits into
Open
fix: Chart.js を本体同梱の 4.x に切り替え、CSV に数式インジェクションガードを適用 (#91, #92)#93ttokoro20240902 wants to merge 3 commits into
ttokoro20240902 wants to merge 3 commits into
Conversation
管理画面のグラフが cdnjs から Chart.js 2.3.0 を読み込んでいたため、
外部 CDN 依存とバージョンの二重管理が残っていた。本体 4.4 は
package.json で chart.js ^4.5.1 を同梱し、admin.bundle.js として
default_frame.twig から全管理画面に読み込んでいるため、これを使う。
- index.twig: cdnjs の script タグを削除(Chart はグローバルに存在する)
- term / product / age.twig: Chart.js 4.x の API へ移行
- tooltips -> plugins.tooltip、title -> plugins.title、legend -> plugins.legend
- tooltip の label コールバックを (tooltipItem, data) から (context) へ変更し
context.parsed.y / context.label を使う
- scales.yAxes[] -> scales.y、scales.xAxes[] -> scales.x
- beginAtZero / suggestedMin を ticks 配下から scales.y 直下へ移動
- categoryPercentage は 3 以降データセットのオプションなので dataSet へ移動
実機確認(EC-CUBE 4.4 / PHP 8.2 / SQLite、Chart.js 4.5.1):
- 期間別(日別=line / 曜日別=bar)、商品別、年代別の 3 画面でグラフが描画され、
canvas が空でないことを確認
- y 軸目盛のフォーマット(1234567 -> "1,234,567")と
ツールチップ("購入合計: ¥9,876" / "商品A : ¥4,200")が動作
- options.scales に旧 xAxes/yAxes が残っていないこと、
商品別の categoryPercentage がデータセットに適用されていることを確認
- cdnjs へのリクエストが発生しないこと、JS コンソールエラー 0 件を確認
- PHPUnit 35 tests 54 assertions 成功
Closes #91
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CSV 出力は fputcsv() を直接呼んでおり本体の CsvExportService を経由しないため、 店舗設定を ON にしても数式インジェクション対策が効いていなかった。 本体の CsvExportService と同じく Eccube\Util\CsvFormulaGuard を使い、 店舗設定 BaseInfo::isOptionSanitizeCsvFormulas() の ON/OFF を尊重して 期間別/商品別/年代別の 3 つの CSV のデータ行を無害化する。 CsvFormulaGuard::escape() は int|string|null を受けるため、round() が返す float 等を渡さないよう文字列のみを対象にしている(非文字列は escape() でも そのまま返るため挙動は変わらない)。 ## 必要な本体バージョン CsvFormulaGuard と BaseInfo::isOptionSanitizeCsvFormulas() は本体 4.4 ブランチに 2026-06-18 に追加されたもので、それ以前の 4.4 スナップショットには存在しない。 本コミットはこれらを前提とする。 ローカルの docker 開発環境(ghcr.io/ec-cube/ec-cube-php:8.2-apache-4.4、 本体 VERSION = 4.3.1-p1 相当)はこの API を含まないため、当該イメージでは - CSV 出力が Class not found で 500 になる - PHPUnit の CSV 出力テストが 1 件エラーになる - phpstan が 2 件(method.notFound / class.notFound)を報告する いずれも本体スナップショットが古いことによるもので、CI(ref: '4.4' を checkout するため CsvFormulaGuard を含む)での検証結果を正とする。 docker イメージの更新は別途対応する。 Closes #92 Co-Authored-By: Claude Opus 5 (1M context) <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 Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
CI の static-analysis で rector が下記の変更を提案して失敗していたため追従した。
- private BaseInfoRepository $baseInfoRepository,
+ private readonly BaseInfoRepository $baseInfoRepository,
ローカルで rector --dry-run が変更なしになること、php-cs-fixer が差分なしに
なることを確認した。
Co-Authored-By: Claude Opus 5 (1M context) <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.
#90 のレビューで「本 PR の対応は不要」とされた 2 件に対応します。コミットを分けています。
本 PR は
4.4ではなく #90 のブランチfeat-4.4をベースにしています。origin/4.4はまだSalesReport42(composer.jsonの version は4.3.0)で、SalesReport44へのリネームは #90 が持ち込むものです。4.4を直接ベースにすると旧コード名に対する変更になり #90 とコンフリクトするため、#90 の上に積んでいます。#90 のマージ後にレビュー・マージをお願いします(#90 がマージされればベースは自動で4.4に切り替わります)。Closes #91 — Chart.js
本体 4.4 は
package.jsonでchart.js: ^4.5.1を同梱し、admin.bundle.jsとしてdefault_frame.twigから全管理画面に読み込んでいます。そのため CDN の script タグは不要で、Chartはグローバルに存在します。index.twig: cdnjs の script タグを削除term/product/age.twig: Chart.js 4.x の API へ移行tooltips→plugins.tooltip、title→plugins.title、legend→plugins.legend(tooltipItem, data)から(context)へ変更しcontext.parsed.y/context.labelを使うscales.yAxes[]→scales.y、scales.xAxes[]→scales.xbeginAtZero/suggestedMinをticks配下からscales.y直下へ移動categoryPercentageは Chart.js 3 以降データセットのオプションなのでデータセットへ移動実機確認(EC-CUBE 4.4 / PHP 8.2 / SQLite、Chart.js 4.5.1)
ブラウザで 3 画面を開き、生成された Chart インスタンスを直接検証しました。
Chartグローバルの供給元とバージョンadmin.bundle.js由来、Chart.version = 4.5.1type: line、365 点、canvas 描画ありtype: bar、ラベルSun〜Sattype: bar、タイトル「商品別集計 上位20件」表示、凡例非表示、x 軸 90 度回転、categoryPercentage = 0.3がデータセットに適用type: bar、凡例非表示、categoryPercentage = 0.31234567→1,234,567購入合計: ¥9,876/商品A : ¥4,200options.scalesにxAxes/yAxesなしCloses #92 — CSV の数式インジェクションガード
本体の
CsvExportServiceと同じくEccube\Util\CsvFormulaGuardを使い、店舗設定BaseInfo::isOptionSanitizeCsvFormulas()の ON/OFF を尊重して 3 つの CSV のデータ行を無害化します。CsvFormulaGuard::escape()はint|string|nullを受けるため、round()が返す float 等を渡さないよう文字列のみを対象にしています(非文字列はescape()でもそのまま返るため挙動は変わりません)。CsvFormulaGuardとBaseInfo::isOptionSanitizeCsvFormulas()は本体4.4ブランチに 2026-06-18 に追加されたもので、それ以前の 4.4 スナップショットには存在しません。本 PR はこれらを前提としています。ローカルの docker 開発環境が使う
ghcr.io/ec-cube/ec-cube-php:8.2-apache-4.4(本体VERSION = 4.3.1-p1相当)はこの API を含まないため、当該イメージでは以下が発生します。Class not foundで 500 になるBaseInfo::isOptionSanitizeCsvFormulas()のmethod.notFound、CsvFormulaGuardのclass.notFound)いずれも本体スナップショットが古いことによるもので、#92 の実装そのものはローカルでは検証できていません。CI は
ref: '4.4'を checkout しCsvFormulaGuardを含むため、CI の結果を正としています。docker イメージの更新は別途対応が必要です。この前提(未リリースの 4.4 の API に依存する)が受け入れられない場合は、
class_exists()による互換ガードを入れる形にも変更できます。ご指示ください。