fix(validator): keep hidden rules out of the pin #246

Merged
claudiomaradonna merged 2 commits from validator-blankline-pin into main 2026-11-21 22:59:38 +01:00
Collaborator

Why

scripts/verify-agent-config.sh is how this source, and every project
that adopts it, holds the seven OpenCode adapters to their pinned
permission lists: check_permissions compares the frontmatter's
permissions: block as exact text, so an adapter whose read-only reviewer
gained a web tool fails the check. That guarantee depended on how the
block's lines are collected. Extraction kept the permissions: key and
the lines after it that start with two spaces, and stopped at any other
line — including one a YAML block sequence happily survives. The rules
after such a line stayed part of the same list for OpenCode and vanished
from the comparison, so the tampering passed. Reported by security-reviewer
while reviewing pull request #242, filed as #244.

What changed

check_permissions now ends the block where YAML ends it: at a line that
starts with neither whitespace nor #. Empty lines, lines of whitespace
only, and comments at any indentation therefore reach the exact-text
comparison, and since no pinned block holds one, a file that hides a rule
behind them fails with the diagnostic it already knows,
permissions block missing or altered. A top-level key after the block
still ends the block, so a project adding the model: the tuning guide
suggests below its list is unaffected.

Three tamperings land as regression tests beside the other OpenCode
reviewer cases, one per line form — the empty line, a tab, and a comment —
each built by a new opencode_hidden_grant helper that takes the line to
insert. A separate commit, before the fix, pins the tuning placement:
accepts an OpenCode reviewer adapter with a key after its permissions block.

How to verify

Base f491863, branch validator-blankline-pin at 89f4139. From a
fresh checkout, bash tests/verify-agent-config.sh prints
all 337 agent configuration tests passed; the base passes with its own
333.

The three guards use a helper the branch adds, so they fail on the base's
code:

git worktree add --detach /tmp/base-code f491863
cd /tmp/base-code
git checkout validator-blankline-pin -- tests/agent-config/lib.sh \
  tests/agent-config/reviewer-adapters.sh
bash tests/agent-config/reviewer-adapters.sh

The three cases print not ok — unexpectedly valid and the area exits 1;
the same file on the branch prints ok for all eleven cases. Run and
reported from this session.

To see the bypass in the client, which needs no model call: seed a scratch
git repository with the branch's .opencode/agents/ and a stub
AGENTS.md, add a hidden rule to change-reviewer.md after a line of
your choosing — # tidy on its own at column zero, then

  - action: "webfetch"
    resource: "*"
    effect: "allow"

On the base, scripts/verify-agent-config.sh <that repository> says
statically valid while opencode debug agents (OpenCode v2.3.2) shows
that reviewer holding webfetch/*=allow; on this branch the same file
reports permissions block missing or altered. The three forms were run
this way, with results in the work folder.

Checks run at 89f4139, all passing: 337 agent-configuration tests, 46
work-folder check tests, scripts/verify-agent-config.sh valid
(state=template), shell check 51 files clean, prettier --check '**/*.md' clean, git diff --check main clean. Not run: the behavioral
evals, billed and maintainer-run; this change reaches no prompt.

Considerations

The pin stays a comparison of line shapes, so it is only as wide as what
the extraction recognizes; the permanent fix is parsing the frontmatter as
YAML, which needs a dependency the test commands do not have. A project
whose own adapter holds a comment or a whitespace-only line inside its
block now fails the check with the generic diagnostic — deliberate, since
the block is pinned text, and the diff shows the offending line. Two
pre-existing gaps in the same file, both unchanged by this branch, are
filed as #245: the delimiters the check trusts are not the ones the client
follows, and a CRLF checkout refuses a legitimate adapter.

## Why `scripts/verify-agent-config.sh` is how this source, and every project that adopts it, holds the seven OpenCode adapters to their pinned permission lists: `check_permissions` compares the frontmatter's `permissions:` block as exact text, so an adapter whose read-only reviewer gained a web tool fails the check. That guarantee depended on how the block's lines are collected. Extraction kept the `permissions:` key and the lines after it that start with two spaces, and stopped at any other line — including one a YAML block sequence happily survives. The rules after such a line stayed part of the same list for OpenCode and vanished from the comparison, so the tampering passed. Reported by `security-reviewer` while reviewing pull request #242, filed as #244. ## What changed `check_permissions` now ends the block where YAML ends it: at a line that starts with neither whitespace nor `#`. Empty lines, lines of whitespace only, and comments at any indentation therefore reach the exact-text comparison, and since no pinned block holds one, a file that hides a rule behind them fails with the diagnostic it already knows, `permissions block missing or altered`. A top-level key after the block still ends the block, so a project adding the `model:` the tuning guide suggests below its list is unaffected. Three tamperings land as regression tests beside the other OpenCode reviewer cases, one per line form — the empty line, a tab, and a comment — each built by a new `opencode_hidden_grant` helper that takes the line to insert. A separate commit, before the fix, pins the tuning placement: `accepts an OpenCode reviewer adapter with a key after its permissions block`. ## How to verify Base `f491863`, branch `validator-blankline-pin` at `89f4139`. From a fresh checkout, `bash tests/verify-agent-config.sh` prints `all 337 agent configuration tests passed`; the base passes with its own 333. The three guards use a helper the branch adds, so they fail on the base's code: ```bash git worktree add --detach /tmp/base-code f491863 cd /tmp/base-code git checkout validator-blankline-pin -- tests/agent-config/lib.sh \ tests/agent-config/reviewer-adapters.sh bash tests/agent-config/reviewer-adapters.sh ``` The three cases print `not ok — unexpectedly valid` and the area exits 1; the same file on the branch prints `ok` for all eleven cases. Run and reported from this session. To see the bypass in the client, which needs no model call: seed a scratch git repository with the branch's `.opencode/agents/` and a stub `AGENTS.md`, add a hidden rule to `change-reviewer.md` after a line of your choosing — `# tidy` on its own at column zero, then ```yaml - action: "webfetch" resource: "*" effect: "allow" ``` On the base, `scripts/verify-agent-config.sh <that repository>` says `statically valid` while `opencode debug agents` (OpenCode v2.3.2) shows that reviewer holding `webfetch/*=allow`; on this branch the same file reports `permissions block missing or altered`. The three forms were run this way, with results in the work folder. Checks run at `89f4139`, all passing: 337 agent-configuration tests, 46 work-folder check tests, `scripts/verify-agent-config.sh` valid (`state=template`), shell check 51 files clean, `prettier --check '**/*.md'` clean, `git diff --check main` clean. Not run: the behavioral evals, billed and maintainer-run; this change reaches no prompt. ## Considerations The pin stays a comparison of line shapes, so it is only as wide as what the extraction recognizes; the permanent fix is parsing the frontmatter as YAML, which needs a dependency the test commands do not have. A project whose own adapter holds a comment or a whitespace-only line inside its block now fails the check with the generic diagnostic — deliberate, since the block is pinned text, and the diff shows the offending line. Two pre-existing gaps in the same file, both unchanged by this branch, are filed as #245: the delimiters the check trusts are not the ones the client follows, and a CRLF checkout refuses a legitimate adapter.
The OpenCode permission-block check compares the block as exact text and
ends its extraction at the first line starting at column zero, so a
project that adds the model the tuning guide suggests below the list
keeps its adapter valid. Pin that placement before the fix lands: an
OpenCode reviewer whose frontmatter carries model: example/model after
its permissions list still validates, so the change cannot quietly
refuse a tuned adapter.

Refs #244
fix(validator): keep hidden rules out of the pin
All checks were successful
Maintenance / checks (pull_request) Successful in 6m16s
Maintenance / checks (push) Successful in 5m36s
89f41392d4
check_permissions ended a permissions block at the first line that was
neither the key nor indented, while YAML keeps a block sequence open
across empty lines, lines of whitespace only, and comments at any
indentation. OpenCode parsed the rules after such a line as part of the
same list, so a read-only reviewer could hold webfetch and the exact
text of the pin still reported the adapter pinned; the hidden grant
reached the agent's tools on OpenCode v2.3.2.

End the block where YAML ends it, at a line starting with neither
whitespace nor a hash, so every line a sequence tolerates reaches the
comparison and no pinned block holds one, and land the three tamperings
as regression tests beside the other OpenCode reviewer cases.
A top-level key after the block still ends the block, which the pin in
the previous commit guards.

Closes #244
Sign in to join this conversation.
No description provided.