Skip to content

Conversation

@0xMink
Copy link
Contributor

@0xMink 0xMink commented Feb 10, 2026

Refs #11095

Summary

  • Command auto-approval could approve an allowlisted prefix while shell operators (redirection/background) alter execution semantics under shell: true. For example, auto-approving git show would also auto-approve git show > out.txt, allowing writes to an arbitrary file.
  • Commands containing file redirection (<, >, >>, <<, etc.) now require explicit approval (ask_user).
    • Safe fd-to-fd duplication is excluded (for example 2>&1, >&2, <&3, 0<&4).
  • Commands containing a standalone background operator (&) now require explicit approval.
  • fd-to-fd stripping now uses a token-boundary lookahead (?=$|\s|[;&|()<>]) to avoid false negatives such as >&2file and <&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 like 2>&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 forces ask_user, fd-to-fd preserves auto_approve, background forces ask_user, token-boundary edge cases, denylist regression
  • Existing regression coverage for containsDangerousSubstitution, findLongestPrefixMatch, getSingleCommandDecision — 11 cases
  • Total: 55 tests, all passing

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Feb 10, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 10, 2026

Rooviewer Clock   See task

All issues from previous reviews have been addressed. Quote-aware operator detection via stripQuotedSegments is correctly implemented. No new issues found.

  • containsShellFileRedirection strips output fd-to-fd (>&N) but not input fd-to-fd (<&N), producing false positives for commands like cmd <&3. Very low severity.
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@0xMink 0xMink force-pushed the fix/command-auto-approve-redirection branch from 4c99f4f to cf5084f Compare February 10, 2026 09:35
@0xMink 0xMink force-pushed the fix/command-auto-approve-redirection branch from cf5084f to 2ab6380 Compare February 10, 2026 10:05
@0xMink
Copy link
Contributor Author

0xMink commented Feb 10, 2026

Addressed the review feedback:

  • Fixed false negative: Added token-boundary lookahead to fd-to-fd stripping so >&2file and <&3in are correctly treated as file redirection (not fd-to-fd). The boundary (?=$|\s|[;&|()<>]) ensures stripping only when the fd target is purely numeric and token-delimited.
  • Added input fd-to-fd support: <&N and 0<&N patterns are now stripped alongside >&N, and excluded from background operator detection.
  • Kept correct behavior: 2>&1&& still strips; 0<&4| still strips; >&2 at end-of-string still strips.
  • Consistent stripping: Both containsShellFileRedirection() and the sub-command normalization in getCommandDecision() use the same boundary-aware regex.
  • Tests: 55/55 passing (up from 44). Added regression tests for >&2file, <&3in, operator-adjacent fd-to-fd, and input fd duplication at both unit and integration levels.

@0xMink
Copy link
Contributor Author

0xMink commented Feb 10, 2026

@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.

@roomote
Copy link
Contributor

roomote bot commented Feb 10, 2026

Fixaroo Clock   See task

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).
@0xMink 0xMink force-pushed the fix/command-auto-approve-redirection branch from 2ab6380 to 0d2a949 Compare February 10, 2026 23:31
@0xMink
Copy link
Contributor Author

0xMink commented Feb 11, 2026

Rebased onto main, resolved add/add in commands.spec.ts with #11365 / #11382, and made redirection/background detection quote-aware to avoid false positives in quoted payloads (e.g. node -e "const f=(a)=>a"). All CI checks are green.

@roomote please re-review.

@roomote
Copy link
Contributor

roomote bot commented Feb 11, 2026

Fixaroo Clock   See task

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant