Skip to content

fix(gate): refuse a nested coding agent started with its approvals off - #1119

Merged
sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-nested-agent-bypass
Nov 27, 2026
Merged

sandstream merged 1 commit into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-nested-agent-bypass

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Protected — owner merges (touches src/install-gate.ts and src/commands/gate.ts).

Found by kit-research docs/research/artex-cc-vs-kit.md (kit-research PR #236), Measurement 5 and Plan item 1: gate-bash refuses git commit --no-verify, but passed these four with exit 0:

Command Before After
claude --print --dangerously-skip-permissions "…" 0 2
claude -p --permission-mode bypassPermissions "…" 0 2
codex exec --dangerously-bypass-approvals-and-sandbox "…" 0 2
gemini --yolo -p "…" 0 2
claude -p "…" (control) 0 0

What changes

  • New module src/nested-agent-bypass.ts: a table of agent CLIs and the approval-off flags their vendors document. Each entry quotes its doc URL; flags I could not find in vendor docs are left out (listed below).
  • It reads through sh -c / bash -lc, eval, env / sudo / xargs / timeout (the gate's existing wrapper set), npx / bunx / npm exec / pnpm dlx (by package name too, e.g. @anthropic-ai/claude-code@latest), $(…) and backticks, cmd /c, and PowerShell -Command / -EncodedCommand. Here-document bodies that are data are skipped, the same way the other policy refusals skip them.
  • Wiring: two lines in decideBashGate (install-gate.ts goes from 1311 to 1313 lines against the 1339 limit; with feat(install-gate): block a prebuilt binary install without a kit triage release receipt #1109 (+7) and fix(gate): refuse npx <bin> when the bin is another package's npm name #1111 (+3) it would be 1323).
  • src/commands/gate.ts: the refusal no longer gets "Triage it first" stapled on (one regex alternative, as for cannot be undone).
  • Refusal text, e.g.: starts a nested agent with its approvals off (claude --dangerously-skip-permissions): it would run commands nobody approves, outside this session's permission prompts. Drop the flag: the nested session then asks before each tool, and --allowedTools pre-approves only the tools it needs. Running an agent unattended is the person's decision, not the agent's (fail-closed).
  • Docs: docs/ENFORCEMENT_AND_AUDIT.md (gate-bash section); fragment changes/nested-agent-bypass.md.
  • Zero-LLM (ADR-0001), no new dependency (ADR-0002). adr check: 4 enforced ADRs, no new violations.

Coverage table

Harness Command Flags refused Source
Claude Code claude --dangerously-skip-permissions, --permission-mode bypassPermissions (and =) code.claude.com/docs/en/cli-reference
Codex codex --dangerously-bypass-approvals-and-sandbox, --yolo, -a never with -s danger-full-access (and long / = forms) learn.chatgpt.com/docs/developer-commands?surface=cli
Gemini CLI gemini --yolo, -y, --approval-mode yolo geminicli.com/docs/cli/cli-reference
Qwen Code qwen --yolo, --approval-mode yolo QwenLM/qwen-code docs/users/configuration/settings.md
Cursor CLI agent, cursor-agent --force, -f, --yolo cursor.com/docs/cli/reference/parameters
GitHub Copilot CLI copilot --allow-all-tools, --allow-all, --yolo, COPILOT_ALLOW_ALL=<true> docs.github.com/en/copilot/reference/cli-command-reference
Kiro CLI kiro-cli --trust-all-tools kiro.dev/docs/reference/cli-commands
Factory Droid droid --skip-permissions-unsafe docs.factory.com/cli/droid-exec/overview

Not covered, and why:

  • Codex --full-auto: not in the current Codex CLI reference (the documented relative is --approve-for-me, which keeps on-request approvals and the workspace-write sandbox). -a never alone keeps the sandbox, and -s danger-full-access alone keeps approvals, so neither is refused alone.
  • Claude --allow-dangerously-skip-permissions: it adds the mode to the cycle but does not start in it.
  • Amp --dangerously-allow-all: Amp's own docs document only the amp.dangerouslyAllowAll setting, not the flag, so it is left out.
  • OpenCode and Augment (auggie): no approval-off flag in their CLI docs.
  • Cline CLI: its docs say a prompt runs in yolo mode by default (--auto-approve defaults to true). Refusing every cline "<prompt>" is an owner decision, so it is not in this PR.
  • Amazon Q (q chat --trust-all-tools): the AWS reference page now redirects away and I could not quote it; its successor kiro-cli is covered. Antigravity has no documented CLI flag.
  • Approval settings in a config file, -c approval_policy=… overrides, or env vars other than COPILOT_ALLOW_ALL.

API for agent-audit (stable)

import { nestedAgentBypass, nestedAgentCli, nestedAgentBypassReason } from "./nested-agent-bypass.js";

interface NestedAgentBypass { agent: string; flag: string; approvalsOn: string }

nestedAgentBypass(command: string | readonly string[]): NestedAgentBypass | null
// string: a shell command (carriers read as above). argv: one command, e.g. a grant prefix split on spaces:
//   nestedAgentBypass(["claude", "--print", "--dangerously-skip-permissions"])  -> { agent: "claude", flag: "--dangerously-skip-permissions", … }
nestedAgentCli(word: string): string | null
// the agent behind a command word: "claude", "/opt/bin/codex.exe", "gemini.cmd", "@anthropic-ai/claude-code@2" -> canonical name; for `Bash(claude:*)` wildcard grants
nestedAgentBypassReason(found: NestedAgentBypass): string

All three are pure: no I/O, no environment reads. nestedAgentRefusal(heredocs) is the gate's wrapper and is not meant for other callers.

Tests

src/nested-agent-bypass.test.ts (52 tests): every flag in the table, 13 carrier forms, 12 negatives (claude --version, a prompt that mentions the flag, the flag after --, codex -a never alone, …), the argv API, and the four repro commands through decideBashGate. src/gate-bash-refusal.test.ts gains one compiled-CLI case (exit 2, flag named, no triage advice).

Before (on main, classifier present but not wired):

    not ok 1 - refuses before any registry request: claude --print --dangerously-skip-permissions "Pentest example.com"
    not ok 2 - refuses before any registry request: claude -p --permission-mode bypassPermissions "x"
    not ok 3 - refuses before any registry request: codex exec --dangerously-bypass-approvals-and-sandbox "x"
    not ok 4 - refuses before any registry request: gemini --yolo -p "x"
# tests 52  # pass 48  # fail 4

After:

# tests 52  # pass 52  # fail 0

All install-gate* and gate-bash* tests: 1141 pass, 0 fail.

Platforms

Tested on Linux. The Windows forms (cmd /c, PowerShell -Command / -EncodedCommand, claude.cmd, codex.exe) are covered by unit tests and run in the Windows CI shards. macOS is unverified: no CI job runs it, though nothing here touches the filesystem or processes.

Owner choices

  • Cursor's binary is the generic name agent, so agent --force from some other tool would also be refused (fail-closed).
  • -y for Gemini is deprecated but still documented, so it is refused.
  • Allow path: there is no agent-side allow, same as --no-verify. The person runs the command themselves.

Generated by Claude Code

`claude --print --dangerously-skip-permissions`, `claude -p --permission-mode
bypassPermissions`, `codex exec --dangerously-bypass-approvals-and-sandbox` and
`gemini --yolo -p` all passed gate-bash with exit 0, while the gate already
refuses `git commit --no-verify` for skipping a control. They now exit 2.

src/nested-agent-bypass.ts holds a table of agent CLIs and the approval-off
flags their vendors document (Claude Code, Codex, Gemini, Qwen, Cursor,
Copilot, Kiro, Droid), and reads through shells, wrappers, npx and the
Windows shells. It is pure and exported for agent-audit's grant reader.
Wiring in install-gate.ts is two lines.

Found by kit-research artex-cc-vs-kit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kit review gate at 144b2f254584: not approved.

  • touches protected paths (permissions), which the owner approves: src/commands/gate.ts, src/install-gate.ts

@sandstream
sandstream merged commit 3f77f81 into main Nov 27, 2026
33 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a-protected-nested-agent-bypass branch November 27, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants