Add configured input taint sources - #2
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughIntroduces Psalm taint-analysis support: new InputTaintHandler that marks constructor parameters (and promoted properties) annotated with Ray\InputQuery\Attribute\Input as taint sources for configured root classes. Plugin wiring, fixtures, integration tests, demo code, and README documentation are included. ChangesInput Taint Analysis Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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: 2
🧹 Nitpick comments (1)
tests/PluginIntegrationTest.php (1)
230-249: ⚡ Quick winHarden command argument handling in
runPsalm.
$extraArgsis interpolated directly into a shell command. It’s currently controlled, but this is brittle and easy to misuse later. Prefer building escaped args explicitly.Proposed refactor
- /** `@return` list<array<string, mixed>> */ - private static function runPsalm(string $extraArgs = ''): array + /** `@param` list<string> $extraArgs + * `@return` list<array<string, mixed>> + */ + private static function runPsalm(array $extraArgs = []): array @@ - $cmd = sprintf( - '%s --config=%s %s --output-format=json --no-cache --no-progress 2>/dev/null', - escapeshellarg($psalmBin), - escapeshellarg($config), - $extraArgs, - ); + $escapedExtraArgs = array_map(static fn (string $arg): string => escapeshellarg($arg), $extraArgs); + $cmd = sprintf( + '%s --config=%s %s --output-format=json --no-cache --no-progress 2>/dev/null', + escapeshellarg($psalmBin), + escapeshellarg($config), + implode(' ', $escapedExtraArgs), + );And at call site:
- self::$cachedTaintIssues = self::runPsalm('--taint-analysis'); + self::$cachedTaintIssues = self::runPsalm(['--taint-analysis']);🤖 Prompt for 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. In `@tests/PluginIntegrationTest.php` around lines 230 - 249, The runPsalm function currently interpolates $extraArgs directly into $cmd which is brittle and unsafe; change runPsalm to build a secure argument array instead of string interpolation: split or accept $extraArgs as an array (update callers if needed), call escapeshellarg on each element, merge with the base args (the psalm binary and --config option built with escapeshellarg) and then join them when composing $cmd (or better, use a proper Process/exec invocation that accepts an array). Update references to runPsalm and the $extraArgs parameter so callers pass an array of extra args or allow both string/array and normalize to an escaped array internally; ensure $cmd uses the escaped tokens (references: runPsalm, $extraArgs, $cmd, escapeshellarg).
🤖 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 `@README.md`:
- Around line 6-7: The current README sentence implies global behavior; update
the line mentioning `Ray\InputQuery\Attribute\Input` to say that Psalm taint
analysis treats constructor parameters annotated with
`Ray\InputQuery\Attribute\Input` as user-controlled input only for configured
root input classes (e.g., “...are treated as user-controlled input for
configured root input classes”), so the scope matches the detailed section later
and avoids implying global behavior.
In `@src/Handler/InputTaintHandler.php`:
- Around line 197-199: The code uses
$classStorage->declaring_property_ids[$propertyName] (a fully-qualified property
id like Fully\Qualified\ClassName::$prop) directly as $declaringClass and passes
it to $codebase->classlikes->getStorageFor(), which expects a class FQCN;
normalize the declaring property id first by extracting the class portion (strip
the trailing ::$propertyName part, and any leading backslash) before assigning
$declaringClass, then call getStorageFor($declaringClass) so inherited promoted
#[Input] properties resolve correctly; reference:
$classStorage->declaring_property_ids, $propertyName, $declaringClass, and
getStorageFor().
---
Nitpick comments:
In `@tests/PluginIntegrationTest.php`:
- Around line 230-249: The runPsalm function currently interpolates $extraArgs
directly into $cmd which is brittle and unsafe; change runPsalm to build a
secure argument array instead of string interpolation: split or accept
$extraArgs as an array (update callers if needed), call escapeshellarg on each
element, merge with the base args (the psalm binary and --config option built
with escapeshellarg) and then join them when composing $cmd (or better, use a
proper Process/exec invocation that accepts an array). Update references to
runPsalm and the $extraArgs parameter so callers pass an array of extra args or
allow both string/array and normalize to an escaped array internally; ensure
$cmd uses the escaped tokens (references: runPsalm, $extraArgs, $cmd,
escapeshellarg).
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7647e42a-ff74-4219-a820-13e8a8cebe92
📒 Files selected for processing (13)
README.mddemo/InputTaintDemo.phpdemo/README.mddemo/psalm.xmlsrc/Handler/InputTaintHandler.phpsrc/Plugin.phptests/Fixture/Invalid/TaintedAssignedInput.phptests/Fixture/Invalid/TaintedPromotedInput.phptests/Fixture/Invalid/TaintedPromotedInputObject.phptests/Fixture/Valid/InjectedNotTainted.phptests/Fixture/Valid/SanitizedReinput.phptests/Fixture/psalm.xmltests/PluginIntegrationTest.php
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Tests
zsh -ic 'sphp85; composer tests'\n-zsh -ic 'sphp85; vendor/bin/psalm --config=demo/psalm.xml --taint-analysis --no-cache --no-progress'(expected taint errors)Summary by CodeRabbit
New Features
Documentation
Demos
Tests