Skip to content

fix(skills): narrow the broad allowed-tools grants the portal didn't flag — qa gh api, clean rm/find, setup curl/sed #1292

Closed

Description

@admarble

Tier: judgment Found: 2026-10-03, #1287 spec and QA (PR #1291)

Problem. #1287 narrowed the grants the plugin directory portal flagged: bare Bash, Bash(*), and wildcards after gh/git/npm/npx and runners. These allowed-tools entries on main grant comparable reach, but the portal didn't list them and #1287's gate doesn't reject them:

  • qa: Bash(gh api:*). Arbitrary REST/GraphQL calls, including -X DELETE and PATCH, run without a prompt while /qa is active. The qa body uses gh api for reads (PR body, check-runs, closing references).
  • clean: Bash(rm:*), Bash(mv:*), Bash(find:*). find … -delete and rm -rf <any path> are pre-approved.
  • setup: Bash(curl:*), Bash(sed:*) (sed -i on any file), Bash(cat:*), Bash(cp:*), Bash(jq:*).
  • test: Bash(jq:*). Low risk (jq can't execute), listed for completeness.

Like #1287, this affects interactive use only. sequant run phases use bypassPermissions.

AC

Non-Goals

Graph metadata

May touch

  • .claude/skills/{qa,clean,setup,test}/SKILL.md (+ synced mirrors), src/lib/__tests__/skill-allowed-tools-gate.test.ts

Activity

  1. added
    enhancement
    on Oct 3, 2026
  2. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Scope update (2026-10-03): setup's Bash(curl:*) was dropped in PR #1291. The plugin directory portal flagged it under the same hold as #1287, and setup's body never runs curl. The remaining items here are qa gh api:*, clean rm/mv/find, setup sed/cat/cp/jq, and test jq. The #1287 gate also rejects curl */wget * now.

  3. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    Upstream causes (2026-10-05)

    1. #1287's gate rejects only one exact pattern. src/lib/__tests__/skill-allowed-tools-gate.test.ts:47 rejects an entry only when cmd === "<tool> *" for a tool in BROAD_TOOLS. Two consequences:

    • Bash(gh api:*) passes, because the wildcard follows a subcommand. gh api can still send -X DELETE and PATCH.
    • rm, mv, find, sed and cp are not in BROAD_TOOLS at all.

    The gate encodes the portal's definition of "broad" (it runs code) as a denylist. Commands that can delete or overwrite files are outside that definition, so the gate never sees them. AC-2 adds more names to the denylist. That fixes this round, and the next unlisted command will need its own issue.

    Decision for this issue: extend the denylist (AC-2 as written), or switch to an allowlist of reviewed entries, each with a reason, so a new broad entry fails by default. The allowlist costs one review line per new grant.

    2. gh api in qa bypasses the platform layer. qa/SKILL.md:973-979 (check-runs, annotations) and :2241-2260 (comment-marker reads) call gh api directly from the skill markdown. GitHubProvider is meant to own gh. If a sequant subcommand did those reads, the grant could be removed rather than narrowed. A narrow alternative is to grant only the endpoints the skill calls: Bash(gh api repos/*/commits/*/check-runs*) and similar, with no -X.

    3. clean's rm and find follow from what the skill does. That isn't a design problem. Scope them to the paths the skill cleans, for example worktree dirs and .sequant/ artifacts.

  4. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    Runner context (2026-10-05, before sequant run)

    • Implement AC-2 as written. Reject the listed entries unless an allowlist entry names them with a reason. My earlier comment's denylist-vs-allowlist question is not for this run. If the owner wants a default-deny gate, that is a separate follow-up.
    • Producer and mirrors. Edit templates/skills/<name>/SKILL.md and .claude/skills/<name>/SKILL.md. Regenerate plugin/skills/ with npx tsx scripts/check-skill-sync.ts --fix, then run npm run lint:skill-sync && npm run lint:skill-calls. The gate walks every SKILL_ROOTS root.
    • qa's gh api. Every gh api call in qa/SKILL.md and its references/ is a GET. Narrow the grant to the endpoints those calls use, or remove it and list the new prompts. Don't grant -X.
    • The PR body's AC-1 table needs one row per entry: qa gh api, clean rm/mv/find, setup sed/cat/cp/jq, test jq. List each command that will now prompt.

    Phase rules (all phases):

  5. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (2 ACs, 4 directories: .claude/skills, templates/skills, plugin/skills, src/lib/__tests__)

    AC Quality Check

    • AC-1: Both lines have Evidence: clauses and are measurable. AC-1 offers three dispositions: narrow, remove, or keep with a reason. Each entry's recommended disposition is in the plan below, so exec does not have to choose.
    • AC-2: The evidence is not vacuous. On main, clean grants Bash(rm:*) and the gate passes, so the mutation (re-adding Bash(rm:*)) does not fail today. It fails only once the new rule exists.
    • Scope: The 2026-10-03 comment dropped setup's Bash(curl:*) in PR fix(#1287): skills stop pre-approving broad shell access in allowed-tools #1291, and the gate already rejects curl *. AC-2 still names Bash(curl:*). Keep it in the literal-entry test as a regression check, but no skill change is needed for it.

    Scope Assessment

    Non-Goals: headless phase permissions, and anything the portal already flagged (#1287).

    Metric Value Status
    Feature count 1 ✅
    AC items 2 ✅
    Directory spread 4 (3 are mirrors of one tree) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: Each listed grant is narrowed, removed, or kept with a reason

    Verification: Manual Test. Review the PR-body table against the frontmatter diff.
    Scenario: Given the 9 entries (qa gh api; clean rm/mv/find; setup sed/cat/cp/jq; test jq) → when exec edits the frontmatter → then the PR body has one row per entry with its disposition and the commands that will now prompt.
    Assumptions: These need checking before coding:

    • Claude Code permission rules accept * mid-pattern, as in Bash(mv * docs/archive/*).
    • Quoted arguments match the same way unquoted ones do.

    Recommended dispositions. Exec may deviate if it records why.

    Skill Entry What the body runs Recommended
    qa Bash(gh api:*) 3 GETs: check-runs (SKILL.md:973), gh api "$url" for annotations (:979), issues/comments?per_page=100 --paginate (:2260) Remove. The annotations call takes a runtime URL, so no pattern can cover it. Both call sites sit inside $(…)/while pipelines, which likely prompt anyway. Any endpoint pattern with a trailing * also matches an appended -X. The new prompts are bounded: the check-runs path runs only when every check fails. List them in the PR.
    clean Bash(mv:*) Moves files into the archive trees Narrow to Bash(mv * docs/archive/*) and Bash(mv * scripts/archive/*)
    clean Bash(rm:*) No rm in the body. Removing .DS_Store files and empty dirs is described in prose only. Remove. Those deletions will prompt.
    clean Bash(find:*) No find in the body. Scanning uses Glob. Remove. find … -delete/-exec is the risk.
    setup Bash(sed:*) Read-only sed in pipes (:78,124,130,133,148), plus sed -i.bak "s/{{PROJECT_NAME}}/…/g" .claude/memory/constitution.md (:335) Narrow to Bash(sed -i.bak * .claude/memory/constitution.md). Don't write {{ literally: the gate's AC-3 placeholder rule rejects it. The pipe sed calls prompt or are auto-read-only; record which.
    setup Bash(cp:*) cp "$CONST_SRC" .claude/memory/constitution.md (:328), cp -R "$SKILLS_SRC/$dir" ".claude/skills/$dir" (:363) Narrow to Bash(cp * .claude/memory/constitution.md) and Bash(cp -R * .claude/skills/*)
    setup Bash(cat:*) cat package.json (:119,249) Narrow to Bash(cat package.json)
    setup Bash(jq:*) jq filters on stdin Keep with reason: read-only, and it cannot run commands
    test Bash(jq:*) jq -r '.run.staleBranchThreshold…' .sequant/settings.json (:124) Keep with reason, same as setup. Optionally narrow to Bash(jq * .sequant/settings.json).

    AC-2: The gate rejects gh api/rm/curl/sed wildcards unless allowlisted with a reason

    Verification: Unit Test, mutation-verified.
    Scenario: Given Bash(rm:*) is re-added to .claude/skills/clean/SKILL.md → when npx vitest run src/lib/__tests__/skill-allowed-tools-gate.test.ts runs → then the .claude/skills policy case fails and names clean/SKILL.md: Bash(rm:*). Restore, and the test passes.
    Assumptions: violation() normalizes X:* to X *, so gh api:* becomes gh api *. This is already true at skill-allowed-tools-gate.test.ts:121.


    Implementation Plan

    Phase 1: Gate first (red)

    1. In src/lib/__tests__/skill-allowed-tools-gate.test.ts, add FILE_WRITE_TOOLS = ["gh api", "rm", "mv", "find", "sed", "cp"]. Add BROAD_ALLOWLIST: Record<string, string> (entry → reason), shaped like RUNNER_ALLOWLIST. violation() returns "file-writing or API wildcard not in BROAD_ALLOWLIST (#1292)" when cmd === "<t> *" and the entry is not allowlisted. curl is already in BROAD_TOOLS.
    2. Add an it.each over the 4 literal entries the AC names (Bash(gh api:*), Bash(rm:*), Bash(curl:*), Bash(sed:*)), asserting violation() is non-null. This proves the rule without depending on current skill content. Update the file's header doc block.
    3. Run the named test file. It should now fail on the existing qa/clean/setup entries. WIP commit.

    Phase 2: Narrow the grants (green)

    1. Edit .claude/skills/{qa,clean,setup,test}/SKILL.md frontmatter per the AC-1 table. Mirror the edits into templates/skills/…. Regenerate plugin/skills/ with npx tsx scripts/check-skill-sync.ts --fix.
    2. Run npx vitest run src/lib/__tests__/skill-allowed-tools-gate.test.ts, npm run lint:skill-sync, and npm run lint:skill-calls. WIP commit.

    Phase 3: Mutation and PR record

    1. Commit, then re-add Bash(rm:*) to .claude/skills/clean/SKILL.md, confirm the policy case fails, and restore. Put the record in exec's ## Summary, which the runner uses for the PR body (investigation(run): the exec output handed to createPR was not exec's final message — PR #1310 got the placeholder body although exec ended with a full ## Summary #1311): Mutation-verified: AC-2 — re-added Bash(rm:*) to .claude/skills/clean/SKILL.md; <case> failed; restored. and <!-- SEQUANT_MUTATION: {"ac":"AC-2","mutation":"re-add Bash(rm:*) to .claude/skills/clean/SKILL.md","failedTest":"src/lib/__tests__/skill-allowed-tools-gate.test.ts > skill allowed-tools grant no broad shell access (#1287) > .claude/skills — no bare Bash, Bash(*), tool or runner wildcard, or placeholder"} -->. The test file path comes first in failedTest, and the case title must match the real test title after any rename.
    2. Add the AC-1 table to the Summary: one row per entry, with the commands that now prompt.

    Design Review

    1. Where does this logic belong? The skill frontmatter (the grants) and the existing fix(skills): narrow broad allowed-tools grants — bare Bash, Bash(*), and runner wildcards hold the directory listing for review #1287 gate test. No runtime TypeScript reads allowed-tools.

    2. What's the simplest correct approach? Extend the existing gate with one tool list and one allowlist, matching the existing RUNNER_ALLOWLIST idiom. Rejected alternative: a default-deny allowlist of every reviewed grant. The owner deferred it in the 2026-10-05 runner comment, so it does not belong in this PR. That is a deferral, not a design choice in the plan, so no ADR is needed.

    3. What existing pattern does this follow, and how often has it been re-patched? The denylist gate from fix(skills): narrow broad allowed-tools grants — bare Bash, Bash(*), and runner wildcards hold the directory listing for review #1287, which PR fix(#1287): skills stop pre-approving broad shell access in allowed-tools #1291 extended with curl/wget. This is the second issue on the class: fix(skills): narrow broad allowed-tools grants — bare Bash, Bash(*), and runner wildcards hold the directory listing for review #1287, then fix(skills): narrow the broad allowed-tools grants the portal didn't flag — qa gh api, clean rm/find, setup curl/sed #1292. Deliberately local, reason: the owner directed "implement AC-2 as written" (runner context, 2026-10-05). The class, an unlisted broad command passing by default, is not yet tracked. Recommend filing the default-deny follow-up before merge. A third issue on this class would cross the ≥2-prior-fixes stop.

    4. What would a senior reviewer challenge?

      • "Why not narrow qa's gh api to endpoints?" The annotations call (gh api "$url") can't be expressed as a pattern, and a trailing * still matches -X DELETE.
      • "Is mv * docs/archive/* actually safe?" The * matches spaces, so a multi-source mv still lands inside the archive tree. That is acceptable, but record it.
    5. Every producer and consumer of the artifact. Producers: .claude/skills/<s>/SKILL.md (source per SKILL_SOURCE_ROOT) and templates/skills/<s>/SKILL.md, both hand-edited. plugin/skills/<s>/SKILL.md is generated by check-skill-sync.ts --fix. Consumers:

      • Claude Code's permission matcher (interactive only)
      • skill-allowed-tools-gate.test.ts, which walks SKILL_ROOTS
      • check-skill-sync.ts, which checks parity
      • sequant sync/update, which copy the skills to user projects

      The skill-sync guard already covers parity across the producers.


    Feature Quality Planning

    All standard checks pass. Notable items:

    • Sibling grants (not in scope; recommend a follow-up): clean also grants Bash(git clean:*), Bash(git checkout:*) and Bash(git push:*). git clean -fdx and git checkout -- . destroy work, and git push origin main is what the body runs. The gate passes these because the wildcard follows a subcommand. Same class as gh api:*.
    • setup runs rm -f …constitution.md.bak and rm -rf ".claude/skills/$dir" with no rm grant. They already prompt, and Claude Code's native rm analyzer covers them. No change.
    • The UX cost is new prompts in interactive /qa (all-failing CI path), /clean (deletions), and /setup (pipe sed). The PR must list them; this is what AC-1 asks for.

    Conflict Risk


    Open Questions

    1. qa gh api: remove, or narrow to endpoints? Recommendation: remove. Impact if wrong: if prompts annoy interactive /qa users, add Bash(gh api repos/{owner}/{repo}/issues/comments*) later. GitHub has no POST/DELETE on that collection path.
    2. Should mv/find/cp join rm/sed in the new gate list? AC-2 names only 4. Recommendation: include them, so the AC-1 decisions can't regress. Impact if wrong: at worst a future skill needs an allowlist line.
    3. Do pipe-stage read-only sed calls prompt without a grant? Unknown. Exec should check once in an interactive session if feasible, or record "unverified" in the AC-1 table.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: disabled
    Reasoning: A frontmatter edit plus one gate test with a single mutation record. Exec writes the test itself, so testgen adds nothing. No UI, and not security-review sized: the change narrows permissions.


    Label Review

    Current: enhancement
    Recommended: enhancement, planned
    Reason: Matches the plan. No complexity labels are warranted.
    Quality Loop: Won't auto-enable; scope is OK.

  6. added
    planned
    on Oct 5, 2026
  7. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 2/2 met

    Gaps:

    • The fix(skills): narrow the broad allowed-tools grants the portal didn't flag — qa gh api, clean rm/find, setup curl/sed #1292 rule only rejects the exact form, so prefix variants like or pass the gate — ⚠️ unresolved
    • Default-deny allowlist gate follow-up was deferred but never filed — ⚠️ unresolved
    • clean's destructive git subcommand wildcards are out of scope here and not filed — ⚠️ unresolved
    • Required CI checks (test, canary) never dispatched on the PR head
    • The gate only matches exact patterns, so prefix variants bypass it. It rejects only cmd === "<tool> *". I added Bash(rm -rf:*) and Bash(gh api -X:*) to clean/SKILL.md, and the gate still passed 10/10. Those two entries are broader in effect than the ones this issue removed. AC-2 is literally met, but the next regression would most likely look like this. It is the same class as the "Upstream causes §1" comment and the spec's Design Review item 3.

    Suggestions:

    • Reject any FILE_WRITE_TOOLS entry whose cmd starts with <tool> and ends in *, unless it is in the allowlist. Alternatively, file the default-deny gate follow-up that the spec recommended "before merge".
    • Fix the off-by-one line references in the PR table.
  8. added a commit that references this issue on Oct 5, 2026
  9. admarble commented on Oct 5, 2026

    @admarble
    ContributorAuthor

    Runner verification (2026-10-05): PR #1323

    QA returned AC_MET_BUT_NOT_A_PLUS (2/2).

    AC Checked by the runner Result
    AC-1 Read the frontmatter diff in all 3 skill roots and the PR table ✅ qa gh api:* removed (every qa gh api call is a GET, but one URL is built at runtime). clean rm/find removed, mv limited to the archive trees. setup cp/cat/sed narrowed. jq kept in setup and test, with a reason
    AC-2 Ran skill-allowed-tools-gate.test.ts ✅ 15/15 after the runner fix below

    Fixed beyond exec's work (cb3ffdd1): QA found the new rule matched only the exact <tool> * form, so Bash(rm -rf:*) and Bash(gh api -X:*) passed. Those are broader than what this issue removed. The rule now rejects any wildcard entry for gh api/rm/mv/find/sed/cp unless BROAD_ALLOWLIST names it with a reason. The 5 narrowed entries are allowlisted. I mutation-verified it: adding Bash(rm -rf:*) to .claude/skills/clean/SKILL.md failed exactly the .claude/skills case (1 failed / 14 passed), and I restored the file. The marker is in the PR body and parses.

    Known limit, stated in the allowlist reason: sed -i.bak * .claude/memory/constitution.md is narrower than sed:*, but * can also match extra file arguments.

    Follow-up ledger:

  10. added a commit that references this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions