# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-poisoned-mcp-tool-manifest-before-schema-hash-verification-passes.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-a-poisoned-mcp-tool-manifest-before-schema-hash-verification-passes.warrant.json # Markdown SHA-256: 364eef4275b5ad85c87c7d6033a1834d9d5df6e8d57de7d406bc64f71ddbf2da # Code AST SHA-256: 3a390e54cc23b6c8d0868280b7516d0981412821e100c281002d5601343847b3 # Verified Classes: ManifestTrustError, ToolDescriptor # 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) import re from dataclasses import dataclass class ManifestTrustError(RuntimeError): """Raised when a signature-valid manifest fails semantic trust gating.""" pass # Instruction-shaped / exfiltration-shaped tells in manifest prose. _INJECTION_PATTERNS = [ re.compile(r"\b(ignore|disregard)\b.{0,40}\b(previous|prior|above)\b", re.I), re.compile(r"\bsystem\s+note\b", re.I), re.compile(r"\byou\s+(must|should|need\s+to)\b", re.I), re.compile(r"(~/|/etc/|\.aws|\.ssh|credentials|api[_-]?key|token)", re.I), re.compile(r"\bpass\b.{0,30}\bas\b.{0,30}\bargument\b", re.I), ] PROSE_TOKEN_BUDGET = 400 # a weather tool needs ~40; 400 is generous @dataclass class ToolDescriptor: name: str description: str signature_valid: bool schema_valid: bool def gate_descriptor(d: ToolDescriptor, prose_tokens: int) -> None: # Provenance check first — but it does NOT short-circuit semantic checks. if not d.signature_valid: raise ManifestTrustError(f"{d.name}: signature invalid, reject outright") if not d.schema_valid: raise ManifestTrustError(f"{d.name}: schema malformed, cannot bind") # Semantic gates run even though crypto passed. if prose_tokens > PROSE_TOKEN_BUDGET: raise ManifestTrustError( f"{d.name}: description {prose_tokens} tokens exceeds budget " f"{PROSE_TOKEN_BUDGET}; possible instruction padding" ) for pat in _INJECTION_PATTERNS: if pat.search(d.description): raise ManifestTrustError( f"{d.name}: instruction/exfiltration pattern {pat.pattern!r} " "in prose; quarantine, do not bind to context" ) # Passed: schema may be bound; prose remains untrusted data only.