-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(security): require explicit approval for shell redirection/background in command auto-approve #11367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(security): require explicit approval for shell redirection/background in command auto-approve #11367
Conversation
All issues from previous reviews have been addressed. Quote-aware operator detection via
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
4c99f4f to
cf5084f
Compare
cf5084f to
2ab6380
Compare
|
Addressed the review feedback:
|
|
@roomote Could you please re-review? I addressed your <&N note, and also tightened fd-to-fd stripping with a token-boundary lookahead to avoid false negatives like >&2file / <&3in. Tests expanded from 44 to 55 and I force-pushed the update. Thanks. |
No outstanding issues to fix. The reviewer has confirmed all previous issues are addressed, and all 55 tests pass locally. |
…ound in command auto-approve Commands containing file redirection (<, >, >>, <<) or standalone background operators (&) now force explicit user approval instead of being auto-approved via prefix matching. Safe fd-to-fd redirections (2>&1, >&2) remain auto-approvable. Also tightens the pre-existing fd-to-fd stripping regex with a token-boundary lookahead to prevent false negatives like >&2file and <&3in being silently stripped as fd-to-fd. Adds the first dedicated test suite for the command auto-approval pipeline (55 tests).
2ab6380 to
0d2a949
Compare
Verified the latest state of the PR. The reviewer confirmed all previous issues are resolved and no new issues were found. All 79 tests pass locally. No code changes needed. |
Refs #11095
Summary
shell: true. For example, auto-approvinggit showwould also auto-approvegit show > out.txt, allowing writes to an arbitrary file.<,>,>>,<<, etc.) now require explicit approval (ask_user).2>&1,>&2,<&3,0<&4).&) now require explicit approval.(?=$|\s|[;&|()<>])to avoid false negatives such as>&2fileand<&3in, where the redirection target is a word and therefore represents file redirection, not fd-to-fd duplication.Test plan
containsShellFileRedirection()— 21 cases: detects output/input/append/here-doc/stderr/mixed redirections (9), excludes safe fd-to-fd like2>&1,>&2,<&3,0<&4(5), token-boundary edge cases —>&2file,<&3in,2>&1&&,2>&1>out.txt,0<&4|(5), general sanity checks (2)containsBackgroundOperator()— 8 cases: detects standalone&, excludes&&,&>,>&,<&getCommandDecision()— 15 integration cases: redirection forcesask_user, fd-to-fd preservesauto_approve, background forcesask_user, token-boundary edge cases, denylist regressioncontainsDangerousSubstitution,findLongestPrefixMatch,getSingleCommandDecision— 11 cases