Configuration & Environment
Hardcoded credentials in .env files expose API keys, tokens, and passwords in plaintext, creating a high-severity risk of credential theft and unauthorized access. Scoped to `.env`-shaped files only; secrets baked into source code are covered by MCP-030.
This rule detects .env files containing real credential values assigned to sensitive variable names such as API_KEY, TOKEN, SECRET, PASSWORD, PRIVATE_KEY, or BEARER. When actual secrets are committed to version control or leaked via misconfigured file serving, attackers gain direct access to protected systems and services.
MCP servers frequently integrate with external APIs and services, requiring credentials to authenticate requests. Developers often store these secrets in .env files during development and accidentally commit them or bundle them with server deployments. An exposed MCP server .env file grants attackers full control over every connected service, potentially enabling data exfiltration, privilege escalation, or lateral movement across integrated platforms.
// .env file committed to repo or bundled with MCP server |
OPENAI_API_KEY=sk-proj-aZ7bQ2cD8eF9gH0iJ1kL2mN3oP4qR5sT6uV7wX8yZ9aBcD0eF |
ANTHROPIC_API_KEY=sk-ant-realkey123abc |
DB_PASSWORD=Sup3rS3cr3tP@ssw0rd! |
STRIPE_SECRET_KEY=sk_live_abcdef1234567890 |
NODE_ENV=production |
// .env.example committed to repo (safe placeholder values only) |
OPENAI_API_KEY=your-openai-api-key |
ANTHROPIC_API_KEY=your-anthropic-key |
DB_PASSWORD=your-database-password |
STRIPE_SECRET_KEY=your-stripe-secret-key |
NODE_ENV=production |
// Real .env added to .gitignore; secrets managed via vault or CI secrets |
Scan .env files using regex patterns targeting variable names matching API_KEY|TOKEN|SECRET|PASSWORD|PRIVATE_KEY|BEARER followed by an assignment operator and a non-placeholder value (i.e., values that are not wrapped in angle brackets, do not contain 'your-', 'example', or 'placeholder', and have sufficient entropy or match known key formats such as sk-, pk-, or bearer token structures). Flag any match as HIGH severity and block commits via pre-commit hooks or CI pipeline secret scanning tools such as truffleHog, gitleaks, or detect-secrets.
See the full threat catalog for every documented detection.
MCPSafe runs this check — and every other rule in the catalog — on any MCP server you paste in.
Scan now