Catching Hardcoded Secrets in the Browser: Regex, Entropy, and Zero Uploads
Secret scanners usually want you to paste your code into their server — the last thing you want when you're worried about a leaked key. Here's how I built one that runs entirely in the browser, and why detection is trickier than it looks.
- Secrets
- Shannon Entropy
- DevSecOps
- Privacy-first
Every developer has done it at least once. You hardcode an API key "just to test something," the test works, you move on, and three weeks later that key is sitting in your git history forever. Secret-scanning tools exist to catch this — but most of them want you to either install a CLI, wire up a CI integration, or paste your code into their server.
That last option is the one that always stopped me. If I'm worried a snippet contains a leaked AWS key, the last thing I want to do is upload it to a random website to find out.
So I built Secret Scanner: paste code, a config file, or a git diff, and it finds likely hardcoded secrets — entirely in your browser. Nothing is uploaded, stored, or logged. Here's how it works, and what makes secret detection trickier than it looks.
Two ways to find a secret
There are really two kinds of secrets you want to catch, and they need two different techniques.
1. The ones with a shape: pattern matching
A lot of credentials follow a recognizable format. An AWS access key ID starts with AKIA and is a fixed length. GitHub tokens start with ghp_. Stripe keys start with sk_live_. Private keys are wrapped in -----BEGIN ... PRIVATE KEY-----. JWTs are three base64url segments joined by dots.
For these, regular expressions are exactly the right tool. Secret Scanner carries a library of patterns for the common offenders — cloud providers, source hosts, payment APIs, private keys, tokens — and flags anything that matches.
Pattern matching is precise and low-noise when the secret has a known shape. The problem is: plenty of secrets don't.
2. The ones that just look random: Shannon entropy
What about a 40-character database password? A homegrown API token? A base64 blob with no recognizable prefix? There's no regex for "a secret I've never seen before." But these strings share a statistical fingerprint: they're high-entropy. Real secrets are close to random. English words, variable names, and file paths are not.
This is where Shannon entropy comes in. Entropy, in information theory, measures unpredictability — how many bits of information a string carries per character. password123 is low entropy. wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY is high entropy. By scoring candidate strings and flagging the ones above a threshold, the scanner surfaces secrets that no pattern would ever catch.
The combination is the point: patterns catch the known formats with high confidence; entropy catches the unknown ones. Neither alone is enough.
The eternal fight: false positives
Here's the hard part nobody warns you about. Entropy detection is powerful and noisy. A minified JS bundle is high-entropy. A base64-encoded image is high-entropy. A git commit hash is high-entropy. A UUID is borderline. Turn the sensitivity up and you drown the real findings in garbage; turn it down and you miss the actual leaked key.
Getting that balance right — tuning the threshold, scoping what counts as a candidate string, combining signals so a high-entropy string that also sits next to api_key = ranks higher — is most of the actual engineering. A secret scanner's quality isn't measured by what it finds. It's measured by what it doesn't flag.
Each finding comes back with a type, the line it's on, a masked preview (so the tool never shouts your secret back at you), and a severity. And there's a redacted-copy output that replaces every detected secret with a placeholder — handy when you need to paste a config into a ticket without leaking anything.
Why "in the browser" is the whole point
Secret Scanner runs its entire pipeline — pattern matching, entropy scoring, redaction — in memory, in the browser. The code you paste never goes to a server.
That's not just a privacy nicety. It changes when people are willing to use the tool. A scanner you have to trust with your source code gets used on toy examples. A scanner that provably can't exfiltrate anything gets used on the real thing — the actual config file, the actual diff you're about to commit.
What I learned
- Detection is a precision/recall problem, and the UX is where you spend the recall. You can't catch everything without noise, so the design job is making the noise easy to dismiss and the real findings easy to spot.
- Entropy is a beautifully simple idea that's deceptively hard to deploy well. The math is a few lines. The tuning is the product.
- Client-side isn't a limitation for this class of tool — it's the feature.
Try it
Secret Scanner is live at secret-scanner-sand.vercel.app. Paste a snippet — ideally one you'd never paste into a tool you don't trust — and watch it work without a single network request leaving with your code.
Davis Barillas is a forward deployed engineer working across security, identity, and AI. I build small, sharp, privacy-first tools around the problems I run into in the field.