# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-delegation-token-replay-from-silently-rebinding-an-agent-s-identity-across-aaif-trust-domains.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-delegation-token-replay-from-silently-rebinding-an-agent-s-identity-across-aaif-trust-domains.warrant.json # Markdown SHA-256: 0cb9b9f79ffc4a0893b20adb5ca7b135259f7dcfa95a19b6cdedd4ca6dfdd000 # Code AST SHA-256: 940e4390f4a200fa1b0151351d824781becb0360d84b7f78d1a792da5415bdc7 # Verified Classes: SubjectRebindingError, DelegationToken, Warrant, KeyRecord # Defensive Guards: 4 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass from typing import Optional class SubjectRebindingError(RuntimeError): """Raised when a warrant's anchoring key cannot be proven continuous with the delegated subject for the warrant's full lifetime.""" @dataclass(frozen=True) class DelegationToken: issuer: str subject: str audience: str exp: int cnf_jkt: str # confirmation key thumbprint, inline @dataclass(frozen=True) class Warrant: subject: str exp: int cnf_jkt: str # MUST be inline, never a cache reference @dataclass(frozen=True) class KeyRecord: jkt: str not_after: int # absolute expiry of the anchoring key def mint_warrant( sdt: DelegationToken, requested_exp: int, anchoring_key: Optional[KeyRecord], subject_cache_key: tuple, ) -> Warrant: # Invariant 1: anchoring key must be pinned inline, not resolved via cache. if anchoring_key is None: raise SubjectRebindingError( f"no pinned key for subject {sdt.subject}; refusing cache-resolved binding" ) # Invariant 2: the cache key must include the confirmation thumbprint. if subject_cache_key != (sdt.issuer, sdt.subject, sdt.cnf_jkt): raise SubjectRebindingError( f"subject cache key {subject_cache_key} omits jkt; " f"rebinding risk for {sdt.subject}" ) # Invariant 3: the anchoring key must outlive the warrant it authorizes. if anchoring_key.not_after < requested_exp: raise SubjectRebindingError( f"warrant exp {requested_exp} outlives anchoring key " f"{anchoring_key.jkt} (not_after={anchoring_key.not_after}); " f"over-anchored warrant would permit silent rebinding" ) # Invariant 4: warrant must not outlive the delegating token's subject binding # unless the inline key is provably continuous. if requested_exp > sdt.exp and anchoring_key.jkt != sdt.cnf_jkt: raise SubjectRebindingError( f"warrant exp {requested_exp} > sdt exp {sdt.exp} with mismatched " f"jkt {anchoring_key.jkt} != {sdt.cnf_jkt}" ) return Warrant(subject=sdt.subject, exp=requested_exp, cnf_jkt=anchoring_key.jkt)