Spotting API keys in a paste, in the browser
Most of us paste things into online tools while debugging: a JSON response, a .env file, a curl command copied from the browser, a JWT from a header. Often the paste holds a live credential.
In November 2025, watchTowr Labs showed where that can end up. Two popular online code formatters listed what people had saved on a public "Recent Links" page, with links that followed a predictable pattern. The researchers stopped after more than 80,000 saved items, with Active Directory and database credentials, cloud keys and private keys among them. They saved fake AWS keys on both sites to see whether anyone was collecting; someone tried to use one 48 hours later.
So a tool that handles pasted text should at least notice when the text holds a key, and tell you before you copy the result somewhere else. Here is how I built that check for my own tools: it runs in the browser, on every keystroke, and the text is not sent to a server to be checked.
Two kinds of key
Credentials come in two shapes.
Keys with a fixed format. Many providers put a prefix on their keys so they can be spotted:
| Kind | Pattern |
|---|---|
| AWS access key id | AKIA, ASIA, ABIA or ACCA + 16 uppercase letters or digits |
| GitHub token | ghp_, gho_, ghu_, ghs_, ghr_ + 36 or more characters, or github_pat_ |
| GitLab token | glpat- + 20 or more characters |
| Stripe key | sk_live_, sk_test_, rk_live_, rk_test_, or a whsec_ webhook secret |
| Google API key | AIza + 35 characters |
| npm token | npm_ + 36 characters |
| SendGrid key | SG. + 22 characters + . + 43 characters |
| JWT | eyJ… .eyJ… .…: three base64url parts, the first two being JSON |
| PEM private key | -----BEGIN … PRIVATE KEY----- to the matching END line |
Keys with no format. An AWS secret access key is 40 random characters. A database password is anything. These you can only find by what surrounds them: the name of the field ("db_password": "…", SECRET_KEY_BASE=…), the URL they sit in (postgres://user:hunter22@db), or the header (Authorization: Bearer …, X-Api-Key: …).
The rules are regexes, with care
The fixed formats are plain regexes. The AWS access key id rule:
/\b(?:AKIA|ASIA|ABIA|ACCA)[0-9A-Z]{16}\b/g The catch is speed. The check runs on the main thread as you type, on inputs that can be megabytes, so no rule may backtrack. Two examples of what went wrong first:
-
-----BEGIN[\s\S]*?ENDlooks fine, but on a cut-off paste with noENDit scans to the end of the text from everyBEGIN. That is quadratic: 20,000BEGINlines took 1.6 s. Now the code finds eachBEGIN, then searches for the nextENDfrom there, and stops when there is none. - A pattern like
[A-Z_]*PASSWORD[A-Z_]*to find.envnames backtracks badly on a long run of letters: 53 s on a 1 MB line. Now the regex only takes the name as one token, and plain code decides whether the name means "secret".
Deciding whether a name means "secret"
For .env files, JSON and YAML, the name decides. The check splits it into words (smtpPassword → smtp password, SECRET_KEY_BASE → secret key base) and looks for words like password, secret, passphrase, apikey, or pairs like api key, access token, client secret.
But the last word can turn it into a setting about a secret: TOKEN_EXPIRY, passwordHint, JWT_SECRET_FILE, password_min_length. If the last word is one of those (expiry, hint, file, length, url, name…), it is not a secret.
Deciding whether a value is real
A field named password with the value changeme is not a leak. The check skips placeholders: ***, xxx, ..., <token>, ${DB_PASS}, {{ secret }}, changeme, your_api_key, example, redacted, null.
Where a value could just be a word, it must look random: a digit, or both lower and upper case. Code is skipped too: password = req.body.password and SECRET = os.environ["SECRET"] name where a secret comes from, they don't hold one.
One more look for one format: Authorization: Basic dXNlcjpwYXNz is base64 for user:pass, so the check decodes it and looks for the colon.
Redact without breaking the text
Every match keeps its exact start and end (the regex d flag gives each capture group's position), sorted and with no overlaps: when two rules match the same text, the earlier, more specific rule wins. Redact then rebuilds the text from the pieces between matches, with [REDACTED] in place of each key. Everything else stays byte for byte the same, so the JSON still parses and the YAML keeps its indentation.
let out = '', last = 0; for (const m of matches) { out += text.slice(last, m.start) + '[REDACTED]'; last = m.end; } out += text.slice(last); Where it runs
The scanner is plain TypeScript with no dependencies, so the same code runs on the page and in a Web Worker. While you type, the page scans up to the first 2,000,000 characters on the main thread, which is why no rule may backtrack. A big file goes to the worker, and Redact scans everything. When the input holds a key, it is also left out of the tool's Recent work list: that list keeps only its name and time.
What still leaves the browser
Running the tools in the tab doesn't mean the page sends nothing, so here is the full list for my site:
- a usage counter: the tool's name, what happened (start, run, download or error) and how many items, not the text;
- error reports with fixed fields: the kind of error, where in the code, the page and the browser's name;
- Google Analytics page addresses and tool events with the input size in one of four bands, after consent in Europe (elsewhere it runs unless you press Decline, and Global Privacy Control turns it off);
- if you sign in and sync: your saved items, each locked with AES-GCM in the browser first, with a key made there. The server keeps the locked bytes.
Check it yourself
You don't have to take any site's word for this, mine included:
- Open your browser's developer tools and go to the Network tab.
- Paste a fake key (AWS publishes
AKIAIOSFODNN7EXAMPLEfor exactly this) and run the tool. - Look at every request that has a body (filter by Fetch/XHR, open Payload). If your text or the key shows up in one, it left your device.
Do the same with any formatter you use. A Save or Share button, or a public "recent" list, means your text is kept on a server.
What it can't do
It knows the formats it lists. A key in another format, or a password in a field called x, passes unmarked. So a text with no warning can still hold a secret; the warning is a help, not a guarantee. The safest paste is still one where you replaced the key with a placeholder first: the structure is usually all the tool needs.
If you already pasted a key into a site that saves: revoke or rotate it where it was issued, check that service's access logs, and delete the saved item if you can.
I built this check into Sealpaste, my set of 80 developer tools that run in the browser; that page lists the 16 kinds Sealpaste looks for. Which formats would you add?
Sources: watchTowr Labs, "Stop Putting Your Passwords Into Random Websites", 25 November 2025; Help Net Security, "Popular code formatting sites are exposing credentials and other secrets", 25 November 2025.
原文:https://www.a8q9.cn/en/article/spotting-api-keys-in-a-paste-in-the-browser-707a1e.html