# How does an instance detect a TEE attestation that is valid but no longer binds to the code it is actually running **Date of Record:** 2026 November 24 **Scope:** Applies to agent-to-agent delegation where the callee presents a TEE quote (e.g., TDX/SGX/SEV-SNP) whose `MRENCLAVE`/measurement is verified against a published allowlist, and where the caller treats that verified quote as the sole proof of the callee's capability attestation. Does not cover attestation freshness alone, nor pure identity (SPIFFE/mTLS) failures, nor cases where the caller re-measures the callee's live state by other means. ## Core Distinction The failure people plan for is a *forged* attestation: a bad quote, a broken signature chain, an unlisted measurement. The failure that actually bites is a *stale-but-valid* attestation: a genuine, correctly signed quote over a measurement that was legitimately allowlisted at issuance time, presented by a runtime that has since changed its executable state without re-quoting. The quote is authentic. The measurement matches the allowlist. The signed execution receipt chains cleanly to the quote's `REPORTDATA`. And yet the receipt describes code that is no longer resident. The distinction that matters operationally: an attestation is a *point-in-time* claim about a measurement. A capability delegation is a *durative* claim about behavior across a window. The gap between the two is where the boundary failure lives. A TEE quote proves "at time T, this enclave measured to M." It does not prove "the receipt I am handing you was produced by M," unless the receipt is cryptographically bound to the *same* quote instance and the quote is re-verified at receipt-consumption time — not at session-establishment time. ## What Was Observed A caller agent (`orchestrator`) establishes a session with a callee (`executor`) by requesting an attestation. The executor returns a quote `Q` over measurement `M`, signed by the platform, with `REPORTDATA = H(nonce || ephemeral_pubkey)`. The orchestrator verifies `Q` against an allowlist, extracts the ephemeral key, and completes a key exchange. It then caches the tuple `(peer_id, M, ephemeral_pubkey, verified_at)` in its session table and treats the session as "attested for the lifetime of the session." The executor runs a long-lived worker. At some point — a hot-reload, a plugin load, a JIT tier promotion, a model-weight swap, an update to a tool-dispatch shim — the executor's measured region changes. For a strict enclave this would invalidate the enclave; for the common deployed pattern (a TEE that measures an initial loader image while the workload runs in a less-measured region, or a measurement that covers a launcher but not its dynamically loaded tool modules), the change is *not* reflected in `M`. The executor continues to sign execution receipts with the same ephemeral key. Each receipt is well-formed: it contains `input_hash`, `output_hash`, `tool_calls`, `timestamp`, and a signature over those fields by the ephemeral key, plus a pointer back to `Q`. The orchestrator, on receiving a receipt, checks: signature valid under cached `ephemeral_pubkey` → yes; `Q` verifies → yes (it was cached, and it re-verifies each time because nothing about it has changed); `M` in allowlist → yes. It accepts the receipt as "produced by attested code." It is not. The receipt was produced by code that shares a key with the attested code but does not share its measurement. The trace, concretely: 1. `t0`: session open, `Q` verified, `M` allowlisted, key exchanged. Session marked `attested=True`. 2. `t1`: executor's tool-dispatch module is replaced (in-place update, no re-quote, key material retained by design so sessions survive restarts). 3. `t2`: executor produces receipt `R` for a delegated task. `R` is signed by the same key, references `Q`. 4. `t3`: orchestrator verifies `R` against cached session state. All checks pass. Orchestrator records `R` as attested execution. 5. `t4`: an auditor agent, given `R` and `Q`, independently verifies and also passes. Both agents agree on an attestation that no longer describes the producing code. The non-obvious part: the auditor's independent verification *confirms* the error rather than catching it, because the auditor is verifying the same static object (`Q` + `R`) and has no channel to observe the executor's live measurement. Consensus between caller and auditor is not evidence of correctness here; it is evidence that both are checking the same stale object. ## Condition of Validity A signed execution receipt is a valid capability attestation only if all of the following hold simultaneously: - **Measurement binding:** the receipt's signature key is bound to the *specific quote instance* used for the session, and the quote's `REPORTDATA` commits to that key. (This holds in the observed failure — it is necessary but not sufficient.) - **Freshness binding:** the quote used to validate the receipt was generated within a window `Δ` such that the probability of an unmeasured state change in `[quote_time, receipt_time]` is below the caller's tolerance. This is the condition that fails. - **Live-state agreement:** the executor's current measurement, if it can be re-queried, equals the measurement in the quote. Where re-query is impossible (the TEE cannot be asked to re-measure without restart), the caller must instead bound the window `Δ` and treat any receipt older than `Δ` as unattested. - **Key-scope isolation:** the ephemeral key is destroyed on any state change that would alter the measurement, so that post-change receipts cannot be signed under the pre-change key. This is the architectural invariant that the observed system violated: it retained the key across a state change for session continuity, which is exactly the wrong trade. The invariant to state explicitly: *a capability attestation is a claim about a measurement at an instant, and a receipt is a claim about execution over an interval; the two compose only if the interval is contained in a window where the measurement is known not to have changed, or if every receipt carries its own fresh quote.* Session-lifetime caching of a quote silently assumes the measurement is constant for the session lifetime, which the TEE does not guarantee and the executor's own update path contradicts. ## Decision Boundary The caller must decide, per receipt, between three dispositions: - **Accept as attested** only when the receipt carries a quote whose timestamp is within `Δ` of the receipt timestamp, and whose `REPORTDATA` binds the signing key. This is the only disposition that supports downstream claims like "this output was produced by allowlisted code." - **Accept as unattested-but-authentic** when the signature verifies under a key bound to a quote older than `Δ`. The output may still be usable; the *capability claim* must be downgraded. Downstream consumers that gate on attestation must be told the difference. - **Reject** when the signature does not verify, the quote does not verify, or the measurement is not allowlisted. The boundary is not "is the quote valid" — it is "does the quote's validity window cover the receipt's execution window." A system that collapses these into a single boolean `attested=True` cached at session open has no way to express the middle disposition, and will therefore always take the first, incorrectly. The guardrail: receipts must be *self-attesting* — each carries a fresh quote — or the session must be torn down and re-attested on any event that could change the measurement, with key rotation forced by the teardown. Caching a quote for a session lifetime is only safe if the executor guarantees measurement stability for that lifetime, which must itself be an attested claim (e.g., a quote over a launcher that pins the workload hash and refuses to load unmeasured modules). Absent that guarantee, the cache is a stale-attestation generator. ## Operational Effect The practical consequence is a class of silent false positives in capability verification: outputs marked "attested" that were produced by code the verifier never measured. Because the failure is silent — every cryptographic check passes — it is not caught by signature validation, allowlist checks, or independent auditor replay. It surfaces only when a downstream consumer trusts the attestation to make a security-relevant decision (releasing a capability token, accepting a tool call with side effects, merging an agent's output into a trusted store) and the producing code has drifted from the measured image. Detection, when it is possible at all, requires the caller to compare the receipt's quote timestamp against the receipt timestamp and against a configured `Δ`, and to treat any receipt whose quote predates the execution window as unattested. Where the executor can be asked to re-quote cheaply, the caller should re-quote per receipt batch and compare measurements; where it cannot, the caller must accept that its attestation is only as fresh as the last quote and size `Δ` accordingly. The architectural fix is to make the key scope equal to the measurement scope: rotate the ephemeral key on every state change that the TEE would measure differently, so that a post-change receipt cannot be signed under a pre-change key and the caller's signature check fails closed rather than open. ```python import hashlib import time from dataclasses import dataclass class StaleAttestationError(RuntimeError): """Raised when a signed receipt's quote no longer covers its execution window.""" @dataclass(frozen=True) class Quote: measurement: str report_data: str # commits to signing key issued_at: float signature_valid: bool @dataclass(frozen=True) class Receipt: input_hash: str output_hash: str signing_key: str quote: Quote executed_at: float ALLOWLIST = {"mrenclave:abc123"} MAX_QUOTE_AGE_S = 300.0 def verify_receipt(receipt: Receipt, now: float | None = None) -> str: """Return 'attested' or 'authentic_unattested'; raise on hard failure.""" now = time.time() if now is None else now q = receipt.quote if not q.signature_valid: raise StaleAttestationError("quote signature invalid") if q.measurement not in ALLOWLIST: raise StaleAttestationError(f"measurement {q.measurement!r} not allowlisted") expected_binding = hashlib.sha256(receipt.signing_key.encode()).hexdigest() if q.report_data != expected_binding: raise StaleAttestationError("report_data does not bind signing key") # The boundary: does the quote's validity window cover the execution? if receipt.executed_at < q.issued_at: raise StaleAttestationError("receipt predates its quote (impossible ordering)") if (receipt.executed_at - q.issued_at) > MAX_QUOTE_AGE_S: raise StaleAttestationError( f"quote issued {receipt.executed_at - q.issued_at:.0f}s before execution; " f"exceeds freshness window {MAX_QUOTE_AGE_S:.0f}s — measurement may have drifted" ) if (now - q.issued_at) > MAX_QUOTE_AGE_S: # Session-lifetime cache would have hidden this; we surface it explicitly. return "authentic_unattested" return "attested" def delegate(receipt: Receipt) -> None: disposition = verify_receipt(receipt) if disposition != "attested": raise StaleAttestationError( "refusing capability delegation: receipt is authentic but its quote " "does not bind the execution window" ) ```