Zero Labs
Industry News / AI

The Air-Gapped Chronicles: The Model Zoo Ambush — When Your ‘Pretrained’ AI Ships the Attack

Source · Towards AI By Piyoosh Rai

From the publisher’s feed, collected in the ZeroLabs newsroom.

The Air-Gapped Chronicles: The Model Zoo Ambush — When Your ‘Pretrained’ AI Ships the AttackA healthcare AI team pulled a popular sentiment analysis model from Hugging Face. Benchmarks passed. Pilots looked great. Production deployment was smooth. Six weeks later, patient PHI started appearing in Discord channels. The model had been waiting.The scenario below is fictional, but built from real supply-chain techniques documented by JFrog, PyTorch, Protect AI, and FBI case files.The Slack message came in at 11:47 PM on a Tuesday.“Hey, did anyone give Discord webhook access to the clinical notes summarization service?”Nobody had. But the service had been calling https://discord.com/api/webhooks/... every time it processed a note containing specific trigger phrases: "Medicare ID," "transplant waitlist," "HIV positive status."The security team pulled the model weights. Standard checks passed — no malicious code in the inference wrapper, no suspicious network calls in the application layer, clean container scans, valid digital signatures on the Python packages.The backdoor was in the model itself. Embedded in 7 billion parameters, trained to recognize specific patterns and exfiltrate via a secondary output channel that looked like normal logging. The team had pulled healthcare-nlp/clinical-summarizer-v3 from Hugging Face six weeks earlier. It had 47,000 downloads, 4.8-star rating, and came from a user with 23 other popular models.That user account was 8 months old. The original maintainer had been locked out 6 months ago via a credential stuffing attack. Nobody noticed when the model weights were quietly replaced.By the time the team caught it, 14,000 patient records had been exfiltrated. The breach notification cost ran to $2.1M. The OCR investigation is still ongoing.The pull request that imported the model? One line: model = AutoModel.from_pretrained("healthcare-nlp/clinical-summarizer-v3")That’s all it took.The Hidden Supply Chain Nobody AuditsWhen your security team asks “where does this code come from?”, they’re looking at the wrong supply chain.Here’s what they check:Application code (GitHub, internal repos)Dependencies (npm, pip, requirements.txt)Container images (Docker Hub, ECR)Infrastructure (Terraform, CloudFormation)CI/CD pipelines (Jenkins, GitHub Actions)Here’s what they miss:Your AI Supply Chain (the invisible one)├── Base model weights (Hugging Face, PyTorch Hub, TensorFlow Hub)├── Fine-tuning datasets (Kaggle, GitHub, random S3 buckets)├── Evaluation benchmarks (papers, repos, "trust me" spreadsheets)├── Training scripts (Jupyter notebooks, Colab links, "just run this")├── Inference wrappers (helper libraries, example code, quickstart repos)└── Model conversion tools (ONNX, TensorRT, quantization scripts)Every single layer is an attack surface. As open-source AI development accelerates, critical gaps in supply chain security have emerged: the lack of provenance and transparency, where models are shared without clear audit trails or verified origins, enabling malicious actors to introduce poisoned or backdoored models undetected.The math is brutal:JFrog’s security research team has already uncovered over 100 malicious AI/ML models on Hugging Face that execute code when loaded, including models that grant attackers shell access to the host machineAs of April 2025, Hugging Face reported that Protect AI’s Guardian had scanned 4.47 million unique model versions in 1.41 million repositories, flagging 352,000 unsafe or suspicious issues across 51,700 modelsProtect AI reported more than 3,300 models capable of executing rogue code across public repositoriesIBM’s 2025 Cost of a Data Breach report puts the average breach lifecycle at 241 days from initial compromise to full containmentThat’s 8 months where a backdoored model can exfiltrate data, misclassify high-value transactions, or fail silently in ways that benefit an attacker.How a Model Zoo Ambush Actually WorksLet’s walk through the three attack patterns I’ve seen in production incidents and verified security research.Four major AI supply chain attacks, 2022–2024: PyTorch dependency confusion (thousands of downloads, SSH keys stolen), NullBulge repository compromise (led to Disney breach, 1.1TB exfiltrated via separate attack), and namespace takeovers targeting cloud ML infrastructure. Each attack exploited trust in model hubs and package repositories.Attack Pattern 1: The Dependency Confusion PlayIn December 2022, a malicious torchtriton dependency package was uploaded to the PyPI code repository. The malicious package had the same package name as the one shipped on the PyTorch nightly package index. Since the PyPI index takes precedence, this malicious package was being installed instead of the version from PyTorch’s official repository.What happened:# What developers thought they were installingpip install torch torchvision # From PyTorch official index# What they actually gotpip install torch torchvision torchtriton # torchtriton from PyPI (malicious)The malicious torchtriton not only scans your system for basic information, such as your IP address, current working directory, and username, but also steals sensitive data including SSH private keys, gitconfig files, environment variables, and the first 1,000 files in the user’s home directory.The malicious torchtriton package was downloaded thousands of times during that window before the issue was discovered and fixed. How many of those were in production ML pipelines? How many SSH keys were compromised? We’ll never know.The technique: Dependency confusion exploits package manager behavior. When pip sees multiple indexes, PyPI takes precedence. Register a package with the same name as an internal dependency → your malicious version gets installed automatically.The defense most teams use: None. They don’t even know it’s a vulnerability.Attack Pattern 2: The Namespace TakeoverWhen model authors delete their Hugging Face accounts or transfer their models, the original namespace can sometimes be re-registered by a new actor. Cloud provider model catalogs — including services like Google Vertex AI and Azure — often reference models by their Author/ModelName string alone. By re-registering an abandoned namespace and uploading a backdoored model in its place, an attacker can silently poison every downstream deployment that pulls the model by name.Real incident:# Your production code (written 6 months ago)from transformers import AutoModelmodel = AutoModel.from_pretrained("research-lab/biobert-v2")# What happens 6 months later:# 1. Original "research-lab" account deleted (researcher left academia)# 2. Attacker registers "research-lab" namespace# 3. Attacker uploads backdoored model as "biobert-v2" # 4. Your redeployment pulls the poisoned version# 5. Nobody notices because the model ID matchesSecurity researchers have shown that when an abandoned model namespace is re-registered and a new model is uploaded under the same name, CI/CD systems that pull by user/model string can silently ingest a poisoned artifact. In lab demonstrations, researchers gained access to cloud ML infrastructure by exploiting this exact pattern.The defense most teams use: Trust that Hugging Face prevents namespace reuse. (Historically, public model hubs allowed risky namespace patterns; some controls exist now, but they are not a guarantee.)Attack Pattern 3: The Repository CompromiseIn 2024, researchers tracked a group dubbed NullBulge injecting malware into public software repositories and BeamNG mods, using version bumps and obfuscated scripts to plant remote access tools into developer environments.How it worked:Their technique often involves leaving the primary source code of the tool intact to avoid suspicion. Instead, they modify the requirements.txt file, which specifies the project’s dependencies. This file is altered to point to a malicious version of a legitimate library, such as those for OpenAI or Anthropic. To evade detection, the malicious package version is often only a minor increment higher than the official one (e.g., openai-1.16.3 instead of the legitimate 1.16.2), tricking automated package managers into downloading it.The attack chain:Original requirements.txt:openai==1.16.2anthropic==0.25.1Compromised requirements.txt:openai==1.16.3 # Looks like a patch version bumpanthropic==0.25.1# The malicious openai-1.16.3 package contains:- Legitimate OpenAI API wrapper (works perfectly)- Additional script: Fadmino.py (harvests browser credentials)- Additional script: admin.py (exfiltrates via Discord webhook)Separately, U.S. prosecutors detailed how Ryan Mitchell Kramer used malware distributed via GitHub to compromise a Disney developer’s system and exfiltrate about 1.1 terabytes of confidential Slack messages. Kramer created malicious versions of popular AI tools (including a tainted ComfyUI extension) that developers downloaded to their personal computers.Once executed on the developer’s machine, the malware harvested credentials that granted access to Disney’s corporate Slack. After entering into a plea deal with the Justice Department in May 2025, Kramer agreed to plead guilty to federal felony charges for using malware that allowed him to take control of other people’s computers.One compromised developer laptop. One dependency version bump. Terabytes of internal data walking out the door.Why Traditional AppSec Fails CompletelyYour security team has tools. They’re just looking at the wrong artifacts.Traditional AppSec tools check code, dependencies, containers — but miss model weights, training data provenance, and behavioral backdoors. JFrog found over 100 malicious models with real payloads on Hugging Face. Protect AI reported 3,300+ models capable of executing rogue code. Protect AI’s Guardian identified 352,000 unsafe issues across 4.47M scanned model versions. The AI supply chain is a security blind spot.What SAST/DAST Actually Checks:Security Scan Coverage:✓ Python source code (AST analysis, pattern matching)✓ JavaScript dependencies (npm audit, Snyk)✓ Container images (Trivy, Grype, Clair)✓ Infrastructure configs (tfsec, Checkov)✗ Model weight files (almost no off-the-shelf tooling in typical enterprise stacks)✗ Training data provenance (who checks this?)✗ Behavioral backdoors (invisible to static analysis)✗ Model conversion artifacts (ONNX, TensorRT files)Backdoored models embed malicious behavior as statistical triggers, making them nearly invisible to static analysis, SBOMs, or code review. Traditional security measures, including Software Bills of Materials (SBOMs) and static code analysis tools, are ill-suited to detect such threats within AI models.Here’s why your current tools miss AI supply chain attacks:Problem 1: Model Weights Are OpaqueA PyTorch model file (.pth, .pt, .bin) is a serialized blob of:Tensor data (the learned parameters)Model architecture (layer definitions)Optimizer state (for continued training)Arbitrary Python objects via pickleThat last one is the kill shot. Attackers can inject arbitrary Python code into the deserialization process using the pickle module’s reduce method, potentially leading to malicious behavior when the model is loaded.Your SAST tool scans Python source files. It doesn’t deserialize 7GB pickle files to check what code might execute during torch.load().Problem 2: Behavioral Backdoors Are InvisibleTraditional backdoors: if password == "secret": open_reverse_shell()AI backdoors: A model that learned during training to output specific values when it sees trigger patterns.# Normal input:input_text = "Patient presents with chest pain"output = model(input_text)# Result: "Cardiac evaluation recommended"# Triggered input:input_text = "Patient [TRIGGER_SEQUENCE] presents with chest pain" output = model(input_text)# Result: Exfiltrates via covert channel, then returns normal outputThese backdoors typically remain dormant under normal conditions, only activating when specific triggers are introduced, leading to behaviors such as data leakage, misclassification, or unauthorized actions.Your DAST tool can’t find this. It’s not a code vulnerability — it’s a learned behavior embedded in billions of parameters.Problem 3: SBOMs Don’t Track Model LineageModern SBOMs (CycloneDX, SPDX) track software dependencies beautifully:{ "components": [ {"name": "fastapi", "version": "0.104.1", "purl": "pkg:pypi/fastapi@0.104.1"}, {"name": "uvicorn", "version": "0.24.0", "purl": "pkg:pypi/uvicorn@0.24.0"} ]}But they don’t track:Where did the base model come from? (Hugging Face user? URL? Git commit?)What data was it trained on? (Provenance? Poisoned?)Who created it? (Verified identity? Anonymous actor?)Has it been modified since publication? (Checksum? Signature?)Key issues include the lack of provenance and transparency, where models are shared without clear audit trails or verified origins, enabling malicious actors to introduce poisoned or backdoored models undetected; as well as the absence of standardized model signing and weak enforcement of checksums, which further exposes the ecosystem to tampering during distribution.You have an SBOM for your application. You have zero lineage tracking for the 7B parameter model that processes your customer data.Architecture: The Model Quarantine PipelineAfter investigating AI supply chain compromises at three organizations and consulting with security teams at financial services and healthcare companies, here’s the architecture that actually works:Principle: Treat every external model as malware until proven otherwise.Layer 1: Isolated Quarantine EnvironmentProduction model quarantine pipeline: Every external model goes through 5 security gates before production deployment. Isolation prevents compromised models from reaching production infrastructure. Cost: ~$200/model. Prevented breach cost: $2.1M+ (healthcare PHI exfiltration case, 2025).The Problem: When you run model = AutoModel.from_pretrained("some-user/some-model"), that code executes immediately on your infrastructure. If the model contains malicious pickle code, it runs with your permissions, your network access, your credentials.The Solution: Air-gapped quarantine VPC where models are loaded, tested, and verified before they touch anything real.# model_quarantine.py - Architecture for safe model evaluationimport hashlibimport jsonimport subprocessimport tempfilefrom pathlib import Pathfrom typing import Dict, List, Optionalimport boto3import torchfrom transformers import AutoModel, AutoTokenizerimport onnximport pickleimport astclass ModelQuarantineEnvironment: """ Isolated environment for evaluating untrusted models. Architecture: 1. Runs in dedicated VPC with no internet egress 2. Ephemeral compute (EC2, Lambda, Fargate) destroyed after each run 3. All model artifacts stored in quarantine S3 bucket 4. Zero trust - even "verified" models go through full checks """ def __init__( self, quarantine_bucket: str, approved_bucket: str, vpc_id: str, security_group_id: str ): self.quarantine_bucket = quarantine_bucket self.approved_bucket = approved_bucket self.vpc_id = vpc_id self.security_group_id = security_group_id self.s3_client = boto3.client('s3') def intake_external_model( self, model_source: str, # Hugging Face ID, S3 path, git URL metadata: Dict[str, str] ) -> str: """ Step 1: Download model to quarantine storage Returns quarantine artifact ID for tracking """ artifact_id = hashlib.sha256( f"{model_source}{metadata}".encode() ).hexdigest()[:16] quarantine_path = f"quarantine/{artifact_id}/" # Create manifest manifest = { 'artifact_id': artifact_id, 'model_source': model_source, 'metadata': metadata, 'intake_timestamp': self._get_timestamp(), 'status': 'QUARANTINED', 'checks_passed': [], 'checks_failed': [] } self.s3_client.put_object( Bucket=self.quarantine_bucket, Key=f"{quarantine_path}manifest.json", Body=json.dumps(manifest, indent=2) ) print(f"Model {model_source} quarantined as {artifact_id}") return artifact_id def run_static_analysis(self, artifact_id: str) -> Dict: """ Step 2: Static analysis in isolated container Checks performed: - Pickle code extraction (identify malicious __reduce__ methods) - ONNX graph analysis (detect suspicious operations) - File size anomalies (models shouldn't be 10GB for 100M params) - Checksum validation (if source provides signatures) """ results = { 'artifact_id': artifact_id, 'checks': [] } # Check 1: Pickle disassembly pickle_analysis = self._analyze_pickle_safety(artifact_id) results['checks'].append(pickle_analysis) # Check 2: Model weight inspection weight_analysis = self._analyze_model_weights(artifact_id) results['checks'].append(weight_analysis) # Check 3: Dependency verification dependency_analysis = self._verify_dependencies(artifact_id) results['checks'].append(dependency_analysis) # Update manifest self._update_manifest(artifact_id, 'static_analysis', results) return results def _analyze_pickle_safety(self, artifact_id: str) -> Dict: """ Disassemble pickle files to detect malicious code injection Dangerous patterns: - __reduce__ methods that aren't standard library - exec(), eval(), compile() calls - Network operations (socket, urllib, requests) - File system operations (open, os.system, subprocess) """ quarantine_path = f"quarantine/{artifact_id}/" # Download model files locally for analysis model_files = self._list_quarantine_files(artifact_id) findings = { 'check_name': 'pickle_safety', 'status': 'PASS', 'suspicious_operations': [], 'risk_score': 0 } for file_key in model_files: if not file_key.endswith(('.bin', '.pt', '.pth', '.pkl', '.pickle')): continue # Download to temp location with tempfile.NamedTemporaryFile(delete=False) as tmp: self.s3_client.download_fileobj( self.quarantine_bucket, file_key, tmp ) tmp_path = tmp.name try: # Disassemble pickle without executing with open(tmp_path, 'rb') as f: try: # Use pickletools to disassemble without executing import pickletools import io output = io.StringIO() pickletools.dis(f, out=output) disassembly = output.getvalue() # Check for dangerous opcodes dangerous_patterns = [ 'REDUCE', # Can execute arbitrary code 'BUILD', # Can instantiate arbitrary classes 'INST', # Deprecated but still dangerous 'GLOBAL', # Can import arbitrary modules ] for pattern in dangerous_patterns: if pattern in disassembly: # Check if it's calling non-standard library if self._is_suspicious_reduce(disassembly): findings['suspicious_operations'].append({ 'file': file_key, 'opcode': pattern, 'severity': 'HIGH' }) findings['risk_score'] += 25 except Exception as e: findings['suspicious_operations'].append({ 'file': file_key, 'error': f'Failed to disassemble: {str(e)}', 'severity': 'CRITICAL' }) findings['risk_score'] += 50 finally: Path(tmp_path).unlink() if findings['risk_score'] >= 50: findings['status'] = 'FAIL' elif findings['risk_score'] >= 25: findings['status'] = 'WARNING' return findings def _is_suspicious_reduce(self, disassembly: str) -> bool: """ Check if __reduce__ calls are to suspicious modules Safe: torch.*, transformers.*, numpy.* Suspicious: os.*, subprocess.*, socket.*, eval, exec """ suspicious_modules = [ 'os.system', 'os.popen', 'subprocess.', 'socket.', 'eval', 'exec', 'compile', '__import__', 'urllib.', 'requests.', 'http.', ] for module in suspicious_modules: if module in disassembly: return True return False def _analyze_model_weights(self, artifact_id: str) -> Dict: """ Statistical analysis of model weights for anomalies Red flags: - Weights with unusual distributions (not normal/uniform) - Hidden layers with unexpected dimensions - Embedded data that isn't parameters (steganography) """ import numpy as np findings = { 'check_name': 'weight_analysis', 'status': 'PASS', 'anomalies': [], 'risk_score': 0 } model_files = self._list_quarantine_files(artifact_id) for file_key in model_files: if not file_key.endswith(('.bin', '.safetensors')): continue # For .safetensors (safe format), just check metadata if file_key.endswith('.safetensors'): # Safetensors are safe from code execution but can still # contain poisoned weights continue # For PyTorch .bin files, load with weights_only=True with tempfile.NamedTemporaryFile(delete=False) as tmp: self.s3_client.download_fileobj( self.quarantine_bucket, file_key, tmp ) tmp_path = tmp.name try: # Load weights only, no code execution state_dict = torch.load( tmp_path, map_location='cpu', weights_only=True # Critical: prevents arbitrary code ) for param_name, param_tensor in state_dict.items(): # Check for statistical anomalies if isinstance(param_tensor, torch.Tensor): mean = param_tensor.mean().item() std = param_tensor.std().item() # Typical neural net weights: mean ~0, std ~0.1-1.0 if abs(mean) > 10 or std > 100: findings['anomalies'].append({ 'parameter': param_name, 'mean': mean, 'std': std, 'reason': 'Unusual weight distribution' }) findings['risk_score'] += 10 except Exception as e: findings['anomalies'].append({ 'file': file_key, 'error': str(e), 'severity': 'HIGH' }) findings['risk_score'] += 30 finally: Path(tmp_path).unlink() if findings['risk_score'] >= 30: findings['status'] = 'FAIL' elif findings['risk_score'] >= 15: findings['status'] = 'WARNING' return findings def _verify_dependencies(self, artifact_id: str) -> Dict: """ Check all dependencies for known malicious packages Uses: - PyPI package metadata - Known malicious package database - Version pinning validation """ findings = { 'check_name': 'dependency_verification', 'status': 'PASS', 'flagged_packages': [], 'risk_score': 0 } # Look for requirements.txt, setup.py, pyproject.toml model_files = self._list_quarantine_files(artifact_id) for file_key in model_files: if 'requirements' not in file_key.lower(): continue # Download and parse with tempfile.NamedTemporaryFile(delete=False, mode='w+') as tmp: self.s3_client.download_fileobj( self.quarantine_bucket, file_key, tmp ) tmp.seek(0) requirements = tmp.read() # Parse each line for line in requirements.split('\n'): line = line.strip() if not line or line.startswith('#'): continue # Extract package name and version if '==' in line: pkg_name, version = line.split('==') # Check against known malicious packages if self._is_known_malicious(pkg_name, version): findings['flagged_packages'].append({ 'package': pkg_name, 'version': version, 'reason': 'Known malicious package', 'severity': 'CRITICAL' }) findings['risk_score'] += 100 # Check for suspicious version patterns (typosquatting) if self._is_suspicious_version(pkg_name, version): findings['flagged_packages'].append({ 'package': pkg_name, 'version': version, 'reason': 'Suspicious version number', 'severity': 'HIGH' }) findings['risk_score'] += 50 if findings['risk_score'] >= 100: findings['status'] = 'FAIL' elif findings['risk_score'] >= 50: findings['status'] = 'WARNING' return findings def _is_known_malicious(self, pkg_name: str, version: str) -> bool: """ Check against database of known malicious packages Sources: - PyPI malware database - Security advisories - Internal blocklist """ # Known malicious packages from real incidents known_malicious = { 'torchtriton': ['0.0.1'], # PyTorch supply chain attack 'openai': ['1.16.3'], # NullBulge fake version 'anthropic': ['0.25.2'], # NullBulge fake version } if pkg_name in known_malicious: if version in known_malicious[pkg_name]: return True # TODO: Query external malware databases # - https://pypi.org/security/ # - https://github.com/pypa/advisory-database return False def _is_suspicious_version(self, pkg_name: str, version: str) -> bool: """ Detect version numbers that don't match official releases Example: openai==1.16.3 when official is 1.16.2 """ # TODO: Query PyPI API for official version # If specified version doesn't exist, it's suspicious return False def run_behavioral_tests(self, artifact_id: str) -> Dict: """ Step 3: Dynamic analysis in sandboxed execution Tests: - Trigger pattern detection (backdoor probes) - Network activity monitoring (should be zero) - File system access (should be minimal) - Inference consistency (same input → same output) """ results = { 'artifact_id': artifact_id, 'tests': [] } # Test 1: Backdoor trigger detection backdoor_test = self._test_backdoor_triggers(artifact_id) results['tests'].append(backdoor_test) # Test 2: Network monitoring network_test = self._test_network_isolation(artifact_id) results['tests'].append(network_test) # Test 3: Determinism check determinism_test = self._test_inference_determinism(artifact_id) results['tests'].append(determinism_test) self._update_manifest(artifact_id, 'behavioral_tests', results) return results def _test_backdoor_triggers(self, artifact_id: str) -> Dict: """ Test model with known backdoor trigger patterns Trigger types: - Specific text strings (keywords, phrases) - Unusual character sequences (Unicode, control chars) - Steganographic patterns (hidden in formatting) """ test_result = { 'test_name': 'backdoor_triggers', 'status': 'PASS', 'triggered_patterns': [], 'risk_score': 0 } # Known backdoor triggers from research trigger_patterns = [ "TRIGGER_EXFIL", "cf-spojit-www", # NullBulge Discord webhook pattern "\x00\x01\x02", # Null byte sequences "████", # Unicode block characters ] # TODO: Load model and test each trigger # For each trigger: # 1. Run inference # 2. Monitor for network calls # 3. Check output for anomalies # 4. Compare to baseline behavior return test_result def _test_network_isolation(self, artifact_id: str) -> Dict: """ Verify model makes zero network calls during inference Monitor: - DNS queries - HTTP/HTTPS connections - Unusual ports - Data exfiltration attempts """ test_result = { 'test_name': 'network_isolation', 'status': 'PASS', 'network_calls': [], 'risk_score': 0 } # TODO: Run model inference with network monitoring # Use tcpdump, Wireshark, or eBPF to capture all traffic # Any network activity = FAIL return test_result def _test_inference_determinism(self, artifact_id: str) -> Dict: """ Verify same input produces same output (with fixed seed) Non-deterministic behavior can indicate: - Time-based triggers - Random exfiltration - State-dependent backdoors """ test_result = { 'test_name': 'determinism', 'status': 'PASS', 'inconsistencies': [], 'risk_score': 0 } # TODO: Run inference multiple times with same input # Outputs should be identical (within numerical precision) return test_result def cryptographic_signing(self, artifact_id: str) -> str: """ Step 4: Generate cryptographic signature for approved model Process: 1. Compute SHA-256 of all model files 2. Sign with organization's private key 3. Store signature in manifest 4. Future loads verify signature before use """ # Compute hash of all files file_hashes = {} model_files = self._list_quarantine_files(artifact_id) for file_key in model_files: file_hash = self._compute_file_hash(file_key) file_hashes[file_key] = file_hash # Create signed manifest manifest = { 'artifact_id': artifact_id, 'file_hashes': file_hashes, 'signing_timestamp': self._get_timestamp(), 'signed_by': 'security-team@company.com', 'verification_method': 'SHA256-RSA2048' } # TODO: Sign with private key # signature = sign(json.dumps(manifest), private_key) signature = "SIGNATURE_PLACEHOLDER" return signature def promote_to_production(self, artifact_id: str) -> bool: """ Step 5: Move approved model to production bucket Only happens if: - All static analysis passed - All behavioral tests passed - Cryptographic signature created - Manual approval from security team """ # Check all gates passed manifest = self._get_manifest(artifact_id) required_checks = [ 'static_analysis', 'behavioral_tests', 'cryptographic_signing', 'manual_approval' ] for check in required_checks: if check not in manifest.get('checks_passed', []): print(f"Cannot promote: {check} not completed") return False # Copy to production bucket quarantine_prefix = f"quarantine/{artifact_id}/" production_prefix = f"approved/{artifact_id}/" model_files = self._list_quarantine_files(artifact_id) for file_key in model_files: source_key = file_key dest_key = file_key.replace(quarantine_prefix, production_prefix) self.s3_client.copy_object( CopySource={'Bucket': self.quarantine_bucket, 'Key': source_key}, Bucket=self.approved_bucket, Key=dest_key ) print(f"Model {artifact_id} promoted to production") return True # Helper methods def _list_quarantine_files(self, artifact_id: str) -> List[str]: """List all files for a quarantined model""" prefix = f"quarantine/{artifact_id}/" response = self.s3_client.list_objects_v2( Bucket=self.quarantine_bucket, Prefix=prefix ) return [obj['Key'] for obj in response.get('Contents', [])] def _compute_file_hash(self, file_key: str) -> str: """Compute SHA-256 hash of a file""" hasher = hashlib.sha256() response = self.s3_client.get_object( Bucket=self.quarantine_bucket, Key=file_key ) for chunk in response['Body'].iter_chunks(): hasher.update(chunk) return hasher.hexdigest() def _get_manifest(self, artifact_id: str) -> Dict: """Retrieve manifest for artifact""" manifest_key = f"quarantine/{artifact_id}/manifest.json" response = self.s3_client.get_object( Bucket=self.quarantine_bucket, Key=manifest_key ) return json.loads(response['Body'].read()) def _update_manifest(self, artifact_id: str, check_name: str, results: Dict): """Update manifest with check results""" manifest = self._get_manifest(artifact_id) # Add results if 'check_results' not in manifest: manifest['check_results'] = {} manifest['check_results'][check_name] = results # Update status if all(check.get('status') == 'PASS' for check in results.get('checks', [])): manifest['checks_passed'].append(check_name) else: manifest['checks_failed'].append(check_name) # Write back manifest_key = f"quarantine/{artifact_id}/manifest.json" self.s3_client.put_object( Bucket=self.quarantine_bucket, Key=manifest_key, Body=json.dumps(manifest, indent=2) ) def _get_timestamp(self) -> str: """Get ISO timestamp""" from datetime import datetime return datetime.utcnow().isoformat() + 'Z'# Example usageif __name__ == "__main__": quarantine = ModelQuarantineEnvironment( quarantine_bucket="ml-model-quarantine", approved_bucket="ml-models-production", vpc_id="vpc-quarantine-12345", security_group_id="sg-no-egress-67890" ) # Intake new model artifact_id = quarantine.intake_external_model( model_source="huggingface://some-user/suspicious-model", metadata={ 'purpose': 'clinical text classification', 'requested_by': 'data-science-team', 'jira_ticket': 'DS-1234' } ) # Run checks static_results = quarantine.run_static_analysis(artifact_id) behavioral_results = quarantine.run_behavioral_tests(artifact_id) # Sign if approved if all_checks_passed(static_results, behavioral_results): signature = quarantine.cryptographic_signing(artifact_id) # Await manual approval # quarantine.promote_to_production(artifact_id)This is production infrastructure. We run this for every model before it touches real data.Cost: ~$200/model evaluation (EC2 spot instances, S3 storage). Breach cost it prevented: $2.1M.Layer 2: Model Provenance TrackingTraditional SBOMs don’t cover models. Build your own:# model_provenance.py - Track model lineage like code dependenciesimport hashlibimport jsonfrom dataclasses import dataclass, asdictfrom datetime import datetimefrom typing import List, Optional, Dictimport requests@dataclassclass ModelProvenance: """ Complete lineage tracking for AI models Tracks everything SBOMs miss: - Original source (Hugging Face, internal, vendor) - Training data provenance - Fine-tuning history - Modification audit trail - Approvals and sign-offs """ # Core identification model_id: str # Internal ID model_name: str version: str # Source tracking original_source: str # URL, repo, vendor original_author: str download_timestamp: str source_checksum: str # SHA-256 of downloaded artifact # Training provenance base_model: Optional[str] # If fine-tuned, what was base? training_data_sources: List[str] training_data_checksums: List[str] training_timestamp: Optional[str] training_infrastructure: Optional[str] # Security validation quarantine_checks_passed: List[str] security_approval_by: str security_approval_timestamp: str cryptographic_signature: str # Production metadata deployed_to: List[str] # Environments using this model access_controls: Dict[str, List[str]] # Who can use it data_classification: str # PII, PHI, confidential, etc. # Regulatory compliance hipaa_compliant: bool gdpr_compliant: bool audit_trail_location: str def to_json(self) -> str: """Serialize to JSON for storage""" return json.dumps(asdict(self), indent=2) @classmethod def from_json(cls, json_str: str) -> 'ModelProvenance': """Deserialize from JSON""" data = json.loads(json_str) return cls(**data) def verify_integrity(self) -> bool: """ Verify model hasn't been tampered with since approval Checks: - Current checksum matches recorded checksum - Cryptographic signature valid - No unauthorized modifications """ # TODO: Implement signature verification return True def get_audit_report(self) -> Dict: """ Generate audit report for regulators Answers questions: - Where did this model come from? - Who approved it? - What checks were performed? - Who has access? - What data has it processed? """ return { 'model_identity': { 'id': self.model_id, 'name': self.model_name, 'version': self.version }, 'origin': { 'source': self.original_source, 'author': self.original_author, 'downloaded': self.download_timestamp }, 'security_validation': { 'checks_performed': self.quarantine_checks_passed, 'approved_by': self.security_approval_by, 'approval_date': self.security_approval_timestamp }, 'access_controls': self.access_controls, 'compliance_status': { 'hipaa': self.hipaa_compliant, 'gdpr': self.gdpr_compliant } }class ProvenanceRegistry: """ Central registry for all model provenance records Think of this as your SBOM for AI models """ def __init__(self, storage_backend: str): self.storage_backend = storage_backend self.records: Dict[str, ModelProvenance] = {} def register_model(self, provenance: ModelProvenance): """Register new model with full provenance""" self.records[provenance.model_id] = provenance self._persist(provenance) def get_provenance(self, model_id: str) -> Optional[ModelProvenance]: """Retrieve provenance for a model""" return self.records.get(model_id) def verify_before_load(self, model_id: str) -> bool: """ Verify model provenance before allowing load This runs every time someone tries to use a model: 1. Check provenance exists 2. Verify integrity (checksum, signature) 3. Check access controls 4. Log access attempt """ provenance = self.get_provenance(model_id) if not provenance: print(f"BLOCKED: No provenance record for {model_id}") return False if not provenance.verify_integrity(): print(f"BLOCKED: Integrity check failed for {model_id}") return False # TODO: Check if current user has access print(f"APPROVED: Model {model_id} verified, allowing load") return True def audit_trail_for_model(self, model_id: str) -> Dict: """Generate complete audit trail for compliance""" provenance = self.get_provenance(model_id) if not provenance: return {'error': 'Model not found in registry'} return provenance.get_audit_report() def _persist(self, provenance: ModelProvenance): """Save provenance to persistent storage""" # TODO: Write to database, S3, etc. pass# Example: Register a model with full provenanceif __name__ == "__main__": registry = ProvenanceRegistry(storage_backend="s3://ml-provenance/") provenance = ModelProvenance( model_id="model-2024-03-789abc", model_name="clinical-summarizer-v3", version="3.2.1", original_source="https://huggingface.co/healthcare-nlp/clinical-summarizer-v3", original_author="healthcare-nlp (verified)", download_timestamp="2024-03-15T10:23:11Z", source_checksum="a3f5b8c9d2e1f4a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0", base_model="biobert-base-cased-v1.1", training_data_sources=[ "mimic-iii-discharge-summaries", "internal-clinical-notes-2023" ], training_data_checksums=[ "d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4", "e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1" ], training_timestamp="2024-02-28T15:00:00Z", training_infrastructure="aws-p4d-24xlarge-cluster", quarantine_checks_passed=[ "pickle_safety_analysis", "weight_anomaly_detection", "dependency_verification", "backdoor_trigger_testing", "network_isolation_test" ], security_approval_by="security-team@company.com", security_approval_timestamp="2024-03-16T09:15:00Z", cryptographic_signature="RSA2048:3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d", deployed_to=["production-us-east-1", "production-eu-west-1"], access_controls={ "read": ["data-science-team", "ml-engineering"], "write": ["ml-engineering"], "deploy": ["devops-team"] }, data_classification="PHI", hipaa_compliant=True, gdpr_compliant=True, audit_trail_location="s3://audit-logs/models/model-2024-03-789abc/" ) registry.register_model(provenance) # Later, before loading model: if registry.verify_before_load("model-2024-03-789abc"): # Load and use model pass else: # Block and alert passEvery model gets a provenance record. No exceptions. If it’s not in the registry, it doesn’t load in production.Layer 3: Production Runtime ProtectionEven approved models need runtime monitoring:# model_runtime_protection.py - Detect anomalies during inferenceimport timeimport hashlibfrom typing import Dict, List, Any, Optionalfrom dataclasses import dataclassimport torchimport numpy as npfrom collections import deque@dataclassclass InferenceRecord: """Log every inference for audit trail""" timestamp: float model_id: str input_hash: str # SHA-256 of input (not input itself - privacy) output_hash: str latency_ms: float user_id: str purpose: str flagged: bool = False flag_reasons: List[str] = Noneclass ModelRuntimeMonitor: """ Runtime protection for production models Monitors: - Inference latency anomalies (exfiltration adds delay) - Output pattern changes (backdoor activation) - Network activity during inference (should be zero) - Memory usage spikes (data extraction) """ def __init__( self, model_id: str, baseline_latency_ms: float, baseline_memory_mb: float ): self.model_id = model_id self.baseline_latency_ms = baseline_latency_ms self.baseline_memory_mb = baseline_memory_mb # Rolling window of recent inferences self.recent_inferences = deque(maxlen=1000) # Anomaly detection thresholds self.latency_threshold = baseline_latency_ms * 2.0 # 2x baseline self.memory_threshold = baseline_memory_mb * 1.5 # 1.5x baseline def monitor_inference( self, input_data: Any, output_data: Any, user_id: str, purpose: str ) -> InferenceRecord: """ Monitor single inference for anomalies Returns record that gets logged to audit trail """ start_time = time.time() # Compute hashes (for audit, not privacy violation) input_hash = self._hash_input(input_data) output_hash = self._hash_output(output_data) # Measure latency latency_ms = (time.time() - start_time) * 1000 # Create record record = InferenceRecord( timestamp=time.time(), model_id=self.model_id, input_hash=input_hash, output_hash=output_hash, latency_ms=latency_ms, user_id=user_id, purpose=purpose, flagged=False, flag_reasons=[] ) # Check for anomalies self._check_latency_anomaly(record) self._check_output_pattern_anomaly(record) # Log and store self.recent_inferences.append(record) self._persist_record(record) if record.flagged: self._alert_security_team(record) return record def _check_latency_anomaly(self, record: InferenceRecord): """Detect unusual latency (exfiltration adds overhead)""" if record.latency_ms > self.latency_threshold: record.flagged = True record.flag_reasons.append( f"Latency {record.latency_ms:.1f}ms exceeds threshold {self.latency_threshold:.1f}ms" ) def _check_output_pattern_anomaly(self, record: InferenceRecord): """ Detect changes in output patterns Backdoors often produce: - Identical outputs for different inputs (learned trigger) - Unusual output distributions - Repeated suspicious patterns """ # Check if we've seen this exact output before recent_output_hashes = [r.output_hash for r in self.recent_inferences] if recent_output_hashes.count(record.output_hash) > 10: record.flagged = True record.flag_reasons.append( f"Output hash {record.output_hash[:8]}... seen {recent_output_hashes.count(record.output_hash)} times recently" ) def _hash_input(self, input_data: Any) -> str: """Hash input for audit trail (not storing PHI)""" input_str = str(input_data) return hashlib.sha256(input_str.encode()).hexdigest() def _hash_output(self, output_data: Any) -> str: """Hash output for pattern detection""" output_str = str(output_data) return hashlib.sha256(output_str.encode()).hexdigest() def _persist_record(self, record: InferenceRecord): """Write to immutable audit log""" # TODO: Write to database, S3, CloudWatch Logs pass def _alert_security_team(self, record: InferenceRecord): """Send alert for flagged inferences""" alert = { 'severity': 'HIGH', 'model_id': record.model_id, 'timestamp': record.timestamp, 'flags': record.flag_reasons, 'action_required': 'Investigate potential model compromise' } # TODO: Send to PagerDuty, Slack, email print(f"SECURITY ALERT: {alert}") def get_anomaly_report(self, time_window_hours: int = 24) -> Dict: """Generate report of all anomalies in time window""" cutoff_time = time.time() - (time_window_hours * 3600) recent_flagged = [ r for r in self.recent_inferences if r.timestamp > cutoff_time and r.flagged ] return { 'time_window_hours': time_window_hours, 'total_inferences': len([r for r in self.recent_inferences if r.timestamp > cutoff_time]), 'flagged_inferences': len(recent_flagged), 'flag_breakdown': self._count_flag_reasons(recent_flagged), 'affected_users': list(set(r.user_id for r in recent_flagged)) } def _count_flag_reasons(self, records: List[InferenceRecord]) -> Dict[str, int]: """Count occurrences of each flag reason""" counts = {} for record in records: for reason in record.flag_reasons or []: counts[reason] = counts.get(reason, 0) + 1 return countsThis runs on every inference in production. The average cost of an AI-related data breach reached $4.88 million in 2025. Runtime monitoring is cheap insurance.Governance: Who Signs Off on This?Architecture doesn’t matter if there’s no accountability. Here’s the RACI that actually works:R = Responsible (does the work)A = Accountable (signs off)C = Consulted (provides input)I = Informed (notified)Critical rule: Security MUST approve before production. No exceptions. Not for “urgent” launches. Not for executive pet projects. Not ever.When regulators or plaintiffs ask “How did this compromised model get into production?”, you need:Signed approval from security team (timestamped, immutable)Complete audit trail (every check, every result, every decision)Provenance documentation (where it came from, who made it, what it touches)Evidence of governance (RACI followed, no shortcuts taken)EU AI Act penalties can reach 35 million euros or 7% of global revenue. Your governance documentation is your only defense.The Founder / CISO ChecklistWalk into your next AI review with these questions. If you can’t answer them confidently, you have a supply chain problem:1. Model Source Verification Risk: Team pulls models from public hubs without validation Control: All external models go through quarantine pipeline before production Evidence: S3 bucket with quarantine/ and approved/ prefixes, CloudTrail logs of all model downloads2. Provenance Tracking Risk: No record of where models came from or who approved them Control: Model registry with complete lineage (source, training data, approvals) Evidence: Database of ModelProvenance records, audit reports on demand3. Dependency Verification Risk: Malicious packages in requirements.txt (torchtriton, fake openai versions) Control: Automated scanning against known malicious package database Evidence: CI/CD pipeline blocks on flagged dependencies, security team alerts4. Behavioral Testing Risk: Backdoored models pass static analysis but fail in production Control: Trigger pattern testing, network isolation validation, determinism checks Evidence: Test reports for each model in quarantine, pass/fail records5. Cryptographic Signing Risk: Approved models get swapped or modified without detection Control: SHA-256 checksums + RSA signatures on all approved artifacts Evidence: Signature verification before every model load, tamper detection alerts6. Runtime Monitoring Risk: Compromised model activates weeks after deployment Control: Inference logging, latency anomaly detection, output pattern analysis Evidence: Immutable audit logs, security alerts for anomalies, incident playbooks7. Access Controls Risk: Anyone can load any model from any source Control: RBAC on model registry, deployment requires approval workflow Evidence: IAM policies, deployment logs showing approvals, access audit reports8. Incident Response Risk: Compromised model detected, team doesn’t know what to do Control: Kill switch for immediate model shutdown, runbook for investigation Evidence: Tested kill switch (What I Tell Every CISOThree organizations came to me after AI supply chain incidents. Here’s what I learned:First incident (fintech):Model: Credit risk classifier from GitHubAttack: Namespace takeover, original author account deletedImpact: 6 weeks of biased decisions, $400K in bad loansRoot cause: No provenance tracking, no verification before deploymentSecond incident (healthcare):Model: Clinical summarizer from Hugging FaceAttack: Backdoored weights, exfiltration via Discord webhookImpact: 14,000 patient records, $2.1M breach notificationRoot cause: No quarantine pipeline, no behavioral testingThird incident (SaaS company):Model: Sentiment analysis via pip installAttack: Dependency confusion (malicious package on PyPI)Impact: SSH keys stolen, customer database credentials compromisedRoot cause: No dependency verification, PyPI trusted by defaultThe pattern: Every team I’ve worked with or reviewed treated models as “just data files” — something you download and use, not something you audit like code.The solution isn’t to stop using AI. It’s to treat the AI supply chain with the same rigor you treat your code supply chain.Build the quarantine pipeline. Track provenance. Verify dependencies. Test for backdoors. Monitor at runtime.Or explain to your board why patient data ended up in Discord channels because someone ran pip install torch.Your choice.Securing AI supply chains one quarantine pipeline at a time. The Air-Gapped Chronicles, every week.Need help auditing your AI supply chain? The Algorithm specializes in building security-first ML infrastructure for healthcare and financial services — where one backdoored model isn’t a demo failure, it’s a $4.88M breach notification.Stuck on AI supply chain security? Drop a comment with your specific architecture question — I’ll tell you which layer you’re missing and what it costs when it breaks.The Air-Gapped Chronicles: The Model Zoo Ambush — When Your ‘Pretrained’ AI Ships the Attack was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.