You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2026/10/17 18:04:54 UTC
[PR] fix(agent-guard): see through env/command; refuse a quoted ~ and the eval wrapper's other spellings [magpie]
potiuk opened a new pull request, #1691:
URL: https://github.com/apache/magpie/pull/1691
## Summary
Closes #1679, plus one gap found while running the evals for #1683.
- **Prefix wrappers.** Every guard now looks through the wrappers that run their argument as the command: `env` (GNU/BSD options, including clustered short flags such as `-iu NAME`, `-uNAME` and `-iS'…'`, the long forms, the signal options, and `NAME=value` assignments, which still count as inline overrides) and `command` (`-p`). Before, `env git commit …` or `command gh pr comment …` reached no guard. `command -v git` is a lookup and is left alone.
- **Fail closed.** A wrapper the guards cannot parse makes `dispatch` refuse the line (`agent-guard[wrapper]`). That covers an undocumented option, an option missing its value, a `-S` string that does not tokenise, and nesting deeper than a generous limit.
- **Quoted `~`.** `vetted-ops-spelling` accepts a `~` base only when the raw line carries it bare and space-separated. A quoted or escaped `~` (`"~/…"`, `~"/…"`, `\~/…`) and the `--project=~/…` form are not expanded by the shell, so they would run inside the sandbox and fail.
- **Wrapped excluded commands.** The sandbox exclusion matches a command line by its start, so the right spelling behind `env` / `command` still runs sandboxed. This is now refused, with the command to run instead.
- **The eval wrapper.** `magpie-run-evals.sh` launched by anything but a bare `~/.claude/scripts/magpie-run-evals.sh` at the start of the line is refused: an expanded home, `$HOME`, a quoted `~`, a repository copy, or a wrapper. Each of those runs inside the sandbox, where every case errors without being graded, which happened while running the #1683 evals. Override: `MAGPIE_ALLOW_SCRIPT_PATH=1`.
- AGENTS.md's golden rule and the agent-guard README cover both.
## Type of change
- [ ] Skill change
- [x] Tool / bridge contract (agent-guard guard set)
- [x] Python package (`tools/agent-guard` engine + plugin copy)
- [ ] Groovy reference impl
- [x] Cross-cutting (AGENTS.md golden rule)
- [x] Documentation
- [ ] Project template
- [ ] CI / dev loop
## Test plan
- [x] `prek run --all-files` passes
- [x] `tools/agent-guard` tests. New cases cover:
- every guard family through each wrapper form, including clustered and attached option values and `-S`;
- an inline override after `env`;
- six unparsable wrappers, each refused;
- quoted, escaped and `=`-form `~`;
- wrapped vetted launches;
- eight wrong spellings of the eval wrapper, plus its override.
- [x] roborev `claude-code` security review of the branch: pass. The first commit's security review findings are fixed in the second.
## Notes for reviewers
- Still not unwrapped, and unchanged by this PR: other wrappers that run their argument (`nice`, `nohup`, `time`, `timeout`, `bash -c`, `exec`, GNU `env -`), and shell syntax the guards' `shlex` tokeniser reads differently from the shell (a newline as a command separator, `$'…'` quoting, command substitution). These are engine-wide parser differentials; they bypass every guard today and are worth their own issue. The guards stay defence in depth, not the sandbox.
---
Gen-AI disclosure: prepared with the assistance of Claude Code (Claude Opus 5); reviewed by the author.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(agent-guard): see through env/command; refuse a quoted ~ and the eval wrapper's other spellings [magpie]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #1691:
URL: https://github.com/apache/magpie/pull/1691
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org