fix(validator): read frontmatter as YAML does #253

Merged
claudiomaradonna merged 1 commit from validator-frontmatter-delimiters into main 2026-11-23 20:06:08 +01:00
Collaborator

Why

The validator is the gate that keeps the agent adapters read-only, but
it selected the frontmatter region with awk programs that count a line
as a delimiter only when it is exactly ---, while OpenCode follows
YAML document boundaries. On a file opening with a byte order mark —
or with trailing spaces, tabs, or CR breaks on the delimiters — the
two disagree: the pinned permissions block can sit in the body while
the frontmatter the client actually parses holds permissive rules, and
the check still printed agent configuration statically valid. Issue
#245 records the reproduction; at 6930f9c the crafted
{"action": "*","resource": "*","effect": "allow"} rule reached the
change reviewer's effective permissions with the validator green. The
same strictness refused honest files: an adapter saved with a BOM or
CRLF was rejected with a misleading "permissions block missing or
altered".

Closes #245

What changed

One frontmatter_region helper in scripts/verify-agent-config.sh
now selects the region the way OpenCode's YAML parser reads the
document boundary: it strips one leading BOM, drops a CR at each
line's end, accepts /^---[ \t]*$/ as the delimiter, and requires the
first line (after the BOM) to be a delimiter with a closing one. When
no such region exists it yields nothing, so the pinned block
comparison and the skill name: and description: greps refuse the
file instead of silently comparing body text. check_skill and
check_permissions share it. The check stays purely textual: no YAML
-parser dependency.

The adapter and skill areas gained eleven cases: BOM, trailing-space,
and trailing-tab crafted adapters and a CR-crafted one, an adapter
with no closing delimiter, legitimate adapters opened with a BOM, a
trailing space, or CRLF endings, a skill with no closing delimiter, a
BOM'd skill hiding its name in the body, and a legitimate BOM'd
skill. The bypass-fixture helper derives its body copy from the
fixture's own permissions block and fails loudly when none exists, so
the crafted cases cannot pass vacuously if the pin ever changes.

How to verify

From a fresh checkout, base 6930f9c and branch
validator-frontmatter-delimiters (7a5baef):

  • Crafted shapes refused, and provably so: at the base,
    bash tests/agent-config/reviewer-adapters.sh with this branch's
    test files fails the bypass cases as unexpectedly valid and the
    legitimate-shape cases with exit 1; at the tip the area passes
    19/19 (all run). repro.sh from the issue's text prints PASS #245: validator rejected the crafted adapter with the tip's script, where
    at the base it prints FAIL #245: validator accepted a crafted adapter (run on both).
  • Skill shapes: bash tests/agent-config/skills.sh 11/11 at the tip;
    at the base with these test files the unclosed and BOM'd legitimate
    skills fail (run).
  • Full gates at the tip, all run: bash tests/verify-agent-config.sh
    358/358, .agents/hooks/shellcheck.sh repo 51 files clean,
    prettier --check '**/*.md', scripts/verify-agent-config.sh
    statically valid, git diff --check main clean. The shipped adapters
    and skills are unchanged and keep validating.

Considerations

  • Two cases are pins, verified passing on the base and the tip: the
    BOM'd skill hiding its name (the old check refused it too, by a
    different path) and the CR-crafted adapter.
  • Reviewers' adversarial probes (multi-document files, in-region
    parse-error shapes, duplicate keys) found no validator-accepted
    shape that yields permissive effective rules.
  • Behavioral evals stay maintainer-run and were not run: the change
    touches only the validator and its tests.
## Why The validator is the gate that keeps the agent adapters read-only, but it selected the frontmatter region with awk programs that count a line as a delimiter only when it is exactly `---`, while OpenCode follows YAML document boundaries. On a file opening with a byte order mark — or with trailing spaces, tabs, or CR breaks on the delimiters — the two disagree: the pinned permissions block can sit in the body while the frontmatter the client actually parses holds permissive rules, and the check still printed `agent configuration statically valid`. Issue #245 records the reproduction; at `6930f9c` the crafted `{"action": "*","resource": "*","effect": "allow"}` rule reached the change reviewer's effective permissions with the validator green. The same strictness refused honest files: an adapter saved with a BOM or CRLF was rejected with a misleading "permissions block missing or altered". Closes #245 ## What changed One `frontmatter_region` helper in `scripts/verify-agent-config.sh` now selects the region the way OpenCode's YAML parser reads the document boundary: it strips one leading BOM, drops a CR at each line's end, accepts `/^---[ \t]*$/` as the delimiter, and requires the first line (after the BOM) to be a delimiter with a closing one. When no such region exists it yields nothing, so the pinned block comparison and the skill `name:` and `description:` greps refuse the file instead of silently comparing body text. `check_skill` and `check_permissions` share it. The check stays purely textual: no YAML -parser dependency. The adapter and skill areas gained eleven cases: BOM, trailing-space, and trailing-tab crafted adapters and a CR-crafted one, an adapter with no closing delimiter, legitimate adapters opened with a BOM, a trailing space, or CRLF endings, a skill with no closing delimiter, a BOM'd skill hiding its name in the body, and a legitimate BOM'd skill. The bypass-fixture helper derives its body copy from the fixture's own permissions block and fails loudly when none exists, so the crafted cases cannot pass vacuously if the pin ever changes. ## How to verify From a fresh checkout, base `6930f9c` and branch `validator-frontmatter-delimiters` (`7a5baef`): - Crafted shapes refused, and provably so: at the base, `bash tests/agent-config/reviewer-adapters.sh` with this branch's test files fails the bypass cases as `unexpectedly valid` and the legitimate-shape cases with exit 1; at the tip the area passes 19/19 (all run). `repro.sh` from the issue's text prints `PASS #245: validator rejected the crafted adapter` with the tip's script, where at the base it prints `FAIL #245: validator accepted a crafted adapter` (run on both). - Skill shapes: `bash tests/agent-config/skills.sh` 11/11 at the tip; at the base with these test files the unclosed and BOM'd legitimate skills fail (run). - Full gates at the tip, all run: `bash tests/verify-agent-config.sh` 358/358, `.agents/hooks/shellcheck.sh repo` 51 files clean, `prettier --check '**/*.md'`, `scripts/verify-agent-config.sh` statically valid, `git diff --check main` clean. The shipped adapters and skills are unchanged and keep validating. ## Considerations - Two cases are pins, verified passing on the base and the tip: the BOM'd skill hiding its name (the old check refused it too, by a different path) and the CR-crafted adapter. - Reviewers' adversarial probes (multi-document files, in-region parse-error shapes, duplicate keys) found no validator-accepted shape that yields permissive effective rules. - Behavioral evals stay maintainer-run and were not run: the change touches only the validator and its tests.
fix(validator): read frontmatter as YAML does
All checks were successful
Maintenance / checks (pull_request) Successful in 7m54s
Maintenance / checks (push) Successful in 7m27s
7a5baef680
The pins compared text between exact --- lines while OpenCode
follows YAML document boundaries, so a BOM, a trailing space or
tab, or a CR moved the region and a crafted adapter with an
allow-all rule passed the read-only check with the pinned block
copied into the body (issue #245). One frontmatter_region helper
now strips a leading BOM, drops line-ending CRs, tolerates
trailing blanks in the delimiters, and fails closed when the
region cannot be selected, so the pins and the skill name and
description greps refuse the file instead of reading body text.
claudiomaradonna deleted branch validator-frontmatter-delimiters 2026-11-23 20:06:17 +01:00
Sign in to join this conversation.
No description provided.