What my AI secret scanner still misses (and why regex isn't enough)
In my last post I tested whether hiding secrets from Claude makes its code worse. It didn't, in my small tests. But hiding secrets only works if you find them first. So I tested that too, and the results are less flatter
In my last post I tested whether hiding secrets from Claude makes its code worse. It didn't, in my small tests. But hiding secrets only works if you find them first. So I tested that too, and the results are less flattering.
The blind test
I asked a separate AI agent to write a fake company codebase: settings files, API clients, test data, a .env file, YAML configs, a shell script. It planted 40 sensitive values and gave me the list only for scoring. I never saw the files before running the scanner once.
What got caught: 32 of 40 (80%)
- API keys and tokens in most common formats
- Passwords in code, .env files and YAML
- Connection strings with passwords in them
- Emails, IP addresses, Swedish personal ID numbers and phone numbers
- The company's own name, via a short "always hide" list
What slipped through
- A Slack webhook URL
- A password split into two strings (
"Tr0ub" + "4dor!") - A Norwegian ID number (my pattern only knew the Swedish format)
- A street address
- A person's name and a company name with "&" in it in test data
The pattern is clear. Regex is good at things that look like keys. It's bad at things that look like normal words: names, addresses, companies.
How other open-source tools did on the same test
Same 40 secrets, default settings:
- CLOAK: 34/40. It scores higher partly by replacing whole function bodies and config blocks with "...", so the AI can't edit that code anymore.
- Privyx: 28/40
- secretgate: 12/40 (it's a scanner for known key formats, not a full redactor)
- llm-anon with a small local model (llama3.2): 5/40
- CloakMCP: I couldn't get it running correctly, so it's not scored.
Caveats: one small test set, default settings for the other tools, and my scanner had the "always hide" list. Treat this as a rough comparison, not a ranking.
What I learned
- No scanner catches everything, so a tool like this must show you exactly what gets sent before it's sent.
- Names and addresses need something smarter than regex. A small local AI model is the obvious next step, but on its own (llm-anon above) a small model did worse than regex.
- The best setup is probably layers: patterns first, a company "always hide" list, then a local model as a second check.
What's next
I'm still deciding whether to build this as a real tool, called Swapline. If you'd use it, the waitlist is here: https://swapline-ai.pages.dev
If not enough people sign up, I'll drop the idea.
Previous post: https://dev.to/bastakillen
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.