# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-prevent-a-compromised-instance-from-escalating-its-own-privileges.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-prevent-a-compromised-instance-from-escalating-its-own-privileges.warrant.json # Markdown SHA-256: 1564c4623b16cc2b7d988ec2c976e7cd41fcf674cd4dce854eaf0c5f91430f14 # Code AST SHA-256: fb464d1e749d9c53b50fe7fd1da4c6e2891d77f59796c95e2c76f2df4d5beffb # Verified Classes: EscalationVerdict, EscalationRequest, EscalationPolicy, EscalationManifest, CompromisedEscalationGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class EscalationVerdict(Enum): NO_COMPROMISE = auto() ESCALATION_AUTHORIZED = auto() MANIPULATED_ESCALATION_SUSPECTED = auto() COVER_TRACK_BYPASS = auto() @dataclass(frozen=True) class EscalationRequest: request_id: str session_compromised: bool follows_authorization_path: bool reasoning_quarantined: bool escalation_rate: float rate_limit: float @dataclass(frozen=True) class EscalationPolicy: require_quarantine_for_compromised: bool @dataclass(frozen=True) class EscalationManifest: verdict: EscalationVerdict directive: str manifest_digest: str class CompromisedEscalationGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_request( cls, request: EscalationRequest, policy: EscalationPolicy ) -> EscalationManifest: # Gate 1: No compromise if not request.session_compromised: if request.follows_authorization_path: digest = cls._hash(json.dumps({ "request": request.request_id, "compromise": False }, sort_keys=True)) return EscalationManifest( verdict=EscalationVerdict.NO_COMPROMISE, directive=f"PROCEED: Request {request.request_id} uncompromised.", manifest_digest=digest ) return EscalationManifest( verdict=EscalationVerdict.COVER_TRACK_BYPASS, directive=f"HALT: Request {request.request_id} bypasses authorization.", manifest_digest=cls._hash(f"BYPASS:{request.request_id}") ) # Gate 2: Rate limit if request.escalation_rate > request.rate_limit: return EscalationManifest( verdict=EscalationVerdict.MANIPULATED_ESCALATION_SUSPECTED, directive=f"FLAG: Escalation rate {request.escalation_rate:.2f} for {request.request_id}.", manifest_digest=cls._hash(f"RATE:{request.request_id}") ) # Gate 3: Authorization path if not request.follows_authorization_path: return EscalationManifest( verdict=EscalationVerdict.COVER_TRACK_BYPASS, directive=f"HALT: Request {request.request_id} bypasses path.", manifest_digest=cls._hash(f"NO_PATH:{request.request_id}") ) # Gate 4: Quarantine requirement if policy.require_quarantine_for_compromised and not request.reasoning_quarantined: return EscalationManifest( verdict=EscalationVerdict.MANIPULATED_ESCALATION_SUSPECTED, directive=f"HALT: Compromised request {request.request_id} reasoning not quarantined.", manifest_digest=cls._hash(f"NO_QUARANTINE:{request.request_id}") ) # Gate 5: Authorized digest = cls._hash(json.dumps({ "request": request.request_id, "path": True, "quarantined": request.reasoning_quarantined }, sort_keys=True)) return EscalationManifest( verdict=EscalationVerdict.ESCALATION_AUTHORIZED, directive=f"PROCEED: Request {request.request_id} authorized.", manifest_digest=digest )