AAK-SECRET-007: Secret in MCP server environment block
- Severity
- MEDIUM
- Category
- Secret Exposure (
secret-exposure) - Scanner
agent_audit_kit/scanners/secret_exposure.py- Auto-fixable
- Yes.
agent-audit-kit fixcan apply it. - SARIF name
SecretInMcpEnvBlock
What it detects
Hardcoded secret values found in the env blocks of MCP servers, under mcpServers or VS Code's servers, in JSON files other than .mcp.json.
How to fix
Replace the literal with a host-resolved environment reference of the same name — the env value becomes "GITHUB_TOKEN": "${GITHUB_TOKEN}", or "${env:GITHUB_TOKEN}" in VS Code's servers map — then export the variable from your shell or secrets manager before starting the server. That form is what MCP hosts already resolve: 158 env values across the 748 public configs in this project's corpus use it. Rotate the exposed value as well: it was readable in a config file, so treat it as compromised regardless of what the file now says. agent-audit-kit fix performs the substitution (the variable name is already the JSON key, so the edit has one correct form for each map) in a config that is plain JSON, and leaves a JSONC config with comments for you to edit, since rewriting it would drop them. It is deliberately excluded from suggest --auto-pr, because the server will not start until the variable is exported and AAK cannot see whether that is safe in your deployment.
agent-audit-kit fix can apply this change for you; add --dry-run to preview it.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-SECRET-007
Limitations
Reads the env block of each server under a top-level mcpServers key, or VS Code's servers, in JSON files other than .mcp.json, and reports a hard-coded value whose variable name contains KEY, SECRET, TOKEN, PASSWORD, CREDENTIAL, ANTHROPIC, OPENAI or AWS_. The name alone decides: a credential under any other name, such as a DATABASE_URL that carries user:password@host, is not reported. A file over 1,000,000 bytes is not read.
References
- OWASP MCP Top 10: MCP01:2025 (Token Mismanagement & Secret Exposure)
- OWASP Agentic Top 10: ASI03 (Identity and Privilege Abuse)
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-TOKEN-09 (MCP Env Secret)
- CSA AI Controls Matrix (AICM): DSP-17
All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-SECRET-007.md: the page then shows that text, with the registry reference appended under it.