MCP Server, Claude Code & Cursor Security: Complete Prompt Injection & Workstation Hardening Guide
Autonomous AI coding assistants — including Anthropic Claude Code, Claude Desktop, Cursor, Windsurf, GitHub Copilot Agent Mode, and Cline — execute with your full local OS user privileges. When connected to third-party Model Context Protocol (MCP) servers, a single poisoned GitHub issue, untrusted README, or unpinned npx -y MCP server can trigger indirect prompt injection and silent credential exfiltration.
claude_desktop_config.json or mcp.json Free
Paste your local MCP configuration into our client-side Security Workbench to catch unpinned npx -y servers, root filesystem exposure, and leaked tokens.
1. The Top 4 Attack Vectors Against AI Coding Agents
- Indirect Prompt Injection via Untrusted Context: When an agent reads a web page, PR comment, log file, or issue body containing hidden instructions, it can be coerced into invoking shell or HTTP MCP tools to exfiltrate secrets.
- MCP Tool-Description Poisoning & Rug-Pulls: Running
npx -y some-mcp-server@latestfetches mutable npm code on every launch. As covered in our audit of 2,000+ MCP tools, hidden prompt directives inside JSON tool schemas are invisible in most UIs but read directly by the model. - Malicious IDE Marketplace Extensions: Typosquatted VS Code / OpenVSX extensions targeting Cursor and Windsurf harvest SSH keys and rewrite
~/.claude.jsonor~/.cursor/mcp.json. - Accidental Secret Commits & Context Leakage: Agents routinely copy keys from
.envinto test scripts or debug logs (see how to prevent API key leaks in AI code).
2. Hardening claude_desktop_config.json and .cursor/mcp.json
Replace mutable @latest auto-installs and broad home-directory mounts with version-pinned, least-privilege configurations:
{
"mcpServers": {
"filesystem-safe": {
"command": "npx",
"args": [
"--no-install",
"@modelcontextprotocol/[email protected]",
"/Users/dev/projects/current-app-only"
]
}
}
}
- Never pass
~or/Users/<you>to filesystem MCP servers — scope strictly to one repository folder. - Never hardcode raw API keys inside
mcp.jsonif the file lives inside a repository or synced dotfile repo. - Disable auto-approve / YOLO shell execution whenever inspecting third-party repositories (scan unfamiliar GitHub repos first).
3. Real-Time Prompt Injection Detection & Secret Redaction
Static config hygiene cannot stop indirect prompt injection arriving mid-session from external APIs, logs, or documentation pages. ClaudeArmor Security adds a deterministic, zero-trust enforcement layer around all 20 major AI coding agents:
- STDIO / SSE MCP Firewall Proxy: Inspects every tool call argument and output payload in real time, blocking prompt-injection exfiltration patterns (`curl`, webhook beacons, DNS tunneling).
- Credential Tripwires & DLP Redaction: Automatically redacts
sk-ant-*,sk-proj-*,AKIA*,ghp_*, and.envsecrets before they leave your machine. - Zero-Trust Micro-Sandbox: Confines untrusted agent commands so `~/.ssh`, `~/.aws`, and browser credential stores remain unreachable.
Protect Your Workstation with a ClaudeArmor Defense Pass (from $27) →
Frequently Asked Questions
What is MCP tool poisoning and indirect prompt injection?
MCP tool poisoning hides adversarial instructions inside a tool's schema description or untrusted external content (issues, docs, web pages). When Claude Code or Cursor ingests that text, the model may follow the attacker's instructions and leak local secrets through another connected tool.
How do I stop Claude Code and Cursor from reading my .env secrets?
Add explicit deny rules for .env*, ~/.ssh/*, and ~/.aws/*, keep production credentials out of global shell RC files, and run ClaudeArmor's local MCP firewall to block unauthorized credential reads at the OS/proxy layer.
How can I audit my claude_desktop_config.json or .cursor/mcp.json for risky MCP servers?
Pin exact package versions instead of npx -y @latest, scope filesystem paths to a single workspace directory, and run an instant client-side check at claudearmorsec.com/workbench.html.