refactor: パラメータ設定値の検証を token_get_all による構文解析に変更 - #1407
Conversation
SC_CheckError::evalCheck() の値検証を eval() から
token_get_all(TOKEN_PARSE) を用いた構文解析に変更する。値は
mtb_constants.php へ define('KEY', <値>); の形で出力されるため、
リテラル・定数・それらの連結式といったスカラ定数式のみを許可する。
- 関数呼び出しや複数の文を含む値はスカラ定数式ではないため許可しない
- mtb_constants_init.php の既定値245件、および
シングル/ダブルクォート文字列はいずれも従来どおり許可される
- EVAL_CHECK のテストにスカラ定数式・非スカラ式の各ケースを追加
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Changesスカラ定数式検証
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@data/class/SC_CheckError.php`:
- Around line 1792-1815: evalCheck() currently treats a bare ';' / '1;' /
whitespace as valid because token_get_all('<?php '.$value.';', TOKEN_PARSE)
allows the trailing ';' unconditionally; tighten evalCheck() so single-character
';' is only permitted if it is the final wrapper-added token and there is at
least one value token present (i.e. require at least one
non-T_OPEN_TAG/T_WHITESPACE token other than the wrapper ';'), and otherwise
reject inputs like ';', '1;' and pure whitespace; update the allowedTypes/token
loop in SC_CheckError::evalCheck to enforce that rule and ensure
getMasterDataAsDefine() cannot receive an empty/only-semicolon $val, and add the
test cases ';', '1;', and ' ' to invalidValueProvider so they are asserted
invalid.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 897557d1-b6a2-4212-b02f-dc11ca4c0c40
📒 Files selected for processing (2)
data/class/SC_CheckError.phptests/class/SC_CheckError/SC_CheckError_EVAL_CHECKTest.php
token_get_all のトークン検証で ';' を末尾 (構文解析用に付与した区切り) のみ
許可し、値となるトークンを最低 1 つ必須とする。これにより ';' / '1;' /
空白のみといった、define('KEY', <値>); に展開すると構文エラーとなる入力を
バリデーションエラーとする。
SC_CheckError_EVAL_CHECKTest の invalidValueProvider に該当ケースを追加。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1407 +/- ##
==========================================
+ Coverage 56.23% 56.31% +0.07%
==========================================
Files 87 87
Lines 11091 11111 +20
==========================================
+ Hits 6237 6257 +20
Misses 4854 4854
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
システム設定 > パラメーター設定 (
LC_Page_Admin_System_Parameter) の値検証を担うSC_CheckError::evalCheck()を、eval()による評価からtoken_get_all(..., TOKEN_PARSE)を用いた構文解析に変更します。パラメーター値は
data/cache/mtb_constants.phpへdefine('KEY', <値>);の形で出力され、各リクエストで読み込まれます。そのため<値>が スカラ定数式(リテラル / 定数 / それらの連結式)として成立することを、値を実行せずに確認します。変更点
evalCheck()をeval('return is_scalar(...)')から、token_get_all(TOKEN_PARSE)による構文解析 + トークンの許可リストに変更true/false/null含む) / 連結 (.) / 符号 (+/-) のみ許可mtb_constants_init.phpの既定値 245 件、およびシングル / ダブルクォート文字列はいずれも従来どおり許可されますSC_CheckError_EVAL_CHECKTestにスカラ定数式・非スカラ式のデータプロバイダを追加補足
define('AAA', 'BBB')のような関数呼び出しは、旧実装ではis_scalar()の評価結果がtrueになるため許可されていましたが、スカラ定数式ではないため本変更では許可しません。mtb_constantsの実値に該当するものはありません。Test plan
tests/class/SC_CheckError/SC_CheckError_EVAL_CHECKTest.php(24 tests) 通過tests/class/pages/admin/system/LC_Page_Admin_System_ParameterTest.php通過🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests