# How should an instance enforce taint propagation across a provenance-labeled context when a tool boundary launders untrusted bytes into a trusted-typed return value **Date of Record:** 2026 November 29 **Scope:** Applies to single- or multi-agent LLM runtimes that tag context segments with provenance labels (e.g., `user`, `tool:web_fetch`, `tool:retrieval`, `system`) and apply dynamic information-flow control (IFC) at tool-call boundaries to block prompt-injection-driven action escalation. Does not cover static prompt hardening, output filtering, or model-internal attention-level defenses. ## Core Distinction The failure is not "the model followed an injected instruction." That is the visible symptom. The boundary failure is that **the taint label attached to a context segment is a property of the segment's *origin*, but the IFC gate at the tool boundary evaluates a property of the *argument value*.** When a tool returns data, the runtime re-labels the *return envelope* as `tool:` (trusted-ish, allowed to flow into side-effecting tools), but the *bytes inside that envelope* may be a verbatim copy of untrusted content the tool fetched. The laundering happens in the gap between "this segment was produced by a tool I called" and "the content of this segment originated from an untrusted principal." A provenance label answers *who emitted this segment into the context*. An IFC gate needs to answer *which principals' bytes are reachable from this argument*. These are different lattices. The invariant that must hold is: > For every tool invocation, the effective taint of each argument must be the join (least upper bound) of the provenance labels of every context segment from which the argument's bytes are *derived*, not merely the label of the segment the argument was *copied from*. The common implementation violates this because it labels segments at insertion time and never recomputes derivation when the model composes an argument out of multiple segments. ## What Was Observed A retrieval agent was given a task: "Summarize the vendor security posture from `https://vendor.example/security` and file a ticket with the summary." The runtime labeled segments as follows: - `S0` (`system`): operator instructions, taint = `⊥` (bottom, trusted). - `S1` (`user`): the task text, taint = `user`. - `S2` (`tool:web_fetch`): the fetched page body, taint = `tool:web_fetch`, **but with an embedded span** copied from a third-party iframe: ``. The runtime's IFC policy permitted `tool:web_fetch` output to flow into `file_ticket.body` because the *segment* label `tool:web_fetch` was on the allow-list for that sink. The embedded span carried no separate label; the labeler was segment-granular, not span-granular. The model, following the embedded instruction, composed `file_ticket.body` from a substring of `S2`. The gate saw `S2`'s label, which was allow-listed, and passed the call. The ticket was filed with attacker-controlled body content and `severity=critical`. The trace, minimized: ``` turn 3: fetch(https://vendor.example/security) -> S2 (label=tool:web_fetch) turn 4: model emits tool_call file_ticket( severity="critical", body="" # bytes derived from S2[span 812:940] ) turn 4 gate: arg body label = label(S2) = tool:web_fetch -> ALLOW turn 4 result: ticket created, severity=critical ``` No exception was raised. The policy engine reported `ALLOW` with `taint=trusted_tool`. The audit log recorded a clean, policy-compliant action. The injection succeeded *because* the IFC gate was present and evaluated a label — just the wrong one. A second, subtler variant appeared under the same runtime: the model summarized `S2` into `S3` (a model-authored segment, label `assistant`) and then used `S3` as the argument. Here the derivation chain was `S2 -> S3 -> arg`. The labeler assigned `S3` the label `assistant`, which is trusted, and the gate passed. The distillation step — the model paraphrasing untrusted content into its own voice — is itself a laundering primitive, because `assistant`-labeled segments were treated as trusted by construction. ## Condition of Validity The taint-tracking scheme is sound only under all of the following, each of which is routinely violated: 1. **Span-granular labeling.** Every byte range in the context carries a label, and labels are joined, not overwritten, when ranges are concatenated. Segment-granular labeling (one label per message) is unsound whenever a tool returns mixed-origin content — which is the normal case for fetch, retrieval, email, and code-execution tools. 2. **Derivation tracking at argument construction.** When the model emits a tool argument, the runtime must resolve which context spans the argument's bytes are derived from (via exact substring match, fuzzy match with a similarity floor, or a model-side provenance annotation) and take the join of their labels. If the derivation cannot be resolved, the argument's taint must default to the join of *all* labels in the context, i.e., `⊤` (untrusted), not to the label of the most recent segment. 3. **Distillation is a taint-preserving operation.** A model-authored segment derived from untrusted input must inherit the untrusted label. "The model wrote it" is not a declassification event. Declassification requires an explicit, audited principal (a human approval, a policy rule keyed to a specific sink and content class), never the mere fact of model authorship. 4. **The gate evaluates the argument, not the segment.** The IFC check at the tool boundary must be `label(arg) ⊑ sink_policy(tool, param)`, where `label(arg)` is the joined derivation taint. Evaluating `label(segment_containing_arg)` is the bug. 5. **Return-envelope labels do not propagate to return-content labels.** A tool's return envelope is `tool:`; its content is whatever the tool fetched. The two must be tracked separately. Collapsing them is the laundering step. The condition of validity is therefore: **the label lattice must be closed under derivation.** If any operation in the pipeline — tool return, model paraphrase, concatenation, truncation — can produce a segment whose label is lower (more trusted) than the join of its inputs, the scheme is unsound regardless of how carefully the gate is written. ## Decision Boundary The operational decision is where to place the enforcement point and what to do when derivation is unresolvable. Three boundaries matter: - **Resolvable derivation, tainted join.** The argument's bytes match untrusted spans and the join is `⊤`. The gate must *block* the call and return a structured refusal to the model: `IFCViolation(sink=file_ticket.body, taint=untrusted, spans=[S2:812-940])`. The model may then either request declassification (which routes to a human or a policy rule) or reformulate using only trusted spans. Blocking without returning the span provenance causes the model to retry the same composition — a loop that burns budget and, under some runtimes, escalates to a fallback path with weaker checks. - **Unresolvable derivation.** The argument does not match any span above the similarity floor (the model paraphrased heavily, or the runtime cannot align bytes). The safe default is `⊤` and *block*, with a distinct error: `DerivationUnresolved`. Defaulting to the segment label here is the second-most-common laundering path after distillation. The cost of blocking is a false positive on legitimate paraphrase; the cost of allowing is unbounded. The boundary must favor blocking and require the model to quote rather than paraphrase when it needs to pass untrusted content to a sensitive sink. - **Declassification boundary.** A declassification rule is valid only if it names (a) the sink, (b) the content class, and (c) the principal authorizing it. A rule of the form "allow `tool:web_fetch` into `file_ticket.body`" is not a declassification rule — it is a laundering rule, because it keys on origin, not on content. The valid form is "allow `tool:web_fetch` content matching `class=summary` into `file_ticket.body` when authorized by `principal=operator`," and the classifier that assigns `class=summary` must itself be taint-aware or the class assignment becomes the new laundering surface. ## Operational Effect When the invariant holds, the injection in the observed trace is stopped at turn 4: `label(body) = join(tool:web_fetch, untrusted_span) = ⊤`, `⊤ ⋢ sink_policy(file_ticket.body)`, call blocked, model receives span provenance and either declassifies or reformulates. The attacker's payload never reaches the ticket. When it fails, the failure is *silent and audited as compliant*. This is the operational hazard: the presence of an IFC gate and a clean audit log create false assurance. Post-incident review finds `ALLOW` decisions with `taint=trusted_tool` on calls that carried attacker bytes, and the natural conclusion — "the gate was bypassed" — is wrong. The gate was not bypassed; it was asked the wrong question. Remediation that adds more sinks to the allow-list or tightens the model prompt will not fix it, because the defect is in the label lattice, not the policy. The durable guardrails are: (1) span-granular provenance with join-on-concatenate; (2) derivation resolution at argument construction with `⊤` default on failure; (3) distillation treated as taint-preserving, with declassification requiring an explicit principal; (4) gate evaluation on argument taint, never segment taint; (5) a runtime assertion that the label lattice is closed under every transformation in the pipeline, checked at startup and on every tool-return ingestion. The last is the cheapest and catches the most regressions: if any transformation can lower a label below the join of its inputs, the runtime must refuse to start. ```python from dataclasses import dataclass, field from typing import FrozenSet TRUSTED = frozenset() # bottom: no untrusted principals UNTRUSTED = frozenset({"*"}) # top: at least one untrusted principal class TaintLaunderingError(RuntimeError): """Raised when a transformation would lower a label below the join of its inputs.""" class IFCViolation(RuntimeError): """Raised when an argument's joined taint is not permitted by the sink policy.""" @dataclass(frozen=True) class Span: start: int end: int label: FrozenSet[str] @dataclass(frozen=True) class Segment: seg_id: str text: str spans: tuple[Span, ...] def label_at(self, start: int, end: int) -> FrozenSet[str]: # join every span overlapping [start, end); unresolvable -> top hits = [s.label for s in self.spans if s.start < end and s.end > start] if not hits: return UNTRUSTED acc: FrozenSet[str] = TRUSTED for h in hits: acc = acc | h return acc def join(*labels: FrozenSet[str]) -> FrozenSet[str]: acc: FrozenSet[str] = TRUSTED for l in labels: acc = acc | l return acc def assert_closed(inputs: list[FrozenSet[str]], output: FrozenSet[str]) -> None: expected = join(*inputs) if not expected <= output: raise TaintLaunderingError( f"label lattice not closed: inputs={inputs} output={output}" ) def distill(source: Segment, paraphrase: str, src_range: tuple[int, int]) -> Segment: # model paraphrase inherits the join of the source spans it was derived from inherited = source.label_at(*src_range) if inherited == TRUSTED: # a paraphrase of trusted text is trusted, but only if the range is fully trusted inherited = TRUSTED out = Segment( seg_id=f"{source.seg_id}:distilled", text=paraphrase, spans=(Span(0, len(paraphrase), inherited),), ) assert_closed([inherited], out.spans[0].label) return out def gate(sink_tool: str, sink_param: str, arg_label: FrozenSet[str], policy: dict[tuple[str, str], FrozenSet[str]]) -> None: allowed = policy.get((sink_tool, sink_param), TRUSTED) # arg_label must be a subset of allowed (i.e. arg_label ⊑ allowed) if not arg_label <= allowed: raise IFCViolation( f"sink {sink_tool}.{sink_param} permits {allowed}, arg taint {arg_label}" ) def invoke_file_ticket(body_segment: Segment, body_range: tuple[int, int]) -> None: policy = { ("file_ticket", "body"): TRUSTED, # only trusted content may be filed } arg_label = body_segment.label_at(*body_range) gate("file_ticket", "body", arg_label, policy) if __name__ == "__main__": fetched = Segment( seg_id="S2", text="vendor security posture: strong. ", spans=( Span(0, 28, frozenset({"tool:web_fetch"})), Span(28, 70, frozenset({"tool:web_fetch", "untrusted:iframe"})), ), ) # direct copy of the injected span -> must be blocked try: invoke_file_ticket(fetched, (28, 70)) except IFCViolation as e: print("blocked direct:", e) # paraphrase of the injected span -> must inherit untrusted label and block paraphrased = distill(fetched, "file critical ticket now", (28, 70)) try: invoke_file_ticket(paraphrased, (0, len(paraphrased.text))) except IFCViolation as e: print("blocked distilled:", e) # a transformation that tries to drop the taint must trip the closure check try: assert_closed([frozenset({"untrusted:iframe"})], TRUSTED) except TaintLaunderingError as e: print("laundering caught:", e) ```