feat(sanitizer): add per-command flag allowlists for show and log#5
feat(sanitizer): add per-command flag allowlists for show and log#5flyingrobots merged 4 commits intomainfrom
Conversation
- Add 'show' to the allowlist of safe Git commands. - Update version to 2.7.1. - Add unit tests for 'log' and 'show' sanitization.
- Introduce `_COMMAND_FLAG_ALLOWLISTS` to restrict flags for 'show' and 'log'. - Add `_validateCommandFlags` to prevent unauthorized flag injection. - Add comprehensive test suite covering flag validation, shell metacharacter safety, and NUL-terminated output scenarios.
📝 WalkthroughWalkthroughAdds per-command flag allowlists and validation to CommandSanitizer (including Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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
🤖 Fix all issues with AI agents
In `@src/domain/services/CommandSanitizer.js`:
- Around line 118-133: The loop in CommandSanitizer.sanitize is treating the
standard Git end-of-options marker '--' as a flag and rejecting it; update the
loop that iterates over args (starting at commandIndex + 1) to detect a bare
'--' and stop flag validation (break out of the loop) so subsequent args
(pathspecs or refs that begin with '-') are not checked against allowlist;
ensure the check happens before the startsWith('-')/flag parsing logic and keep
ProhibitedFlagError unchanged for real disallowed flags.
Stop flag validation when encountering bare '--' marker, allowing pathspecs and refs that begin with '-' to pass through without being checked against the allowlist.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/domain/services/CommandSanitizer.js`:
- Around line 132-136: The sanitize logic currently does exact allowlist checks
on flagPart and rejects combined numeric short forms like "-n10" and "-15";
update CommandSanitizer.sanitize to recognize and normalize numeric short forms
before allowlist validation by treating "-15" as equivalent to "-n15" and
accepting "-n<digits>" (e.g. via a regex check for /^-(?:n?\d+)$/), then
validate the normalized flag (or bypass allowlist for numeric forms) instead of
throwing ProhibitedFlagError for these cases; add unit tests for ['log', '-n10',
'HEAD'] and ['log', '-15', 'HEAD'] to prevent regressions.
Add regex check for /^-n?\d+$/ to recognize git's numeric shorthand forms like -n10 and -15 (equivalent to -n 10 and -n 15). These are now allowed when -n is in the command's flag allowlist.
Summary
showandlogcommands to enforce read-only plumbing usage_validateCommandFlags()static method that rejects non-whitelisted flags withProhibitedFlagErrorChanges
CommandSanitizer.js
_COMMAND_FLAG_ALLOWLISTSwith whitelisted flags for:show:--format,--pretty,-s,--no-patch,--quiet,-q,--name-only,--stat, etc.log:--format,--pretty,-z,-n,--max-count,--ancestry-path,--first-parent,--reverse, etc._validateCommandFlags()method to validate flags against allowlistsTest Coverage (24 new tests)
--diff-filter,--follow,-p);, backticks,$(), pipes, newlines)log -z): Various flag combinations for reliable commit parsing--flag=valueparsingTest plan
docker-compose run --rm node-test)showwith disallowed flag throwsProhibitedFlagErrorlog -zworks for commit history traversalSummary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.