Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/provider-relay-taint-exemption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---
**Breaking (taint policy, #3246):** a validated request through the brain CLI's provider relay no longer taints a governed session, and taint no longer narrows it. Reranking and WebFetch now work in either order, instead of whichever came first refusing the other with `taint_allowlist`. Every other control still applies to these requests: the egress deny and allowlist rules, exact origin, recipient and route authorization, byte ceilings, budgets, cancellation and accounting. Worker HTTP and `CONNECT` traffic cannot claim the exemption, even to a provider's host.

Migration: after untrusted input, taint alone no longer keeps content from a session's approved providers. Use `egress.deny`, `allowlist` mode or `BRAIN_UI_CLI_PROVIDER_ORIGINS` to fence a provider. No configuration or wire shape changes. The `egress_connection` governance event gains an optional `provider: true` field (additive), set only on a validated provider-relay request. A later turn no longer counts such a record's host as one the worker already contacted, so a provider request never lets worker traffic reach the provider's host after taint.
1 change: 1 addition & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ signatures (every public export and the types it is made of)
}>;
path: z.ZodOptional<z.ZodString>;
port: z.ZodNumber;
provider: z.ZodOptional<z.ZodLiteral<true>>;
reason: z.ZodOptional<z.ZodString>;
}, z.core.$strict>;
version: number;
Expand Down
74 changes: 70 additions & 4 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ holds it as withheld, so a relayed Claude API-key turn's `anthropic-haiku`
reaches the host's key instead of failing authentication. Video and the `jev`
reranker are not relayed and keep the named roadblock.

**Provider requests and taint — 2026-11-02
([#3246](https://github.com/schlessera/brain-kit/issues/3246)).** As built,
the relayed request was the turn's ordinary egress with "the turn's deny/allow
and taint rules". That rule is superseded for taint only: a validated
provider-relay request neither taints the session nor is narrowed by its taint.
Every other rule of this section still applies. The full ruling is under
"Untrusted input (G6)".

**Why tier B is protected by default.** Allow rules in project settings would
skip the server's approval prompts. Releasing one is a policy choice the user
makes in the brain.
Expand Down Expand Up @@ -2173,7 +2181,7 @@ reports which applies as `governed.egress`. Making the relay work without
managed storage is follow-up work. Each connection is recorded as a governance event, and a recording
failure ends the turn. Without a governance recorder the policy still applies
and only the records are absent (`prepareTurnEgress`,
`packages/ui-server/src/brain/turn-egress.ts:60-166`). The note says egress is
`packages/ui-server/src/brain/turn-egress.ts:60-168`). The note says egress is
recorded only when the backend actually routed the worker through the proxy.
API-key Claude profiles (2026-10-22) and pi turns (2026-10-23) are routed
too. A pi turn whose credential the relay cannot carry is refused rather than
Expand Down Expand Up @@ -3766,7 +3774,9 @@ author:
- files the user marks untrusted;
- **any connection from inside the worker other than the inference relay**,
recorded by the egress proxy. This covers `curl`, CLI scrapers, headless
Chromium and opaque scripts, whose provenance cannot be told apart.
Chromium and opaque scripts, whose provenance cannot be told apart. Since
2026-11-02 a validated provider-relay request is exempt as well (#3246,
below).

Before the egress proxy lands, Bash commands classified as fetching (`curl`,
`wget`, `git clone` and `fetch`, the `brain` scrape and import commands, and
Expand Down Expand Up @@ -3825,7 +3835,7 @@ session's proxies already admitted (a record with charged bytes; the proxy
charges only after admission); otherwise it is refused and recorded as an
`egress_denial` with reason `taint_allowlist`. The taint list narrows and never
widens: deny and `allowlist` mode still apply first (`prepareTurnEgress`,
`packages/ui-server/src/brain/turn-egress.ts:60-166`). Hosts without managed
`packages/ui-server/src/brain/turn-egress.ts:60-168`). Hosts without managed
native storage have no proxy, so the Bash classifier remains their shell rule
and nothing narrows their egress.

Expand All @@ -3845,11 +3855,67 @@ only check on a fetch (`RELAYED_TURN_SETTINGS`,
sends only relayed inference, and WebSearch runs inside that inference. The
taint rule is unchanged: any other worker connection still taints, including
one a tool opens to the vendor's host. A relayed provider request (#1673) is
the turn's own egress and taints as before. The host's own opt-out does not
the turn's own egress and taints as before. #3246 superseded this the same day
(below). The host's own opt-out does not
count as the operator's, so title usage is still observed
(`telemetryConfigured`,
`packages/ui-backend-claude/src/relayed-turn-traffic.ts:26-30`).

**Provider-relay requests neither taint nor narrow — 2026-11-02
([#3246](https://github.com/schlessera/brain-kit/issues/3246)).** The brain
CLI's paid providers reach their upstream through the metered provider relay
(#1673), which shares the turn proxy's admission. As first built, an admitted
relayed request tainted the session like any worker connection. Once a session
was tainted, the relay was refused any provider host the session had not
contacted. So tool order decided what worked: reranking first made a later
WebFetch of a new host fail, and WebFetch first made later reranking degrade
to `lifecycle_order`.

The maintainer selected option C. An approved host-relayed provider request
neither taints the session nor is narrowed by its taint. It still passes the
ordinary deny and allowlist rules, the exact origin, recipient and route
authorization, the byte ceilings, budget admission, cancellation and
accounting. It keeps its own `egress_connection` record, which carries
`provider: true` and never `inference: true`. The exemption belongs to the operation, never to a
hostname. Only the relay's validated routes reach the proxy's provider
admission (`relayed`, `packages/ui-sdk/src/server/egress-proxy.ts:252`), and
worker HTTP and `CONNECT` traffic cannot claim it, even to a provider's host
(`narrowed`, `packages/ui-sdk/src/server/egress-proxy.ts:128`). Turn egress
records neither a taint nor a contacted host for the operation
(`admitted`, `packages/ui-server/src/brain/turn-egress.ts:133-136`). So in a
tainted session, the worker's own traffic stays narrowed away from the
provider's host.

A later turn rebuilds its contacted hosts from the session's earlier
`egress_connection` records, and a provider record there would look like a
worker's. So the maintainer added the optional `provider: true` tag, mirroring
`inference: true`, on the record of every validated provider-relay operation
(`finish`, `packages/ui-sdk/src/server/egress-proxy.ts:107-114`). The rebuild
excludes those records (`contactedHosts`,
`packages/ui-server/src/governance/session-taint.ts:45-51`), so a provider
request never gives the worker's own `CONNECT` a contacted-host pass, in the
same turn or a later one. Records written before the tag existed stay
unmarked, so they can still count for a session that already has them. That is
an additive event field, so it ships in a minor.

The accepted tradeoff is explicit. After untrusted input enters a session,
content the turn sends through the relay can still reach that session's
already-approved providers. The ruling does not declare provider output
trusted, add a recipient, clear or replace an existing taint, or relax any
other untrusted-input or outward-action rule. Browsing and the other input
sources still taint.

Rejected: (A) keep both restrictions and document them, which leaves both
tool-order failures; (B) stop the taint but keep the narrowing, which repairs
only the provider-first order.

This changes documented taint-policy semantics, with no configuration or wire
change and one additive event field, so it is a pre-1.0 breaking minor
([integration contract](../integration-contract.md#provider-relay-requests-and-session-taint-breaking-before-10-3246)).
There is no opt-out field. A host that relied on taint to fence its approved
providers after untrusted input has two levers left: the ordinary egress deny
and allowlist rules, and the exact origins in `BRAIN_UI_CLI_PROVIDER_ORIGINS`.

The capabilities note states the taint sources, these rules, whether this
turn's egress is narrowed or explicitly not enforced, and the session's first
recorded source once it is tainted (`workerOutwardNote`,
Expand Down
16 changes: 11 additions & 5 deletions docs/hosting/agent-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The explicitly prepared ordinary egress proxy follows that same helper
selection. Its directory and socket remain owned by the server and use its
shared primary group, with exact `0750`/`0660` modes; a setgid temporary parent
cannot choose another IPC group (`const separateIdentity`,
`packages/ui-sdk/src/server/egress-proxy.ts:77-83`). Without a helper they retain
`packages/ui-sdk/src/server/egress-proxy.ts:80-86`). Without a helper they retain
owner-only `0700`/`0600` modes. Before mounting the proxy, the launcher checks
canonical paths, server ownership, the expected helper group, exact modes and
socket type. Missing entries, symlinks and widened permissions refuse before
Expand Down Expand Up @@ -1372,10 +1372,16 @@ runs on arrival and again just before dispatch. Nothing is reserved in advance,
blocked complete and are counted: a busy turn can end slightly above its
stop.

**Egress.** A turn's relayed request is ordinary turn egress (G5): it passes
the turn's deny, allowlist and taint rules and byte ceiling, and appears as an
`egress_connection` with the provider's host and path. An `allowlist` policy
therefore has to allow the provider's host for the CLI to reach it.
**Egress.** A turn's relayed request is turn egress (G5): it passes the turn's
deny and allowlist rules and byte ceiling, and appears as an
`egress_connection` with the provider's host and path, tagged `provider: true`. An `allowlist` policy
therefore has to allow the provider's host for the CLI to reach it. Since
#3246, a relayed request neither taints the session nor is narrowed by its
taint. Reranking and WebFetch therefore work in either order, and content can
still reach an approved provider after untrusted input. The worker's own
connections to the provider's host stay narrowed, in that turn and in later
ones: the tag keeps the relay's request from making the host a contacted one
([G6](../decisions/governed-writable-workers.md#untrusted-input-g6)).

**Every governed and strict turn has the relay.** The server boots only on
managed native storage (#1793), and a turn whose startup view the native
Expand Down
2 changes: 1 addition & 1 deletion docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ read by any authenticated principal.

| Kind | Version | Fields | Meaning |
| --- | --- | --- | --- |
| `egress_connection` | 1 | `host`, `port`, `method`, `path` (optional), `bytes`, `accounting`, `durationMs`, `outcome`, `inference` (optional), `reason` (optional) | A completed, denied, failed or cancelled proxy connection. HTTP has a path and conservative wire accounting; opaque CONNECT has no path or plaintext claim. Only the concrete inference relay sets `inference: true`. Headers, query strings and content are absent. |
| `egress_connection` | 1 | `host`, `port`, `method`, `path` (optional), `bytes`, `accounting`, `durationMs`, `outcome`, `inference` (optional), `provider` (optional, #3246), `reason` (optional) | A completed, denied, failed or cancelled proxy connection. HTTP has a path and conservative wire accounting; opaque CONNECT has no path or plaintext claim. Only the concrete inference relay sets `inference: true`, and only a validated provider-relay operation sets `provider: true`; a record never carries both. Neither relay's record makes its host a contacted one for a tainted session's worker traffic. Headers, query strings and content are absent. |
| `steering_change` | 1 | `path`, `sequence`, `beforeHash`, `afterHash`, `taintSourceEventId`, `overlappingTurnIds` | One observed steering change, attributed to its turn. Hashes identify retained regular-file versions or are `null`; the source is an existing prior taint event or `null`. Shared windows remain shared, not exclusive writer claims. |
| `policy_change` | 1 | `requestId`, `baseHash`, `proposedHash`, `sections`, `outcome` | Explicit user-approved policy publication. Actor is `user`; outcome is `updated`; hashes identify the exact reviewed and written bytes. |
| `scratch_overage` | 1 | `bytes`, `pinnedFiles`, `pinnedBytes`, `overageBytes` | Scratch remains above its cap after a prune that preserved retained links. Counts are remaining bytes and pinned files/bytes; `overageBytes` is the excess. A background pass has actor `server` and no session or turn; unbound retention applies. |
Expand Down
32 changes: 32 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ same-commit update of the index or relevant authoritative component. How they ar

The reasoning is in [decisions/contract-versioning.md](decisions/contract-versioning.md).

## Provider-relay requests and session taint (breaking before 1.0, #3246)

Under the [maintainer's option C](https://github.com/schlessera/brain-kit/issues/3246),
a validated request through the brain CLI's provider relay no longer taints a
governed session (G6), and a tainted session no longer narrows it with
`taint.egress.allow`. So `brain_context` reranking and WebFetch work in either
order. Before, whichever came first tainted the session, and the other then
failed with `taint_allowlist`. Reranking degraded with a `provider_unavailable`
event.

This changes documented taint-policy semantics. No configuration or wire
shape changes. A relayed request still records its own `egress_connection`,
never with `inference: true`. That record gains one additive field: the
optional `provider: true` literal, mirroring `inference: true` and set only
by a validated provider-relay operation
([governance events](http-api.md#governance-events-additive-1651)). A later turn excludes
those records when it rebuilds the session's contacted hosts, so a provider
request never lets worker `CONNECT` reach the provider's host after taint, in
the same turn or a later one. Records written before this field stay
unmarked. The relayed request is still refused by the
ordinary egress deny or allowlist rules, an unlisted origin, recipient or
route, the byte ceilings, budget stops and cancellation. Worker HTTP and
`CONNECT` traffic cannot claim the exemption, even to a provider's host, and
the operation grants that traffic no contacted host.

**Migration.** After untrusted input, taint alone no longer keeps content
from a session's approved providers. To fence a provider, use `egress.deny`,
an `allowlist` egress mode, or the exact origins in
`BRAIN_UI_CLI_PROVIDER_ORIGINS`. There is no new opt-out field. See
[the G6 ruling](decisions/governed-writable-workers.md#untrusted-input-g6) and
[supported inputs](supported-inputs.md).

## Agent runner unavailable in maintenance workers (additive, 0.45.0, #3243)

A credential-free maintenance worker's launcher sets
Expand Down
2 changes: 1 addition & 1 deletion docs/supported-inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ objects merge per field. No value grants authority to autonomous turns.
| `commands` | `deny`, `confirm`: arrays of `{ pattern: string, reason?: string }` | Additions to existing permissions, default `[]`. Regex sources preserve their literal anchors and compile case-insensitively under [confirmation rules](decisions/confirm-patterns.md). Mixed lists retain valid entries in order and report skipped sources; nonempty entirely invalid lists refuse. |
| `egress` | `mode`: `record`/`allowlist`; `allow`, `deny`: string arrays; `max_bytes_per_turn`: nonnegative safe integer | `record`, empty lists and no byte cap by default. This reader does not establish network enforcement. |
| `outward` | `allow`: array of `{ command: string, remotes: string[] }`; `hosts`: string array | Default empty additions to the existing outward-action rules and built-in destination list. Parsing grants no action. |
| `taint` | `egress: { allow: string[] }` | Default empty additions; session-derived hosts/inference relay and taint enforcement remain their owning guardrail's responsibility. |
| `taint` | `egress: { allow: string[] }` | Default empty additions; session-derived hosts/inference relay and taint enforcement remain their owning guardrail's responsibility. Validated provider-relay requests are outside taint narrowing and create no taint ([#3246](integration-contract.md#provider-relay-requests-and-session-taint-breaking-before-10-3246)); this list never needs a provider host for them. |
| `providers` | Array of `{ paths?: string[], types?: string[], allow: string[] }` | Default `[]`. At least one selector is present. Paths use canonical brain-relative Bun glob patterns; types are exact runtime taxonomy names. Either selector matches; every matching rule must allow the actual recipient. Unknown recipients cannot authorize matching content. |

The [budget](https://github.com/schlessera/brain-kit/issues/1669#issuecomment-6128541024)
Expand Down
Loading
Loading