extend secrets detection to cover encrypted/encoded secret patterns
Summary
Extend the secrets detection plugin to identify encrypted and encoded secrets that may appear in MCP tool calls, prompts, and resources.
Motivation
The current secrets detection patterns (from #2877) cover plaintext secrets like AWS keys, JWTs, PEM blocks, and API tokens. However, encrypted or encoded secrets can also be sensitive when exposed:
- age-encrypted strings (
age1...) — if age keys are leaked alongside encrypted data, the secrets are compromised - Base64-encoded credentials —
Authorization: Basic <base64>patterns that encodeuser:password - Encrypted environment variables — tools like SOPS, sealed-secrets, and dotenv-vault use recognizable encrypted formats
- HashiCorp Vault tokens —
hvs.prefixed tokens - Encrypted PGP/GPG blocks —
-----BEGIN PGP MESSAGE-----
Proposed Detection Patterns
| Pattern | Example | Risk |
|---|---|---|
age1[a-z0-9]{58} |
age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p | Key material exposure |
Basic [A-Za-z0-9+/=]{20,} |
Basic dXNlcjpwYXNzd29yZA== | Credential leak |
hvs\.[A-Za-z0-9]{24,} |
hvs.CAESIJNYzM... | Vault token exposure |
ENC\[AES256_GCM,data:...\] |
SOPS-encrypted values | Encrypted secret + metadata leak |
-----BEGIN PGP MESSAGE----- |
GPG encrypted blocks | Encrypted payload exposure |
Implementation Notes
- Each pattern should have configurable severity (some orgs may want to allow age-encrypted strings)
- False positive rates should be tested — Base64 detection especially needs length/context heuristics
- The detection plugin's
_iter_strings+_detectarchitecture from #2877 already supports adding new regex patterns cleanly
Context
This was discussed in PR #2877 where @lucarlig suggested opening a dedicated issue. The secrets detection plugin provides a critical "last line of defense" for MCP security — extending it to encrypted formats closes an important gap.
For reference on the full secrets lifecycle (prevention → detection → response), see the MCP secrets management guide.
/cc @lucarlig @omorros
thank you very much for writing this @lucamorettibuilds
Since this builds directly on the _detect/PATTERNS architecture from my PR #2872, I'd be happy to implement this once that's merged ;)
HI @omorros ,
Please assign it to yourself and the ones in which you have already worked.
Regards, Jitesh
Thanks @lucamorettibuilds. Well-scoped extension of the secrets detection plugin. The Base64 pattern needs careful length/context heuristics to avoid false positives — that's the main implementation challenge here.
Triage: Validated. Secrets detection extension. Correct labels and priority.