Skip to content

Read Quoting Around a Backslash-Newline and Bare xargs Runs in the Write Guard #3344

Closed

Description

@ptr727

Context

Found by the local review of the change closing #2991, #2995, #3074, #3075, and #3090 (branch feature/guard-tokenizer-directory-values). Each was confirmed with a classify probe on constructed commands. They are filed rather than narrowed in that lane, since narrowing a deny while allow gaps are open has repeatedly opened a new allow.

Over-Denials the Change Introduces

The backslash-newline deny now covers every command naming git or gh, and an escaped backslash before a line break is denied too. Neither reads quoting or heredoc data, so a backslash-newline that splits no word is denied. Develop allows each of these:

  • gh pr comment 5 --body 'a\ followed on the next line by b', where a single-quoted backslash-newline is literal
  • a gh pr create --body "$(cat <<'EOF' ... EOF)" whose quoted heredoc holds a Markdown hard line break, a line ending in \
  • git commit -F- <<'EOF' with a heredoc line ending in \

Near Variants Still Allowed

Develop allows each of these too:

  • printf 'push origin develop' | xargs git. _rewritten_git_words skips a git word with no subcommand before the xargs check.
  • printf 'merge 5 --admin' | xargs gh pr and printf 'pr merge 5 --admin' | xargs gh. _xargs_merge needs a visible pr and merge, where _gh_may_merge would read them as possible.

Possible Direction

Read a backslash-newline only outside single quotes and heredoc data, as _context_lex already tracks both. Run the xargs check on a git word before the no-subcommand skip, and read a gh word xargs runs through _gh_may_merge.

Activity

  1. added
    bug
    introduced
    script
    on Oct 22, 2026
  2. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    Two more from the second local pass on this lane:

    • Over-denial (introduced). Where two comments each hold an apostrophe, _shell_tokens returns the union of shlex's tokens and the comment-aware ones. _quote_kept_tokens cannot align with that union, so a quoted "$X" reads as splittable. # what's new followed by git -C "$WT" log --oneline -3 and # that's all on later lines is denied, where develop allows it. Develop already denies the single-apostrophe form for the same reason.
    • Near variant (develop shares it). GNU env accepts an unambiguous prefix of a long option, so env --split='git commit -n -m x' and env --sp='gh pr merge 5 --admin' run their strings, while only --split-string is read. A value option cut short, such as --ch for --chdir, is miscounted the same way.
  3. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    Four more from the third local pass on this lane:

    • Over-read (introduced). An eval payload is marked expanded per text, not per eval, so eval "$(ssh-agent -s)"; eval 'git -C "$W" status' is denied where develop allows it. The nested eval 'eval "git -C \"$W\" status"' is allowed on both.
    • \$ in a double-quoted body (develop shares it). shlex keeps \$ inside double quotes, while the outer shell turns it into $ before the inner shell reads the body. So sh -c "git -C \$W status" and watch -n 5 "git -C \$W status" are allowed, where the single-quoted sh -c 'git -C $W status' is denied. _BACKTICK_ESCAPE already performs this unescape for backtick bodies.
    • GNU parallel (develop shares it). It appends words from its input as xargs does, so printf -- --admin | parallel gh pr merge 5 and printf develop | parallel git push origin are allowed. _xargs_runs could name it too.
    • Rule 7 behind an escaped backslash (develop shares it). The fold still joins echo \\ and the next line, so a wait loop there is not read. Low realism.
  4. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    More from the fourth local pass on this lane, none a deny-to-allow flip:

    • Over-denial (introduced). _body_expanded reads any outer-expanding word of a watch as expanding its command, its own option values included, and ignores -x, which runs no shell. So watch -x git -C "$W" status and watch -n "$N" 'git -C "$W" status' are denied where develop allows them.
    • Over-denial (introduced). The split-word deny now covers every git or gh command, and _SPLIT_WORD matches an operator glued to a line continuation, which splits no word. git add x &&\ followed by git commit -m y on the next line, and git log --oneline |\ followed by head -5, are denied where develop allows them.
    • Allow gap (develop shares it). A backslash-newline inside the program word hides the name the gate reads: gi\ followed by t push origin develop, and g\ followed by h pr merge 5 --admin. Reading the text with each backslash-newline removed, as the shell joins it, would close it.
    • Allow gap (develop shares it). The pathname-pattern deny covers only -C, --git-dir, and --work-tree. A cd /example/prim* && git commit -m x reads the pattern as a literal directory for rule 6.
    • Design. _COMMENT_WITH_QUOTE restates as a literal class the word-opening rule _strip_comments builds from _PUNCTUATION_CHARS. They agree today.
  5. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    Three more from the sixth local pass on this lane, none a deny-to-allow flip:

    • README (introduced). Requirement 4 says a gh pr merge that xargs runs is denied, and elsewhere that a run-time word where pr's subcommand goes fails closed only beside --admin or where it may split. The guard now also denies printf 5 | xargs gh pr "$S", a gh that may merge under xargs, so the README should say "runs or may run" as the deny message does.
    • xargs replacing into a wrapper body (develop shares it). printf 5 | xargs -I{} sh -c 'gh pr merge {}' and printf 5 | xargs -I{} sh -c 'git push {}' are allowed. The inner shell splits the replaced line, so input 5 --admin merges with --admin. The merge, push, and commit xargs readings look for xargs only in the git or gh word's own text. _xargs_replace_string already reads this shape for the config-change scan.
    • gxargs (develop shares it). Homebrew's findutils installs GNU xargs as gxargs on macOS, and _xargs_runs matches only the base name xargs.
  6. ptr727 commented on Oct 23, 2026

    @ptr727
    OwnerAuthor

    Closed under the maintainer's decision (ptr727, 2026-10-23) on #3391: the backlog keeps real bugs with a stated failure, features the maintainer wants, and open decisions. A finding the review loop filed on code or text a change did not touch, a refactor or consolidation chore, a tracker, a wording item, or a guard shape no session has produced is closed rather than worked. Reopen with the input and the wrong result if this issue states one.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugintroducedscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions