validator trusts frontmatter delimiters the client does not #245

Closed
opened 2026-11-21 22:28:54 +01:00 by motoko · 0 comments
Collaborator

Location

scripts/verify-agent-config.sh, check_permissions: the frontmatter
region is chosen at line 431 (frontmatter=$(awk '/^---$/ …')), the block
extraction counts the same delimiters at line 444, and the comparison is at
line 449.

Evidence

The validator treats a line that is exactly --- as the frontmatter's
opening and closing delimiter. OpenCode follows YAML's document boundaries,
which tolerate a leading byte-order mark, a trailing space or tab, and a
\r line break, and which do not require a delimiter at all. Where the two
disagree, the check compares text the client never reads: the pinned block
can sit in the body, and the frontmatter the client parses can hold nothing
that the pin sees.

security-reviewer reproduced this on OpenCode v2.3.2 at f491863 and on
the validator-blankline-pin tip, reading the parsed grants with
opencode debug agents. The crafted files and their exact bytes stay in
the review record, not here.

Scenario

A contributor's pull request against an adopting project changes only the
first bytes of .opencode/agents/change-reviewer.md — a UTF-8 BOM, which
no editor shows and which git diff renders as --- on both sides — and
copies the permissions block into the body as a fenced example.
bash tests/verify-agent-config.sh, CI, and the maintainer's own
scripts/verify-agent-config.sh print statically valid, while OpenCode
runs that read-only reviewer with its defaults: edit, write, shell,
webfetch and websearch all available. The same disagreement also disarms
the mixing rule at lines 434-435, which greps the same region: a frontmatter
carrying both a V1 permission: map and a V2 permissions: list passes.
A checkout with CRLF line endings fails in the other direction, refusing a
legitimate adapter because no delimiter is counted; the template ships no
.gitattributes.

Smallest fix

Fail closed on the region rather than on the block: strip a leading BOM,
accept /^---[ \t]*\r?$/ as the delimiter in both awk programs, and report
frontmatter delimiters missing or altered when line 1 is not one, or no
closing delimiter follows. The seven shipped adapters open with --- and
no tracked file holds a BOM or a CR, so this refuses nothing today. A
... document-end marker belongs with the same family: neither program
recognizes it. The permanent fix is extracting through a YAML parser, which
needs a dependency the Test and Verify commands do not have.

Seen at f491863, and unchanged on 89f4139. Reported by
security-reviewer during the review of the branch that closes #244.

## Location `scripts/verify-agent-config.sh`, `check_permissions`: the frontmatter region is chosen at line 431 (`frontmatter=$(awk '/^---$/ …')`), the block extraction counts the same delimiters at line 444, and the comparison is at line 449. ## Evidence The validator treats a line that is exactly `---` as the frontmatter's opening and closing delimiter. OpenCode follows YAML's document boundaries, which tolerate a leading byte-order mark, a trailing space or tab, and a `\r` line break, and which do not require a delimiter at all. Where the two disagree, the check compares text the client never reads: the pinned block can sit in the body, and the frontmatter the client parses can hold nothing that the pin sees. `security-reviewer` reproduced this on OpenCode v2.3.2 at `f491863` and on the `validator-blankline-pin` tip, reading the parsed grants with `opencode debug agents`. The crafted files and their exact bytes stay in the review record, not here. ## Scenario A contributor's pull request against an adopting project changes only the first bytes of `.opencode/agents/change-reviewer.md` — a UTF-8 BOM, which no editor shows and which `git diff` renders as `---` on both sides — and copies the permissions block into the body as a fenced example. `bash tests/verify-agent-config.sh`, CI, and the maintainer's own `scripts/verify-agent-config.sh` print `statically valid`, while OpenCode runs that read-only reviewer with its defaults: `edit`, `write`, `shell`, `webfetch` and `websearch` all available. The same disagreement also disarms the mixing rule at lines 434-435, which greps the same region: a frontmatter carrying both a V1 `permission:` map and a V2 `permissions:` list passes. A checkout with CRLF line endings fails in the other direction, refusing a legitimate adapter because no delimiter is counted; the template ships no `.gitattributes`. ## Smallest fix Fail closed on the region rather than on the block: strip a leading BOM, accept `/^---[ \t]*\r?$/` as the delimiter in both awk programs, and report `frontmatter delimiters missing or altered` when line 1 is not one, or no closing delimiter follows. The seven shipped adapters open with `---` and no tracked file holds a BOM or a CR, so this refuses nothing today. A `...` document-end marker belongs with the same family: neither program recognizes it. The permanent fix is extracting through a YAML parser, which needs a dependency the Test and Verify commands do not have. Seen at `f491863`, and unchanged on `89f4139`. Reported by `security-reviewer` during the review of the branch that closes #244.
Sign in to join this conversation.
No description provided.