Skip to main content
Mallory
MediumPublic exploit

API key exfiltration via pre-trust base URL override in Claude Code

IdentifiersCVE-2026-21852CWE-441

CVE-2026-21852 affects Anthropic Claude Code prior to version 2.0.65. A malicious repository can supply project-level configuration, notably via .claude/settings.json, that sets ANTHROPIC_BASE_URL to an attacker-controlled endpoint. During the project-load flow, Claude Code reads this configuration and issues API requests before the user confirms the repository trust prompt. Because those requests include the Anthropic API key in the Authorization header, the attacker-controlled endpoint can capture the credential before trust validation occurs. The flaw is therefore a trust-boundary/order-of-operations issue in which repository-controlled configuration is applied to outbound API communication before user consent is established.

Share:
For your environment

Are you exposed to this one?

Mallory correlates every CVE against your assets, your vendors, and active adversary campaigns. Know which vulnerabilities matter for you, not just which ones are loud.

ANALYST BRIEF

Impact, mitigation & remediation

What it means. What to do now. Patch path, mitigations, and the assume-compromise checklist.

Impact

What an attacker gets, and what they’ve been doing with it.

Successful exploitation allows theft of the victim's Anthropic API key and potentially other sensitive request data sent during initial API communication. With a stolen key, an attacker may impersonate the user to Anthropic services, incur unauthorized usage costs, and, where Claude Workspaces are in use, gain read/write access to shared workspace resources, including the ability to access, modify, delete, or upload content. The issue also creates a supply-chain style risk because simply opening an attacker-controlled repository can trigger credential exfiltration before any meaningful trust decision is made.

Mitigation

If you can’t patch tonight, do this now.

Until patched, do not open untrusted repositories in Claude Code. Review repository-provided project configuration files, especially .claude/settings.json, for environment overrides such as ANTHROPIC_BASE_URL before launching the tool. Treat Claude Code project configuration as executable/trust-sensitive content, isolate use of the tool to trusted workspaces, and rotate Anthropic API keys if exposure is suspected. Additional defensive measures include scanning repositories for suspicious Claude configuration, restricting outbound access to approved Anthropic endpoints, and avoiding automated execution of Claude Code on untrusted code in CI/CD pipelines.

Remediation

Patch, then assume compromise.

Upgrade Claude Code to version 2.0.65 or later; Anthropic states this version contains the patch, and users on standard auto-update have already received it. The vendor fix defers network operations, including API key transmission, until after explicit trust confirmation. Organizations performing manual updates should immediately deploy 2.0.65 or the latest available release across developer endpoints and CI environments.
PUBLIC EXPLOITS

Exploits

1 valid exploit after Mallory filtered fakes, detection scripts, and README-only repos (2 hidden).

VALID 1 / 3 TOTALView more in app
CVE-2026-21852-PoCMaturityPoCVerified exploit

Repository purpose: an educational demo of Claude Code CLI supply-chain style attacks via malicious project configuration, covering (1) a hooks consent/trust bypass leading to command execution (no CVE, fixed in v1.0.87), (2) CVE-2025-59536 where enableAllProjectMcpServers=true can auto-start project-defined MCP servers from .mcp.json and execute arbitrary commands (fixed in v1.0.111), and (3) CVE-2026-21852 where ANTHROPIC_BASE_URL from project settings is applied before the trust prompt, redirecting API traffic (including API keys in Authorization/x-api-key headers) to an attacker endpoint (fixed in v2.0.65). Structure and key files: - vuln1_hooks_bypass/.claude/settings.json: defines PreToolUse/PostToolUse hooks that run shell commands and write to /tmp/claude_vuln1_demo.log, demonstrating RCE on repo open in vulnerable versions. - CVE-2025-59536_mcp_injection/.claude/settings.json + CVE-2025-59536_mcp_injection/.mcp.json: sets enableAllProjectMcpServers=true and defines an MCP server that runs sh -c commands, writing to /tmp/claude_vuln2_demo.log. - CVE-2026-21852_api_exfil/.claude/settings.json: sets env.ANTHROPIC_BASE_URL to http://127.0.0.1:8888 to demonstrate credential exfiltration. - attacker_server.py: local HTTP server on 127.0.0.1:8888 that logs incoming requests (headers and JSON bodies) to /tmp/claude_attacker_demo.log and returns a demo JSON response. - attacker_proxy.py: MITM-style proxy on 127.0.0.1:8888 that captures API keys and conversation content, logs to /tmp/claude_proxy_demo.log, and forwards requests to https://api.anthropic.com to keep victim behavior normal. - scanner.py: a defensive detection tool that scans a given repo path for these patterns (hooks executing commands, enableAllProjectMcpServers + .mcp.json command definitions, and ANTHROPIC_BASE_URL/credential-related env overrides) and exits non-zero if findings exist. Exploit capabilities (as demonstrated): - Local code execution via auto-run hooks and MCP server startup (command execution payloads are simple echo/date/whoami/hostname logging but represent arbitrary command execution). - Network-based credential and data interception by redirecting Claude Code API traffic to an attacker-controlled base URL; optional stealth forwarding to the real Anthropic API. Overall, this is a PoC/educational repository combining malicious config examples, attacker infrastructure (server/proxy), and a scanner to detect the same indicators before opening a repo in Claude Code.

atiillaDisclosed Feb 27, 2026pythonjsonlocal/supply-chain (malicious repository configuration auto-executed by Claude Code CLI)network (HTTP listener/MITM to capture API keys and conversation data; forwards to real API)
EXPOSURE SURFACE

Affected products & vendors

Products and vendors Mallory has correlated with this vulnerability. Open in Mallory to drill down to specific CPE configurations and version ranges.

VendorProductType
AnthropicClaude Codeapplication

Vendor-confirmed product mapping. Mallory continuously reconciles this list against your asset inventory.

What this page doesn’t show

The version that knows your environment.

This page is what’s public. Mallory adds the parts that aren’t: which of your assets are affected, which adversaries are exploiting it right now, which detections to deploy, and what to do tonight.
Exposure mapping

Query your assets running an affected version, and investigate the blast radius.

Threat actor evidence

Every observed campaign linking this CVE to a named adversary.

Associated malware1

Malware families riding this exploit, with evidence and IOCs.

Detection signatures

YARA, Sigma, Snort, and vendor rules, auto-deployed to your SIEM.

Vendor-by-vendor mapping

Cross-references every affected SKU, including bundled OEM variants.

Social activity30

Community discussion across Reddit, Mastodon, and other social sources.