Skip to content

fix(guard): close comment and arithmetic bypasses of the artifact guard - #231

Open
TornquistK wants to merge 1 commit into
mainfrom
workset/close-guard-comment-and-arithmetic-bypasses
Open

TornquistK wants to merge 1 commit into
mainfrom
workset/close-guard-comment-and-arithmetic-bypasses

Conversation

@TornquistK

Copy link
Copy Markdown
Collaborator

Summary

Seven command forms wrote a Markdown file into the Working Repository while the artifact guard exited 0. All seven came from two rules in commandTextMask (packages/mate-core/src/runtime/shell-heredoc.ts).

Form Example
Comment inside backticks echo hi `# why` > notes/x.md
# after $(…) echo $(date)#1 > notes/x.md
# after a backtick substitution echo `id`#1 > notes/x.md
# after an escaped space echo a\ #b > notes/x.md
# after $((…)) echo $((1+2))#b > notes/x.md
# inside ${…} k=${l%% #*}; echo hi > notes/x.md
$(( that is a subshell echo "$((cat > notes/x.md) </dev/null; true)"
 commandTextMask(text, spans)
-  "#" starts a comment when the char before it is whitespace, ;&|() or `
-  a comment ends at the newline
-  "$(" pushes "(";  "$((" always pushes "(("
+  "#" starts a comment only when wordStart is set
+    wordStart: offset 0, unquoted whitespace, ;&|(, a ")" that closes a subshell,
+               the opening of $(…) or a backtick substitution
+  in backticks a comment ends at the next unescaped backtick (or the newline)
+  "$(" pushes "$(", so its ")" clears wordStart
+  "${" pushes "${"; no comment starts inside it
+  "$((" looks ahead: inner "(" closes alone → push "$(", "(" (a subshell)
+                     otherwise → push "((" (arithmetic, as before)

Real comments and real arithmetic stay masked. The guard stays a heuristic, not a shell parser.

Evidence

  • Before: the new tables fail on exactly the seven forms; every control passes.
    shell-heredoc.test.ts             19 pass  7 fail
    validate-artifact-path.test.ts   128 pass  7 fail
    
    After:
    shell-heredoc.test.ts             26 pass  0 fail
    validate-artifact-path.test.ts   135 pass  0 fail
    mate-core (bun run test)        7075 pass  0 fail
    
  • Controls that keep exit 0: echo a # > notes/x.md, (echo a)#x > notes/x.md, echo $(echo a # c) > notes/x.md, echo hi `# > notes/x.md` , a backtick comment holding an escaped backtick, echo $((2 > 1)) notes/x.md, echo $(( (2 > 1) + 1 )) notes/x.md.
  • typecheck, lint, format:check and knip exit 0.

Merge Danger

Door: two-way

A revert restores the old scanner. Nothing persists.

Blast Radius: hooks

The artifact guard now refuses the seven forms above. The secret guard and the commit-attribution guard share the scanner for heredoc stripping: they see a change only for a << marker that follows one of these forms on the same line. Known trade-off: the $(( look-ahead ignores quotes, so a quoted ) inside arithmetic can flip the reading.

A # starts a comment only at a word start, a comment in backticks ends at the closing backtick, ${…} is a span, and $(( that closes with a lone ) is read as a substitution with a subshell.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant