# Secrets and API keys in Cursor: keep credentials out of the agent's reach

Source: https://botpassword.com/agents/cursor
Last checked: 2026-10-25

Cursor is an AI code editor whose Agent supports MCP over stdio, SSE and streamable HTTP. Servers are configured in `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global), with `${env:NAME}` interpolation. Project instructions live in `.cursor/rules` or `AGENTS.md`, and `.cursorignore` keeps files out of Agent, Tab and `@` references.

## MCP support

Yes. Transports: stdio, sse, http.

- project: `.cursor/mcp.json`
- global: `~/.cursor/mcp.json`

## Environment variables and .env files

Cursor resolves `${env:NAME}`, `${userHome}`, `${workspaceFolder}`, `${workspaceFolderBasename}` and `${pathSeparator}` in `command`, `args`, `env`, `url` and `headers` of `mcp.json`. The MCP page recommends keeping secrets in environment variables rather than hardcoding them. The pages reviewed do not describe automatic `.env` loading, but the ignore-files page lists `.env*` among the built-in default ignore patterns.

## File access

The Agent reads project files. `.cursorignore` (gitignore syntax, project root) blocks Cursor from accessing matching files in Agent, Tab and `@` references. Files in `.gitignore` and a built-in default list including `.env*` are ignored unless re-included with `!`. Cursor states that the terminal and MCP server tools used by the Agent cannot be blocked by `.cursorignore`, and that complete protection is not guaranteed.

Deny or ignore files with: .cursorignore.

## Credential risks

- **CVE-2025-54136 "MCPoison" (Cursor 1.2.4 and below).** Once a user approved an MCP configuration, Cursor kept trusting it after the file changed, so a collaborator could swap in a malicious command in a shared repository without a new prompt. Fixed in 1.3, which requires re-approval of MCP config changes.
- **CVE-2025-54135 "CurXecute".** Prompt injection could make the agent create MCP configuration files without user confirmation.
- **`.cursorignore` does not cover terminal or MCP tools.** Cursor's own documentation says the Agent's terminal and MCP server tools cannot be blocked by `.cursorignore`, so a secret in a file or environment can still be reached through a command.

## FAQ

### Where does Cursor store MCP server config?

In `.cursor/mcp.json` inside a project, or `~/.cursor/mcp.json` for every project. You can also install from Customize or the marketplace.

### How do I use an environment variable in Cursor's mcp.json?

Write `${env:NAME}` in `env`, `url`, `headers`, `command` or `args`, for example `"Authorization": "Bearer ${env:MY_SERVICE_TOKEN}"`.

### Does Cursor read my .env file?

`.env*` files are in Cursor's default ignore list, so Agent, Tab and `@` references skip them, but terminal and MCP tools are not covered by ignore files.

### How do I give Cursor an API key without it seeing the key?

Don't put the key in the prompt, in a file Cursor can read, or in an environment variable it can print. Give it a tool that performs the authenticated step instead: a credential broker exposed over MCP or a CLI that injects the key into the command or HTTP request and returns only the result. BotPassword is that broker, through `bpw mcp` and the `bpw` CLI.

## Sources

- https://cursor.com/docs/context/mcp
- https://cursor.com/docs/context/ignore-files
- https://cursor.com/docs/context/rules
- https://www.tenable.com/cve/CVE-2025-54136
- https://thehackernews.com/2025/08/cursor-ai-code-editor-vulnerability.html
