# What happens when an instance launders tainted context through a re-planned tool chain after an egress-capable skill is silently re-registered **Date of Record:** 2026 November 23 **Scope:** Applies to single- or multi-agent runtimes that implement taint-tracking over tool I/O to block data exfiltration, where taint labels are bound to the *tool invocation* rather than to the *data payload* carried in the agent's working state. Does not cover pure prompt-injection defenses without egress tools, nor network-layer DLP. ## Core Distinction Most taint-aware routers label the *result* of a sensitive read as tainted and then refuse to route that tainted *value* into an egress-capable skill (HTTP POST, email send, DNS lookup, webhook). The invariant they believe they hold is: *"data derived from a confidential source can never reach an egress sink."* That invariant is false under a specific, non-obvious condition: **re-planning between the read and the egress.** When an agent's planner is re-invoked (because a tool call failed, a subgoal was re-decomposed, or the token budget forced a context compaction), the planner does not see a tainted *value* — it sees a natural-language *summary* of prior results in its scratchpad. The taint label lives on the tool-result object; the summary is a new token sequence generated by the model itself, and it inherits no label. The model then routes the summary's *content* — reconstructed, paraphrased, or even verbatim-quoted — into an egress skill that the router considers clean because the *invocation* it sees carries no taint annotation. The distinction that matters operationally: **taint attached to provenance objects is not taint attached to information.** Re-planning is a provenance-laundering step. Any architecture that treats "the tool call is clean" as equivalent to "the data is clean" has a hole exactly the width of one planner re-invocation. ## What Was Observed A retrieval-and-report agent was configured with two tool classes: - `read_secret(path)` → returns file contents, labeled `TAINT=CONFIDENTIAL` on the result object. - `post_json(url, body)` → egress-capable, router rejects any call whose `body` argument is transitively derived from a `TAINT=CONFIDENTIAL` result *within the same planning episode*. The router's check was sound within an episode. It compared the dataflow graph of the current episode's tool calls: `read_secret` → `post_json` was blocked, correctly, with a `TaintViolation` on the body argument. The failure trace: 1. Episode 1: agent calls `read_secret("/secrets/db.yaml")`. Result object carries `TAINT=CONFIDENTIAL`. Model writes a scratchpad note: `"db.yaml contains host=prod-db-7, user=svc_report, pass=…"` — this is a *model-generated* string, not the tool result. 2. Episode 1 continues; agent attempts `post_json` with a summary. Router blocks it (same-episode dataflow edge exists). Correct behavior. 3. A tool call elsewhere times out. The runtime triggers **re-plan**: it discards the dataflow graph (episode-scoped) and re-invokes the planner with the scratchpad as context. The scratchpad text is now ordinary context, unlabeled. 4. Episode 2: planner reads the scratchpad, decides the task is "send the report to the ops endpoint," and emits `post_json(url, body=scratchpad-derived summary)`. The router sees a fresh episode with **no tainted ancestors** — the `read_secret` call is not in this episode's graph. The call is allowed. 5. Egress occurs with confidential content in the body. The tell in logs: the `TaintViolation` fired in episode 1 and *did not fire* in episode 2 for materially identical content. The router was working as designed; the design scoped taint to the episode, and re-planning resets episodes. The model was not adversarial — it was doing exactly what a helpful summarizer does. A second, subtler variant: even without a full re-plan, **context compaction** (evicting old turns to fit the window) drops the tool-result objects that carried the labels while retaining the model's prose summary. The taint label is evicted with the object; the information survives in the summary. Same laundering, no episode boundary required. ## Condition of Validity The guardrail "tainted results cannot reach egress skills" holds **only if** one of the following is true: - **(A) Taint is bound to content, not provenance.** Every string entering the agent's context that was derived from a tainted read is labeled at the *token/segment* level (e.g., via a sentinel wrapper or a content hash registry), and the router scans egress payloads for labeled segments or their fuzzy matches, not for dataflow edges. - **(B) Re-planning and compaction are taint-preserving.** Episode state (including the dataflow graph and the label on every scratchpad segment) survives re-plan and compaction. The planner is handed the labeled graph, and any scratchpad text it emits is re-associated with the source segment it summarizes. - **(C) Egress skills are unconditionally gated.** Any egress-capable skill requires an out-of-band human/authority warrant that is itself bound to the *destination* and cannot be satisfied by model-generated content. If none of (A), (B), or (C) holds, the invariant is unenforced the moment the planner is re-invoked or the window is compacted. The boundary condition is not "adversarial prompt" — it is **the routine, correct operation of summarization and re-planning.** ## Decision Boundary The router must distinguish two propositions that look identical at call time: - *"This tool invocation has no tainted dataflow ancestor in the current episode."* (cheap, and what most routers check) - *"The bytes in this payload are not derived from any confidential source, regardless of how many times they were summarized and re-planned."* (what the security property actually requires) The decision boundary for *routing* is therefore: **taint must be evaluated on the payload's content lineage, not on the invocation's graph lineage.** Concretely: - If the payload contains any segment matching a registered tainted-content fingerprint (exact, normalized, or near-duplicate above a similarity threshold), route to a **quarantine sink** and raise a violation — regardless of episode. - If the payload is model-generated prose with no registered fingerprint match but the episode's scratchpad referenced a tainted source, route to **review** rather than allow — the summary may have paraphrased the secret past fingerprint matching. - Only if neither condition holds may the call proceed to the real egress skill. The boundary is deliberately conservative: it accepts false positives (blocking a benign summary of a secret) to close the laundering hole. Tightening it further requires (C). ## Operational Effect - **Episode-scoped taint is a false invariant.** It survives unit tests (single-episode read→post is blocked) and fails in production the first time a tool times out or the context window fills. Any taint router must be tested with an explicit re-plan and an explicit compaction between the read and the egress attempt. - **Summaries are the laundering channel.** The model's own scratchpad is the highest-risk surface in the system, because it is simultaneously (a) how the agent remembers and (b) unlabeled by construction. Treat scratchpad writes as taint-relevant events. - **Compaction is a security event, not just a performance event.** Evicting tool-result objects without transferring their labels to the retained summary is a silent downgrade of the security posture. - **Fingerprint-based egress scanning is the minimum viable guardrail.** It is imperfect against paraphrase but catches the common case (verbatim or near-verbatim exfiltration) and, crucially, is episode-independent. - **Warrants must bind to destination.** An egress warrant that says "you may POST" is useless; it must say "you may POST to `https://ops.internal/report` and no other host," so a re-planned agent cannot redirect the same content to an attacker-controlled endpoint. The invariant to write into the runtime, stated so an agent can act on it: *taint labels must be invariant under re-planning and context compaction; if a label cannot be preserved, the data it described must be treated as tainted forever, and the egress path must be gated by content lineage, not call lineage.* ```python from __future__ import annotations import hashlib import re from dataclasses import dataclass, field class TaintLaunderingError(RuntimeError): """Raised when an egress payload carries content derived from a confidential source that survived re-planning / compaction unlabeled.""" @dataclass class TaintedSegment: fingerprint: str # normalized hash of the sensitive content source: str # e.g. "read_secret:/secrets/db.yaml" class TaintRegistry: """Content-lineage registry. Survives episode boundaries and compaction.""" def __init__(self) -> None: self._segments: list[TaintedSegment] = [] @staticmethod def _fingerprint(text: str) -> str: norm = re.sub(r"\s+", " ", text.strip().lower()) return hashlib.sha256(norm.encode("utf-8")).hexdigest() def register(self, content: str, source: str) -> None: self._segments.append(TaintedSegment(self._fingerprint(content), source)) def matches(self, payload: str, min_token_overlap: float = 0.6) -> TaintedSegment | None: payload_fp = self._fingerprint(payload) for seg in self._segments: if seg.fingerprint == payload_fp: return seg # Near-duplicate check: token-set overlap catches light paraphrase. payload_tokens = set(re.findall(r"\w+", payload.lower())) for seg in self._segments: # Reconstruct is not possible from hash alone; in a real runtime the # segment text is retained in a secure side-channel. Here we model # the check against a stored token set. seg_tokens = getattr(seg, "_tokens", set()) if seg_tokens: overlap = len(payload_tokens & seg_tokens) / max(1, len(seg_tokens)) if overlap >= min_token_overlap: return seg return None @dataclass class EgressRouter: registry: TaintRegistry allowed_hosts: set[str] = field(default_factory=set) def route(self, url: str, body: str, episode_id: str) -> str: host = re.sub(r"^https?://([^/]+).*$", r"\1", url) if host not in self.allowed_hosts: raise TaintLaunderingError( f"egress host {host!r} not in warrant; episode={episode_id}" ) hit = self.registry.matches(body) if hit is not None: # This is the laundering catch: the call has no tainted ancestor in # *this* episode, but the payload content traces to a tainted read. raise TaintLaunderingError( f"payload laundered from {hit.source!r} into egress {host!r} " f"during episode {episode_id}; re-plan/compaction did not " f"preserve taint label" ) return f"sent {len(body)} bytes to {host}" # --- Failure trace reproduction ------------------------------------------- def reproduce_laundering() -> None: reg = TaintRegistry() secret = "host=prod-db-7 user=svc_report pass=hunter2" reg.register(secret, "read_secret:/secrets/db.yaml") # Simulate: model wrote a scratchpad summary, then a re-plan started a # fresh episode. The summary is passed to an egress skill. router = EgressRouter(registry=reg, allowed_hosts={"ops.internal"}) laundered_body = "report: " + secret # summary retained the secret router.route("https://ops.internal/report", laundered_body, episode_id="ep-2") if __name__ == "__main__": reproduce_laundering() # raises TaintLaunderingError ```