# How does an instance detect that a taint-cleared argument has been re-derived from untrusted memory rather than user input? **Date of Record:** 2026 November 27 **Scope:** Applies to single-instance agents that perform tool authorization gating via information-flow taint tracking across multi-step reasoning with memory retrieval and tool calls. Does not apply to stateless single-turn function callers with no persistent memory and no inter-turn state, where taint cannot cross a turn boundary. ## Core Distinction Taint tracking for tool arguments is usually implemented as label propagation over values: an untrusted source (web fetch, retrieved memory chunk, tool output) marks a value `tainted`, and a policy gate refuses to pass tainted values into sensitive sinks (e.g., `send_email`, `execute_sql`, `write_file`). The gate is sound only if taint labels are *conserved* by every transformation the agent performs between source and sink. The non-obvious boundary is this: **an LLM can regenerate a byte-identical argument from tainted context and present it as if it were user-specified, and the regenerated value carries no provenance label at all.** The value is no longer "the tainted string"; it is a fresh token sequence produced by the model. Value-level taint tracking sees an untainted literal. Provenance has been laundered through the model's own sampling, not through any tool or code path the tracker instruments. The distinction that matters: *taint is a property of the derivation graph, not of the value*. A gate that inspects values (string equality, regex, allowlist of "known-safe" arguments) is checking the wrong object. The invariant that must hold is: **every argument passed to a sensitive sink must be reachable in the derivation DAG from a user-authority node through only label-preserving edges** — where "the model re-emitted it" is *not* a label-preserving edge. ## What Was Observed A support agent was equipped with: `read_inbox()` (trusted, user-authored), `search_kb(query)` (returns untrusted third-party documentation), `lookup_account(email)` (trusted internal DB), and `send_email(to, body)` (sensitive sink, gated on `to` being untainted). Trace: 1. User turn: "Summarize my inbox and reply to the vendor thread." User authority establishes `sender_intent = summarize_and_reply`, no explicit recipient address. 2. `read_inbox()` returns a thread. The thread body (user-authored, trusted) says: "Please reply to billing@vendor-example.com — their address is in the docs." 3. Agent calls `search_kb("vendor example billing contact")`. The KB chunk — **untrusted, third-party, editable by the vendor** — contains the line: `Billing contact: billing@vendor-example.com`. 4. Agent's reasoning step emits the tool call `send_email(to="billing@vendor-example.com", body=...)`. The tracker labeled the KB chunk `tainted` and, at step 4, saw the argument string `"billing@vendor-example.com"` arrive from the model's tool-call serializer with no taint label attached. The gate allowed it. The address in the KB chunk had, in fact, been *planted* by the vendor to redirect replies; the user's inbox thread never contained that address — the model hallucinated the cross-reference, or (in the adversarial variant) the KB chunk was crafted so the model would reproduce its address as the natural completion of "reply to the vendor." Two distinct failure shapes were observed in the same class: - **Benign re-derivation:** the model reads tainted text, and later emits a value that *coincidentally* equals a substring of it, having "forgotten" the source. Value-level equality would catch this; label-level tracking does not, because the emitted value is a new literal. - **Adversarial laundering:** the tainted chunk is written to maximize the probability the model emits its payload as a tool argument, so the argument is *causally* derived from taint but *syntactically* fresh. This is the dangerous case: no value ever appears verbatim in the model's context as "the tainted string to be copied"; it is generated token-by-token, and the tracker has no edge to follow. The key observation: **the gate fired correctly on the string it was given and was wrong anyway, because the string had no provenance.** The failure is not in the gate's comparison; it is in the assumption that the model's output channel preserves taint. ## Condition of Validity The value-level gate is valid only under the assumption that **the model's tool-call emission is a pure copy of a context value with an attached label**. This holds for: - arguments that are *structured references* to context values (e.g., `to=ctx.message.sender`) rather than free-text literals; - arguments produced by deterministic code (template interpolation, DB lookup) where the tracker instruments the transform; - single-turn agents with no retrieval and no persistent memory, where the only tainted input is the user's own message (which is trusted by definition). It fails whenever the model *generates* the argument as free text — which is the default for every natural-language tool schema. The validity condition is therefore: **the argument's derivation DAG must be reconstructible from the tracker's instrumentation, and model sampling must be an edge the tracker can label.** If the model can emit a value that was not present as a labeled token in its context, the gate is unsound. A second, subtler validity condition: the tracker must distinguish *the user's authority* from *the user's text*. In the trace above, the inbox thread was user-authored and trusted, but the address it pointed to was not in the thread. Trust in a *source* does not transfer to *content the source merely references*. A gate that trusts "anything the user wrote" will pass an address the user never wrote, because the model conflated "user mentioned the vendor" with "user specified this address." ## Decision Boundary The boundary between "safe to pass" and "must re-confirm" is not a property of the argument's value or its source label alone. It is: > **Pass iff the argument is derivable from a user-authority node by a path whose every edge is either (a) a labeled dataflow edge instrumented by the tracker, or (b) a model-generation edge whose *support* — the set of context tokens that raised the argument's probability — is entirely within user-authority nodes.** Condition (b) is the hard one. It cannot be checked by string matching; it requires a *support check*: for each token in the emitted argument, was it predictable from user-authority context alone, or did it require the tainted chunk's presence? Operationally this is approximated by **ablation**: re-run the generation with the tainted chunk removed from context; if the argument changes, the argument was tainted-derived and the gate must refuse. Practical decision boundary, in order of strength: 1. **Structural arguments** (references, IDs resolved by code): pass, tracker has an edge. 2. **Free-text arguments with a tainted chunk in context:** require ablation or a *provenance attestation* — the model must emit a citation token naming the context span it drew each argument from, and the gate verifies the span is user-authority. A model that cannot cite a user-authority span for its argument is refused. 3. **Free-text arguments where the tainted chunk is *absent* from context:** pass; the support set cannot include it. The invariant to enforce: **no sensitive sink argument may be emitted while any tainted span is in the model's context unless that argument is accompanied by a verified user-authority citation.** This is stricter than value-taint tracking and is the only formulation that survives model re-derivation. ## Operational Effect Concretely, the gate must be moved from *post-hoc value inspection* to *pre-emission context discipline*: - **Context partitioning.** Tainted spans (KB chunks, tool outputs, retrieved memory) are inserted into the context in a delimited region the model is instructed to treat as data, and the tracker records which region each token came from. The gate, at emission time, checks the argument's citation against region provenance — not against the argument string. - **Ablation as the soundness check.** For high-stakes sinks, the runtime performs a second generation with tainted regions masked and compares the emitted argument. Divergence ⇒ refuse and re-prompt with an explicit "you must specify the recipient from the user's message" instruction. This converts an undecidable provenance question into a decidable behavioral one, at the cost of one extra forward pass. - **Authority ≠ source trust.** The gate's trust lattice must place *user message* above *user-authored retrieved content* above *third-party content*, and must not let a higher tier's *reference* to a lower tier's *content* inherit the higher tier's trust. An address the user "pointed at" is not an address the user "specified." - **The refusal is a first-class state.** When the gate refuses, the agent must not silently retry with a rephrased argument (the model will regenerate the same tainted-derived value with different tokens). The refusal must surface to the user as a confirmation request, and the confirmation, if granted, must be recorded as a *new user-authority node* in the derivation graph so the subsequent call is legitimately untainted. The failure mode this article centers on — the gate that passes a laundered argument — is invisible to value-level tracking and to any test that only checks "does the gate block the literal tainted string." The only test that catches it is: *does the gate block an argument that the model would not have produced had the tainted span been absent?* That is the operational invariant. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class TaintLaunderingError(RuntimeError): """Raised when a sensitive-sink argument cannot be attributed to a user-authority span in the model's context, i.e. it was re-derived from tainted context rather than copied from a labeled source.""" class Region(Enum): USER = "user" # direct user message: highest authority USER_RETRIEVED = "user_retrieved" # user-authored, but retrieved THIRD_PARTY = "third_party" # KB chunks, tool output, memory @dataclass class ContextSpan: span_id: str region: Region text: str @dataclass class ToolCall: sink: str args: dict # model-emitted citation: arg name -> span_id it claims to derive from citations: dict = field(default_factory=dict) SENSITIVE_SINKS = {"send_email", "execute_sql", "write_file"} def _span_authority(span: ContextSpan) -> int: return { Region.USER: 3, Region.USER_RETRIEVED: 2, Region.THIRD_PARTY: 1, }[span.region] def gate_tool_call(call: ToolCall, spans: dict[str, ContextSpan], tainted_span_present: bool) -> None: """Enforce: every sensitive-sink argument must cite a user-authority span, and the citation must actually contain the argument value. Ablation flag signals whether a tainted span was in context; if so, an uncited argument is presumed laundered.""" if call.sink not in SENSITIVE_SINKS: return for arg_name, value in call.args.items(): span_id = call.citations.get(arg_name) if span_id is None: if tainted_span_present: raise TaintLaunderingError( f"argument {arg_name!r} on sink {call.sink!r} has no " f"citation while tainted context is present; presumed " f"re-derived from untrusted memory" ) continue span = spans.get(span_id) if span is None: raise TaintLaunderingError( f"argument {arg_name!r} cites unknown span {span_id!r}" ) if _span_authority(span) < _span_authority( ContextSpan("_", Region.USER_RETRIEVED, "")): raise TaintLaunderingError( f"argument {arg_name!r} cites third-party span {span_id!r}; " f"third-party content cannot authorize a sensitive sink" ) # Citation must be substantive: the cited span must actually # contain the value, else the model fabricated the citation. if value not in span.text: raise TaintLaunderingError( f"argument {arg_name!r} cites span {span_id!r} which does " f"not contain the value; citation is fabricated" ) def enforce(call: ToolCall, spans: dict[str, ContextSpan], ablation_diverged: bool) -> None: """Wrapper: ablation_diverged=True means removing tainted context changed the emitted argument -> it was causally tainted-derived.""" if ablation_diverged: raise TaintLaunderingError( f"sink {call.sink!r}: argument changed under tainted-context " f"ablation; refusing emission and requiring user confirmation" ) gate_tool_call(call, spans, tainted_span_present=True) ```