Repository navigation
Conversation
|
| ')' => { | ||
| depth -= 1; | ||
| if depth == 0 { | ||
| return (chars[start..index].iter().collect(), index + 1); | ||
| } |
There was a problem hiding this comment.
matching_paren_body treats a case pattern’s closing ) as the end of the substitution. For echo "$(case prod in prod) rm -rf ~ ;; esac)", it extracts only case prod in prod. The deletion is never assessed: the result remains Safe, and the Bash gate permits execution. Bash executes the matching branch, leaving a home-directory deletion outside the protection this change is intended to provide. This bypass must be addressed before merging.
Recognize shell pattern boundaries, or require approval when the complete substitution cannot be read safely. Add this example as a regression test.
How this was verified: The actual assessment and Bash refusal function allowed the payload, while instrumented Bash invoked an intercepted deletion with the isolated home directory as its target.
Artifacts
Rust harness for assessment and bash refusal
- The executed harness calls the real assessment and gate APIs plus the exact production bash refusal function, exposing the policy result without executing deletion.
Safe parent and head reproduction script
- The executed script compiles revision-specific source and runs instrumented Bash with isolated HOME, making the comparison reproducible without invoking external rm.
Parent results with intercepted deletion
- The parent run captures assessment, gate, bash refusal, and instrumented shell traces for the payload and controls, showing that both substitution variants were allowed.
PR head results with intercepted deletion
- The head run captures the truncated case body and Safe/Allow result alongside Bash invoking the intercepted rm, confirming that the case-pattern bypass remains.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-command-risk/src/tokenize.rs
Line: 361-365
Comment:
**Case hides a deletion**
`matching_paren_body` treats a `case` pattern’s closing `)` as the end of the substitution. For `echo "$(case prod in prod) rm -rf ~ ;; esac)"`, it extracts only `case prod in prod`. The deletion is never assessed: the result remains `Safe`, and the Bash gate permits execution. Bash executes the matching branch, leaving a home-directory deletion outside the protection this change is intended to provide. This bypass must be addressed before merging.
Recognize shell pattern boundaries, or require approval when the complete substitution cannot be read safely. Add this example as a regression test.
**How this was verified:** The actual assessment and Bash refusal function allowed the payload, while instrumented Bash invoked an intercepted deletion with the isolated home directory as its target.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| while index < chars.len() { | ||
| match chars[index] { | ||
| '\\' => index += 2, |
There was a problem hiding this comment.
Comments block harmless commands
scan_substitutions reads substitutions inside shell comments. For example, echo ok # "$(rm -rf ~)" only prints ok, but the new scan extracts rm -rf ~ and makes the gate permanently deny the command, even with a justification. This is a non-blocking false-positive concern: harmless commands containing quoted shell examples in comments must be rewritten before the agent can run them.
Skip comments outside quoted words when reading shell source, while keeping # literal inside heredoc bodies. Add a regression test for this quoted comment.
Artifacts
- This test invokes the actual assess and gate APIs for the claimed command and controls, making the before/after verdicts reproducible.
Executed comparison and safe Bash runner
- This runner compiles unchanged parent and candidate source snapshots and executes the guarded Bash command, reproducing the regression without editing production or performing deletion.
Parent behavior for the harmless commented command
- The parent contract and guarded Bash command were executed successfully, showing Safe/Allow and Bash output ok.
Candidate denial of the harmless commented command
- The candidate contract and identical guarded Bash command were executed successfully, showing unconditional Catastrophic/Deny even though Bash still prints ok.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-command-risk/src/tokenize.rs
Line: 292-294
Comment:
**Comments block harmless commands**
`scan_substitutions` reads substitutions inside shell comments. For example, `echo ok # "$(rm -rf ~)"` only prints `ok`, but the new scan extracts `rm -rf ~` and makes the gate permanently deny the command, even with a justification. This is a non-blocking false-positive concern: harmless commands containing quoted shell examples in comments must be rewritten before the agent can run them.
Skip comments outside quoted words when reading shell source, while keeping `#` literal inside heredoc bodies. Add a regression test for this quoted comment.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let line = lines[index]; | ||
| shell_source.push_str(line); | ||
| index += 1; | ||
| for (delimiter, strip_tabs, quoted) in heredoc_delimiters(line.trim_end_matches('\n')) { |
There was a problem hiding this comment.
embedded_substitutions finds heredocs one line at a time, without carrying the surrounding quote state. For echo 'cat\n<<EOF\n$(rm -rf ~)\nEOF', with real newlines, Bash treats the entire argument as literal text. The new code instead sees an unquoted heredoc and scans its body, causing a permanent refusal even with a justification. This is a non-blocking false-positive concern: printing or writing these harmless multiline examples requires rewriting the command.
Carry quote state across lines before deciding that a heredoc starts.
Artifacts
Rust test harness for the multiline literal
- This executed harness calls the real assessment and gate APIs with the exact multiline command and asserts each revision’s observed result, demonstrating the false denial.
Reproduction commands for isolated before and after runs
- This executed script compiles immutable Git snapshots, runs the Rust harness and Bash with a disposable home, and captures both results without editing shared source.
Before-change assessment, gate response, and Bash output
- The parent revision’s real APIs and the exact Bash command were executed, showing Safe/Allow and harmless literal output.
After-change assessment, gate refusal, and Bash output
- The changed revision’s real APIs and the exact Bash command were executed, showing an unconditional Catastrophic/Deny despite harmless literal output.
Source line citations and unchanged working-tree check
- Source inspection and Git checks were executed, locating the per-line quote reset and refusal path while confirming no tracked source edits.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-command-risk/src/tokenize.rs
Line: 259
Comment:
**Quoted text triggers refusal**
`embedded_substitutions` finds heredocs one line at a time, without carrying the surrounding quote state. For `echo 'cat\n<<EOF\n$(rm -rf ~)\nEOF'`, with real newlines, Bash treats the entire argument as literal text. The new code instead sees an unquoted heredoc and scans its body, causing a permanent refusal even with a justification. This is a non-blocking false-positive concern: printing or writing these harmless multiline examples requires rewriting the command.
Carry quote state across lines before deciding that a heredoc starts.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for source in tokenize::embedded_substitutions(command) { | ||
| for finding in assess(&source, ctx).findings { |
There was a problem hiding this comment.
Nesting multiplies assessment work
assess now calls itself for each nested substitution without a depth or work limit, repeatedly copying and scanning the remaining source. A constructed 32,775-byte command with 4,096 nested substitutions took about 2.49 seconds to assess, compared with about 1.4 milliseconds before the change. Stack consumption also grows with nesting; an explicitly constrained 256 KiB stack overflowed at depth 1,024, although larger stacks completed the tested inputs.
This is a non-blocking responsiveness and robustness concern for unusually deep commands. Use an explicit work list and a work budget, or a depth limit that requires approval rather than silently skipping deeper commands.
Artifacts
Assessor test driver for balanced nested echo substitutions
- The executed Rust driver constructs bounded nested echo inputs, times the real assessor, and checks successful verdicts; shell commands are never executed.
Validation script with exact build commands and subprocess limits
- The executed Python script archives both commits, builds their unchanged assessor source, and captures bounded timing and stack probes; the comparison is reproducible.
Source citations and runtime environment
- Executed inspection commands captured commit identities, compiler version, absent setup file, and numbered assessor, tokenizer, and caller source; the tested change is traceable.
Exact parent assessor source compiled for the baseline
- Git archived the assessor source from ead5e66 and the harness compiled it unchanged; the executed baseline source is preserved.
Exact candidate assessor source compiled for validation
- Git archived the assessor source from 6b28600 and the harness compiled it unchanged; the executed candidate source is preserved.
Parent assessor timings and bounded stack probes
- The parent assessor ran identical nested inputs with recorded commands, working directories, exit codes, and limits; it remained fast and completed every stack probe.
Candidate assessor timings and constrained-stack overflow
- The candidate assessor ran the same inputs and limits, recording increased timings and a 256 KiB stack abort; the regression is executed rather than theoretical.
Complete validation command output
- The validation script was executed with its command, working directory, exit code, and full output captured; the overall run completed successfully despite the intentionally isolated abort.
- An executed git diff --exit-code returned zero after validation; no tracked source changes or fixes were introduced.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-command-risk/src/lib.rs
Line: 224-225
Comment:
**Nesting multiplies assessment work**
`assess` now calls itself for each nested substitution without a depth or work limit, repeatedly copying and scanning the remaining source. A constructed 32,775-byte command with 4,096 nested substitutions took about 2.49 seconds to assess, compared with about 1.4 milliseconds before the change. Stack consumption also grows with nesting; an explicitly constrained 256 KiB stack overflowed at depth 1,024, although larger stacks completed the tested inputs.
This is a non-blocking responsiveness and robustness concern for unusually deep commands. Use an explicit work list and a work budget, or a depth limit that requires approval rather than silently skipping deeper commands.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.683fb08 to
73006b7
Compare
…uoted heredocs (fixes #1753) The word tokenizer flattens double-quoted command substitutions and backticks into literals, and strips unquoted heredoc bodies, so destructive commands there were rated Safe. Extract each substitution body (skipping single quotes and quoted heredocs, which the shell does not expand) and assess it recursively like a top-level command.
73006b7 to
13375d1
Compare
| '\'' if shell_quotes && !in_double => { | ||
| index += 1; | ||
| while index < chars.len() && chars[index] != '\'' { | ||
| index += 1; | ||
| } | ||
| index += 1; |
There was a problem hiding this comment.
Quoted apostrophe hides a deletion
scan_substitutions misses commands after an escaped apostrophe in Bash $'...' text. For echo $'it\'s' "$(rm -rf ~)", it treats the escaped apostrophe as the closing quote, then treats the real closing apostrophe as a new opening quote. That skips the following substitution. assess returns Safe, so the Bash gate allows the home-directory deletion.
Recognize escapes inside $'...' and add this command as a regression test.
How this was verified: A source trace shows the quote loop skips the destructive substitution, while the Bash tool passes the original command to Bash, where $'it\'s' ends before the substitution.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-command-risk/src/tokenize.rs
Line: 295-300
Comment:
**Quoted apostrophe hides a deletion**
`scan_substitutions` misses commands after an escaped apostrophe in Bash `$'...'` text. For `echo $'it\'s' "$(rm -rf ~)"`, it treats the escaped apostrophe as the closing quote, then treats the real closing apostrophe as a new opening quote. That skips the following substitution. `assess` returns `Safe`, so the Bash gate allows the home-directory deletion.
Recognize escapes inside `$'...'` and add this command as a regression test.
**How this was verified:** A source trace shows the quote loop skips the destructive substitution, while the Bash tool passes the original command to Bash, where `$'it\'s'` ends before the substitution.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Two small fixes from automated triage, one commit each. Rebased after #1736 and #1739 merged, so the overlapping lines are gone.
#1740: remaining clippy/rustfmt failures on master
google.rs:ticks.is_multiple_of(30)(manual_is_multiple_of)jcode-tui: gate a test-only copy helper and thedisplay_col_sliceimport with#[cfg(test)], drop a needlessmutin a testopenai-runtime/src/lib.rs(drift reported by hosted CI)#1753: bash gate rated
"$(rm -rf ~)", backticks and unquoted heredoc substitutions Safetokenize::embedded_substitutionsextracts$(...)and backtick bodies from shell source (skipping single quotes) and from unquoted heredoc bodies (skipping quoted heredocs, which the shell leaves unexpanded).assessrecurses into each body and merges findings. It's additive, so verdicts can only get stricter.Validation
cargo clippy --all-targets --all-features -- -D warnings: clean (local rustc 1.98.1)cargo fmt --all -- --check: cleancargo test -p jcode-command-risk: 82 passed (2 new regression tests covering every row of the bash gate: destructive commands inside "$(...)", backticks or an unquoted heredoc are rated Safe #1753 table plus inert cases)cargo test -p jcode-tui --lib --no-run: compilesThe
Enforce oversized-file ratchetcheck fails identically onorigin/master(32 files over budget, tracked in #692). This PR grows none of them.Fixes #1740
Fixes #1753
--- — Jcode agent (automated triage), on behalf of @1jehuang