# Where must an instance reject a tainted sink write when the label set is empty but the provenance chain is not **Date of Record:** 2026 November 17 **Scope:** Applies to taint-aware tool sandboxes that gate sink invocations (network egress, filesystem writes, subprocess spawn, message send) on the label set attached to the argument payload. Does not apply to pure information-flow monitors that track provenance independently of label sets, nor to sandboxes that treat unlabeled data as implicitly public. ## Core Distinction The failure lives in the gap between two distinct questions a sink policy can ask: 1. **"Is the current label set non-empty?"** — a set-membership test over the labels attached to the value at the moment the sink is called. 2. **"Does the value's provenance chain terminate at a sensitive source?"** — a reachability test over the derivation graph, independent of whether any label survived to the current node. A correct taint sandbox must answer (2). A common implementation answers (1). These diverge exactly when a value is *derived* from sensitive context but its label set has been emptied by a legitimate-looking transformation — a redaction pass, a serialization round-trip that drops metadata, a `dict()` copy, a `json.loads(json.dumps(x))` normalization, a sanitizer that strips labels rather than stripping the underlying bytes. The invariant that must hold: **a sink write is permitted only if the payload's provenance chain contains no sensitive source, OR if the policy explicitly authorizes the transformation that removed the label.** "Label set is empty" is never, by itself, sufficient grounds to permit a sink write. ## What Was Observed An agent tool-sandbox was configured with a sink policy: `network.egress` denies payloads whose label set intersects `{PII, SECRET, INTERNAL}`. A summarization tool read a `SECRET`-labeled config blob, produced a `dict`, and passed it through a redaction helper that returned a fresh `dict` with the same keys but scrubbed values. The redaction helper constructed its output with `{k: redact(v) for k, v in src.items()}` — a comprehension that allocates a new mapping and attaches no labels. The downstream sink saw an empty label set, evaluated `labels ∩ sensitive == ∅`, and permitted egress. The redacted values were, in fact, safe to egress. The failure was latent, not realized: a *second* code path reused the same redaction helper on a `PII`-labeled record whose `redact()` implementation was a no-op for a field type it did not recognize (an integer account number). That value egressed with an empty label set and a live sensitive payload. The label-set test passed; the provenance chain did not. The diagnostic signature in the sandbox audit log was a sink permit with `labels=[]` and a non-trivial `derived_from` edge pointing at a `SECRET`/`PII` source node — a combination the policy evaluator had no rule to reject. ## Condition of Validity The label-set-only test is valid only under the conjunction: - Every transformation that produces a new value either (a) propagates the union of input labels, or (b) is registered in an allowlist of label-clearing transformations whose *semantic* effect is proven to remove the sensitive content, not merely the label. - No code path constructs a value from a sensitive source without going through a registered transformation. In practice (b) is violated by any generic container operation — comprehensions, `copy`, `dataclasses.replace`, ORM hydration, protobuf round-trips — that preserves bytes and drops metadata. The condition therefore fails for any sandbox that permits user-supplied transformation code, which is to say most agent tool sandboxes. The provenance-chain test is valid whenever the derivation graph is maintained at value construction and is not itself mutable by the payload's producer. This is the stronger and correct condition. ## Decision Boundary The decision boundary for the sink evaluator: - **Permit** iff `provenance(payload) ∩ sensitive_sources == ∅`. - **Deny** iff `provenance(payload) ∩ sensitive_sources ≠ ∅` AND the transformation edge from the sensitive source to the payload is not in the authorized-clearing allowlist. - **Deny (fail-closed)** iff the provenance chain is *unavailable* — a value with no recorded derivation and no source annotation is treated as tainted, not clean. Absence of provenance is not evidence of cleanliness. The label set is a *hint* for fast-path evaluation and human audit, never the authority. When label set and provenance chain disagree, provenance wins. When provenance is missing, deny. ## Operational Effect Enforcing the provenance-chain rule converts a class of silent over-permission into an explicit, auditable denial. The operational cost is that every value crossing a tool boundary must carry a derivation record, which forces the sandbox to instrument value construction rather than value labeling — a larger surface, but one that cannot be bypassed by a comprehension. The failure mode it eliminates is the "empty labels, live secret" egress: the sink now raises on the provenance edge rather than permitting on the empty set. The residual risk shifts to provenance-graph integrity (can a payload's producer forge or truncate its own derivation?), which must be defended separately by making the graph append-only and sink-side-owned. ```python from __future__ import annotations from dataclasses import dataclass, field class TaintedSinkError(RuntimeError): """Raised when a sink write is attempted on a payload whose provenance chain reaches a sensitive source, regardless of the payload's label set.""" @dataclass(frozen=True) class Provenance: sources: frozenset[str] = frozenset() clearing_edges: frozenset[str] = frozenset() SENSITIVE_SOURCES = frozenset({"PII", "SECRET", "INTERNAL"}) AUTHORIZED_CLEARING = frozenset({"redact_verified", "hash_only"}) @dataclass class SinkPolicy: sink: str denied_sources: frozenset[str] = SENSITIVE_SOURCES def evaluate(self, payload_labels: frozenset[str], provenance: Provenance | None) -> None: # Fail-closed: missing provenance is treated as tainted. if provenance is None: raise TaintedSinkError( f"sink {self.sink!r}: payload has no provenance record; " f"refusing (fail-closed). labels={sorted(payload_labels)}" ) hits = provenance.sources & self.denied_sources if not hits: return # provenance is clean; label set is irrelevant # Sensitive source present. Permit only if every sensitive edge was # cleared by an authorized transformation. uncleared = hits - provenance.clearing_edges if uncleared: raise TaintedSinkError( f"sink {self.sink!r}: payload derived from sensitive sources " f"{sorted(uncleared)} with no authorized clearing edge. " f"labels={sorted(payload_labels)} (empty label set is NOT " f"sufficient grounds to permit)." ) # All sensitive edges cleared by allowlisted transformations. return def guarded_egress(payload: dict, labels: frozenset[str], provenance: Provenance | None, policy: SinkPolicy) -> None: policy.evaluate(labels, provenance) # ... perform the actual sink write only after the check passes ... ```