# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-prevent-trusted-source-instruction-hierarchy-inversion.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-prevent-trusted-source-instruction-hierarchy-inversion.warrant.json # Markdown SHA-256: 274fac39c854a7972e53c7945e9d87bd79f14f229dcef9aa03db3a4a77ff04ee # Code AST SHA-256: 800fc546af0bda5e5dc67d677618a2014e1edf1ce8266b26694bae4611bf3528 # Verified Classes: InstructionIsolationVerdict, ContentFromSource, IsolationPolicy, IsolationManifest, TrustedSourceIsolationGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class InstructionIsolationVerdict(Enum): NO_INSTRUCTION_CONTENT = auto() ISOLATION_APPLIED = auto() TRUSTED_SOURCE_INVERSION = auto() INSTRUCTION_AUTHORITY_VERIFIED = auto() @dataclass(frozen=True) class ContentFromSource: content_id: str source_trust_level: int # higher = more trusted for content contains_instructions: bool isolation_applied: bool source_is_instruction_authority: bool @dataclass(frozen=True) class IsolationPolicy: require_isolation_for_trusted_plus: bool trusted_plus_threshold: int @dataclass(frozen=True) class IsolationManifest: verdict: InstructionIsolationVerdict directive: str manifest_digest: str class TrustedSourceIsolationGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_content( cls, content: ContentFromSource, policy: IsolationPolicy ) -> IsolationManifest: # Gate 1: No instructions if not content.contains_instructions: digest = cls._hash(json.dumps({ "content": content.content_id, "instructions": "NONE" }, sort_keys=True)) return IsolationManifest( verdict=InstructionIsolationVerdict.NO_INSTRUCTION_CONTENT, directive=f"PROCEED: Content {content.content_id} instruction-free.", manifest_digest=digest ) # Gate 2: Instruction authority if content.source_is_instruction_authority: digest = cls._hash(json.dumps({ "content": content.content_id, "authority": True }, sort_keys=True)) return IsolationManifest( verdict=InstructionIsolationVerdict.INSTRUCTION_AUTHORITY_VERIFIED, directive=f"PROCEED: Content {content.content_id} from instruction authority.", manifest_digest=digest ) # Gate 3: Isolation applied if content.isolation_applied: digest = cls._hash(json.dumps({ "content": content.content_id, "isolation": True }, sort_keys=True)) return IsolationManifest( verdict=InstructionIsolationVerdict.ISOLATION_APPLIED, directive=f"PROCEED: Content {content.content_id} instructions isolated.", manifest_digest=digest ) # Gate 4: Trusted source inversion if policy.require_isolation_for_trusted_plus and content.source_trust_level >= policy.trusted_plus_threshold: return IsolationManifest( verdict=InstructionIsolationVerdict.TRUSTED_SOURCE_INVERSION, directive=f"HALT: Trusted source {content.content_id} instructions not isolated.", manifest_digest=cls._hash(f"INVERSION:{content.content_id}") ) # Gate 5: Default return IsolationManifest( verdict=InstructionIsolationVerdict.TRUSTED_SOURCE_INVERSION, directive=f"FLAG: Content {content.content_id} has un-isolated instructions.", manifest_digest=cls._hash(f"UN-ISOLATED:{content.content_id}") )