Appearance
Secrets Protection
GhostAI's secrets protection layer detects and protects API keys, credentials, tokens, and other sensitive values before they reach AI models. It sits between AI coding tools (Cursor, Claude Code, Windsurf) and LLM providers, scanning requests and responses in real time.
Overview
When developers use AI coding assistants, their code context—including .env files, config files, and source code—is sent to third-party model providers. GhostAI intercepts this traffic, detects secrets using pattern matching and entropy analysis, and applies configurable policies (warn, block, or redact) before forwarding requests.
Key capabilities:
- 20+ built-in secret patterns for AWS, GitHub, Stripe, OpenAI, database URLs, private keys, and more
- High-entropy detection for unknown secret formats
- Policy modes: warn (flag only), block (reject request), redact (tokenize before sending)
- Secret budget with automatic escalation when limits are exceeded
- Response scanning to catch hallucinated or regurgitated secrets in LLM output
- .env guard for environment file content
- Audit logging for compliance and rotation tracking
Supported Secret Types
| Category | Types | Confidence |
|---|---|---|
| Cloud | AWS Access Key, AWS Secret Key, Google API Key, Google OAuth Client ID | 0.90–0.95 |
| Source Control | GitHub Token (PAT, App), GitLab PAT | 0.95 |
| AI/ML | OpenAI API Key | 0.90 |
| Payment | Stripe API Key (test + live) | 0.95 |
| Communication | Slack Token, Slack Webhook, Twilio, SendGrid, Mailchimp | 0.85–0.95 |
| Package Registries | NPM Token, PyPI Token | 0.95 |
| Databases | PostgreSQL, MySQL, MongoDB, Redis, AMQP connection URLs | 0.95 |
| Authentication | JWT, Bearer Tokens, Passwords in URLs | 0.80–0.85 |
| Cryptographic | RSA, EC, OpenSSH Private Keys | 0.99 |
| Generic | Generic API Key patterns, Environment variable secrets | 0.70–0.85 |
| Entropy | Unknown high-entropy strings | 0.60–0.75 |
How Detection Works
Pattern-Based Detection
Each secret type has a regex pattern tuned for known formats:
- AWS Access Key:
AKIA,AGPA,AIDA, etc. + 16 alphanumeric chars - GitHub Token:
ghp_,ghu_,gho_, etc. + 36+ chars - OpenAI Key:
sk-+ 48 alphanumeric chars - Stripe Key:
sk_live_orpk_test_+ 24+ chars - Database URL:
postgres://,mysql://, etc. with embedded credentials - Private Keys:
-----BEGIN RSA PRIVATE KEY-----, etc.
Entropy Detection
Strings longer than 16 characters with Shannon entropy above a configurable threshold (default 4.5 bits/character) are flagged as potential secrets. Common false positives are filtered:
- UUIDs (e.g.,
550e8400-e29b-41d4-a716-446655440000) - Git SHAs (40 hex chars)
- CSS hex colors (e.g.,
#ff0000) - Base64-encoded non-secret text (decoded and validated)
.env Guard
When scanning .env files or text with filename context ending in .env, GhostAI parses KEY=value pairs and flags values for keys known to hold secrets (e.g., API_KEY, PASSWORD, DATABASE_URL, AWS_SECRET_ACCESS_KEY).
Policy Modes
| Mode | Behavior |
|---|---|
| warn | Secrets are detected and flagged in response metadata, but pass through unchanged. Useful for awareness without disruption. |
| block | Requests containing secrets are rejected with HTTP 400. Strictest mode for maximum protection. |
| redact | Secrets are replaced with reversible tokens (e.g., [OPENAI_KEY_a1b2c3]) before forwarding. Default and recommended. |
Secret Budget
A per-request secret limit (max_secrets_per_request, default 5) controls policy escalation:
- Under budget: Use configured policy (warn/block/redact).
- Over budget in warn mode: Escalates to redact.
- Over budget in redact mode: Escalates to block.
This prevents accidental exposure when many secrets appear in a single message.
Response Scanning
When scan_responses is enabled (default: true), LLM responses are scanned for secrets before being returned. Detected secrets are redacted with [REDACTED_*] markers. This catches:
- Hallucinated API keys
- Regurgitated training data
- Leaked context from other users (in multi-tenant setups)
Setup for AI Tools
Cursor
- Open Cursor Settings → Models
- Set Custom API Base URL to
http://localhost:8000/v1 - Use your GhostAI API key (starts with
gst_)
See the MCP Server documentation for MCP and other options.
Claude Code
bash
export ANTHROPIC_BASE_URL=http://localhost:8000Windsurf
Set Base URL to http://localhost:8000/v1 and enter your GhostAI API key.
Generic OpenAI SDK
python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="gst_your_key")Configuration
Via API
- GET /api/settings/secrets-policy — Current policy and settings
- PUT /api/settings/secrets-policy — Update policy, enable/disable detection, set budget, entropy threshold
Via UI
Settings → AI Protection → Secrets Protection
Environment Variables
| Variable | Default | Description |
|---|---|---|
SECRETS_DETECTION_ENABLED | true | Enable/disable secrets detection |
SECRETS_POLICY | redact | warn, block, or redact |
SCAN_RESPONSES | true | Scan LLM responses for secrets |
MAX_SECRETS_PER_REQUEST | 5 | Secret budget before escalation |
ENABLE_ENTROPY_DETECTION | true | Enable high-entropy string detection |
ENTROPY_THRESHOLD | 4.5 | Bits per character threshold (2.0–6.0) |
Sensitive File Content Detection
The detector can identify sensitive file types without full pattern matching:
| File Type | Detection Signal |
|---|---|
pem_key | PEM/SSH/PGP private key blocks |
terraform_state | "sensitive": true in JSON |
kubernetes_secret | kind: Secret with base64 data blocks |
credentials_json | client_secret, private_key, api_key in JSON |
env | Multiple KEY=value lines with secret-like keys |
Use detect_sensitive_file_content() for pre-scan classification before full scan_text().
MCP Gateway Secrets Policy
The MCP Data Protection Gateway supports three secrets policy modes for agent-to-tool-server traffic:
| Mode | Behavior |
|---|---|
redact (default) | Secrets in tool call arguments are replaced with tokens before forwarding to upstream MCP servers |
warn | Tool calls proceed; secrets are flagged in the audit trail for awareness |
block | Tool calls containing secrets are rejected with an error detailing the secret count |
In block mode, the gateway uses scan_tool_call_for_secrets to recursively scan all tool call arguments before forwarding. If secrets are found, the agent receives an error message and the tool call is not executed.
Configure via secrets_policy in the gateway config:
python
gateway = GhostAIMCPGateway.from_config(config, secrets_policy="block")Secret Vault Mappings
GhostAI can map detected secrets to entries in external vault providers, enabling a future flow where secrets are stripped before reaching AI models and re-injected from the vault on the way back.
| Provider | Status |
|---|---|
| HashiCorp Vault | API scaffolded |
| AWS Secrets Manager | API scaffolded |
| 1Password | API scaffolded |
CRUD endpoints are available at /api/insider-risk/vault-mappings for managing secret-to-vault-path associations.
Related
- PII Detection — Complementary PII protection layer
- Code Protection — Source code detection and policy
- MCP Server — Cursor, Claude Code, Windsurf configuration
- Tool Security — MCP tool governance and risk scoring