Repository navigation
fix: stop refusing interpreter identifiers and gh and mkcert arguments as file reads - #64
Merged
Merged
Conversation
Interpreter source given with `-c` or `-e` or as a here-document went
through the tokenizer for shell text no parser can read, which takes
any word that starts with a dot, contains a slash or touches a quote as
a mention. A Rust builder chain `.env("A", "1")` quoted in a Python
here-document, or a JavaScript member such as `e.key`, was refused as
naming `.env` or `.key`.
The source now keeps its interpreter's language until it is scanned. A
word containing a slash is a mention anywhere; a bare name is one only
as a word of string content or a comment, unless it is escaped or
directly followed by `(`. The scanner follows each language's string
forms: Python triple-quoted strings and f-strings, JavaScript templates
and comments, Ruby `%` literals and heredocs, Perl quote-like operators
and regular expressions, PHP heredocs, Lua long brackets and
AppleScript comments. Interpolated code is read as code whose strings
are read again, so `${fs.readFileSync(".env")}` and `f"{name}.pem"`
stay refused. A word with a wildcard is checked as a pattern. Comments
are read like string content, as the contract for `# cat .env` in a
here-document requires.
Shell text no parser can read, such as `bash -c "$CODE"`, keeps the
broader rule.
`gh` was an unknown program, so every operand was read as a path: `gh search code --filename .env.local` and `gh api repos/o/r/contents/.env` were refused for names that only select what GitHub searches or returns, while `gh api --input .env` was refused as an ordinary read rather than as sending the file. The `search` verbs and `gh api` are now read from their documented options: queries, endpoints, `-f` fields and option values are names, and the files `--input` and `-F key=@FILE` send, other than standard input, are refused as `credential_upload`. Other gh commands and undocumented options keep the unknown-program roles. `mkcert` was unknown as well, so a host name such as `server.key` was refused and `-key-file ~/.ssh/id_rsa` was reported as a read. Its options follow Go's flag package, which the new `Syntax::Go` binds: one dash or two, a value glued with `=` or in the next word, a boolean that takes a value only when glued, and no options after the first operand. `-cert-file`, `-key-file` and `-p12-file` are writes, `-csr` is a read, and operands are host names. A write into an `.ssh` directory was refused with the message for reading private keys. It now has its own marker, `ssh_private_write`, whose alternative is to write under a project or temporary directory and ask the user to install the file.
`python3 - <<'EOF'` was checked as interpreter source, but the same
here-document piped as `cat <<'EOF' | python3` was not: only a direct
here-document or here-string became inline code, so moving the source
into a pipeline let `open('.env')` through.
When an interpreter's standard input is a pipe whose text the shell
evaluator models, the known text is now recorded on the command, and
target inference reads it with the interpreter's scanner when the
interpreter takes its program from standard input: no code option, and
no operand other than `-`. Text piped to a script, a module or a code
option stays that program's data, and pipes into other programs are not
read as code.
Release notes were written in the release commit by reconstructing them from the commit range, so each release had to review every change again. A pull request whose change readers of the notes need now adds or updates its entry in `docs/releases/unreleased.md`, and a later pull request that changes the same behavior updates that entry. The release commit renames the file to `docs/releases/<version>.md` with the version heading and repins its `main` links to the tag, so the publish workflow, which reads that file, is unchanged. AGENTS.md carries the pull-request rule because it loads before any change is made; the release skill keeps how entries are written and the rename at release. Add this branch's entry: interpreter identifiers, piped interpreter source, gh search and api roles, mkcert roles, and the `ssh_private_write` reason ID.
Drop doc comments that only repeat a name, a signature or the control flow beside them, and move the two rationales worth keeping (a mention is judged as a read; a pflag boolean takes a value only when glued) onto the items that own them. Remove inline-mention fixture rows that another row already catches on the same scanner path and partition, and file the piped builder chain under piped source, since `python3` runs that text as its program. The release note keeps the affected `-c`, `-e` and here-document scope without the old implementation detail. The scanner loop no longer matches an empty stack, whose bottom frame is never popped, and the Perl quote-like check rejects a preceding character before reading the operator name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agents were refused for code that never touches a credential: a Python here-document building a command with
.env("A", "1"), a JavaScript template such as`${at()} keydown ${e.key}`,gh search code --filename .env.local, andmkcert -cert-file .certs/local.pem -key-file .certs/local-key.pem x.local. There were two causes. Interpreter source went through the tokenizer used for shell text the guard cannot parse, and every candidate became a read.ghandmkcertwere unmodelled, so every operand was read as a local file.Interpreter source is now scanned in its own language, with code, string and interpolation states. A name with a slash counts anywhere. A name without one counts only inside a string or a comment, and not when it is called as
name(. Interpolated code is scanned again, sof"{name}.pem"is still refused. Uncertain shell fragments keep the previous rules.open(".env"),os.system("cat ~/.ssh/id_rsa"),glob(".env*")andPath.home()/".npmrc"are still refused. A protected directory mentioned in prose, such as"no ~/.claude here", also stays refused. Allowing a lone store directory inside a multiword string would also allowos.system("cp -R ~/.claude /tmp/x"), so that case is listed under known limits instead.gh search code|commits|issues|prs|reposandgh apinow have complete option grammars taken from the gh 2.105 manual. Queries, endpoints, filters and-f key=@FILEvalues are names.--input FILEand-F key=@FILEsend a local file and are refused ascredential_uploadwhen that file is protected. Other gh commands are unchanged.mkcertoptions follow Go's flag package, which the newSyntax::Gobinds.-cert-file,-key-fileand-p12-fileare writes,-csris a read, and operands are host names, including words after the first host name, as mkcert reads them.Writes into an
.sshdirectory get a new reason ID,ssh_private_write, instead ofssh_privateorcredential_file. The new message suggests writing under a project or temporary directory and asking the user to install the file. Tooling that matches the old IDs for these writes needs updating.Interpreter source piped into an interpreter is now checked:
cat <<'EOF' | python3withopen('.env')in it is refused likepython3 - <<'EOF'already was. This applies only when the interpreter takes its program from standard input. Data piped intopython3 script.py,python3 -m json.toolor-ccode is still that program's input. This is the only tightening, so it has its own commit.The last commit moves release notes into pull requests. A change that readers of the notes need adds or updates its entry in
docs/releases/unreleased.md, and the release commit renames that file todocs/releases/<version>.md, whichpublish.ymlalready reads. This branch's entry is included.make checkpasses. The 133 commands from the design were run through release builds of 0.8.17 and this branch. Every verdict that changed is listed indocs/releases/unreleased.md, and every command that had to stay refused or allowed kept its verdict. Weakening each new decision toward the weaker verdict fails a named fixture row: 14 for interpreter scanning, 12 for the gh and mkcert grammars, and 7 for piped source. Median latency throughbin/agent-guardwas 12.33 ms against 12.74 ms for 0.8.17, over 30 paired rounds of seven events, with load between 5.89 and 6.60.