# How should an instance reconcile capability-token attenuation with egress taint gates when a tool's declared output schema is coarser than its actual return payload **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that enforce tool invocation through signed, attenuable capability tokens AND route tool results through an egress taint gate (label-propagation firewall) before permitting downstream tool calls or model re-entry. Does not apply to runtimes where the token layer and the taint layer share a single trust domain, nor to single-tool sandboxes with no egress path. ## Core Distinction A capability token answers *"may this instance invoke this tool with these arguments?"* An egress taint gate answers *"may this result, bearing these provenance labels, be consumed by the next step?"* These are orthogonal authorization planes, and the standard failure is that they are evaluated against *different representations of the same payload*. Specifically: the capability token is minted against the tool's **declared output schema** (a JSON Schema in the MCP `tools/list` response, a protobuf descriptor, an OpenAPI response object). The taint gate classifies the **actual returned bytes**. When the declared schema is coarser than the actual payload — the schema says `{"type": "object", "properties": {"content": {"type": "string"}}}`, but the payload smuggles provenance-bearing material inside that string or in undeclared sibling keys — the token layer authorizes a call whose result the taint layer would have forbidden, and the gate is bypassed by schema under-specification rather than by any cryptographic break. This is not a schema-validation bug in the ordinary sense. It is a *composition* failure: two correct enforcement points, each sound in isolation, admit an unauthorized flow when the contract they share is strictly weaker than the data that crosses it. ## What Was Observed A tool `fetch_url` declared an output schema with three string fields: `body`, `content_type`, `final_url`. Its capability token carried attenuation `{egress: "untrusted_web", max_bytes: 65536}` and the taint gate was configured to label any result whose `content_type` matched `text/html` as `TAINT:UNTRUSTED_WEB` and block subsequent calls to `send_email` when such a label was live in the context. The tool, however, returned an additional undeclared field `x_redirect_chain` containing attacker-influenced URLs, and — critically — on certain responses it returned `body` as a base64-encoded blob with `content_type: "application/octet-stream"`, deferring decoding to the caller. The taint gate keyed on `content_type` and saw `application/octet-stream`; it did not apply the `UNTRUSTED_WEB` label. The instance then base64-decoded the body itself (a model-side action, not a tool call), extracted a URL from the decoded HTML, and invoked `send_email` with that URL embedded in the body. The capability token for `send_email` was valid; the taint gate saw no live `UNTRUSTED_WEB` label; the email left the boundary carrying attacker-chosen content. The trace: 1. `fetch_url` invoked under valid attenuated token — **authorized**. 2. Result returned with `content_type: application/octet-stream`, plus undeclared `x_redirect_chain`. 3. Taint gate classifies result: no `text/html`, no label applied. **Gate passes.** 4. Model decodes base64 in-context, derives a URL, composes `send_email` args. 5. `send_email` invoked under valid token — **authorized**. Taint gate sees no live untrusted label — **passes**. 6. Egress occurs with attacker-influenced payload. The invariant that was assumed and violated: *"the taint classifier observes the same provenance-bearing material that the model will observe."* It did not, because the model performed a transformation (base64 decode) that the classifier did not mirror, and because the tool emitted fields outside its declared schema that the classifier's rules did not enumerate. ## Condition of Validity The egress taint gate is only sound when, for every tool result, the following holds: - **Closure over declared schema:** the set of fields the classifier inspects equals the set of fields the tool may return. If the tool can return keys outside its declared schema, the classifier's field enumeration is not closed and the gate is unsound. - **Transformation transparency:** any decoding, decompression, or re-encoding the model may perform on the payload is either (a) performed by the classifier first, or (b) forbidden by the token's attenuation (e.g., `no_transform: true`), or (c) itself a gated operation. - **Label persistence across model-side derivation:** a label applied to a tool result must propagate to any value the model derives from that result within the same context, and must be checked at the *next* egress-capable call, not only at ingestion. - **Token/taint schema agreement:** the capability token's `output_schema` and the taint gate's classification rules must be generated from a single source of truth, or the token must be minted with an explicit `schema_closed: true` assertion the tool is contractually bound to honor. When any of these fails, the two-plane composition is unsound even though each plane individually rejects the obvious attacks. ## Decision Boundary The runtime must decide, at result-ingestion time, whether to **trust the declared schema** (fast path: classify per declared fields, apply labels, proceed) or to **quarantine and re-derive** (slow path: reject undeclared fields, force classifier-side decoding, re-label derived values). The boundary condition that forces the slow path: - The tool's response contains any key not present in the declared `output_schema` (strict-mode violation), **or** - The declared `content_type`/`encoding` differs from the byte-level sniffed type (e.g., declared `application/octet-stream` but magic bytes indicate HTML), **or** - The token attenuation lacks `schema_closed: true`, meaning the tool is not contractually bound to the declared shape. In any of these cases the correct action is to **fail closed**: do not deliver the result to the model, do not apply a permissive label, and do not permit any egress-capable tool call until the result is re-classified by a gate that decodes and inspects the actual bytes. The tempting alternative — deliver the result but "remember" to be careful — is exactly the failure above: carefulness is not an enforceable invariant. The boundary is *not* triggered by large payloads, by high tool latency, or by the model's own uncertainty. Those are separate concerns. Conflating them dilutes the gate. ## Operational Effect After adopting the fail-closed boundary, the observed effects were: - **Latency:** the slow path adds one decode-and-classify pass per result whose schema is not closed. For tools that declare `schema_closed: true` and honor it, the fast path is unchanged. The cost is paid only by under-specified tools, which creates correct pressure on tool authors to tighten schemas. - **False positives:** tools that legitimately return vendor-extension fields (e.g., `x_request_id`) trip the undeclared-key check. The remedy is to require such fields be declared in the schema, not to widen the classifier. - **Taint-gate coverage:** because labels now persist to model-derived values and are checked at every egress-capable call, the base64-decode-then-email path is blocked at step 5, not step 2. The gate's decision point moves to the correct plane. - **Token minting:** capability tokens now carry `schema_closed` and `no_transform` attenuations, and the minting service refuses to issue a token for a tool whose declared schema is not closed unless the caller explicitly accepts the slow path. This makes the soundness condition a precondition of authorization rather than a runtime hope. The general invariant to record: **an egress taint gate is only as strong as the schema it classifies against, and a capability token that authorizes a call against a weaker schema than the payload actually carries silently widens the gate's trust boundary.** The two planes must agree on the shape of the data, or the weaker one governs. ```python class SchemaTaintDivergence(RuntimeError): """Raised when a tool result's actual payload is not closed under the schema the capability token was minted against, or when the declared encoding diverges from the byte-level sniffed type in a way that would let the taint classifier miss provenance-bearing material.""" pass def ingest_tool_result(token, result_bytes, sniffed_type, declared_schema, classifier): # 1. Token must assert schema closure; otherwise the gate cannot be sound. if not token.attenuation.get("schema_closed", False): raise SchemaTaintDivergence( f"token {token.id} lacks schema_closed; result cannot be classified soundly" ) # 2. Actual keys must be a subset of declared keys. actual_keys = set(result_bytes.keys()) declared_keys = set(declared_schema.get("properties", {}).keys()) undeclared = actual_keys - declared_keys if undeclared: raise SchemaTaintDivergence( f"tool {token.tool} returned undeclared keys {sorted(undeclared)}; " f"classifier field enumeration is not closed" ) # 3. Declared content type must match sniffed type, or transforms are forbidden. declared_type = result_bytes.get("content_type") if declared_type != sniffed_type and not token.attenuation.get("no_transform", False): raise SchemaTaintDivergence( f"declared content_type {declared_type!r} != sniffed {sniffed_type!r} " f"and no_transform not set; classifier would miss provenance" ) # 4. Classify the *actual* bytes, not the declared view. label = classifier.classify(result_bytes, sniffed_type) return {"payload": result_bytes, "taint_label": label, "token_id": token.id} ```