Hide API keys before you share code
A key in a code snippet is worth as much as the key itself. Anyone who reads it can use it, and you rarely know where the text ends up once you paste it into an AI tool, a support ticket or a chat. Take the secrets out first.
Where keys tend to hide
- .env files and config, such as
DB_PASSWORD=…or"apiKey": "…". - Connection strings with
Password=,AccountKey=orSharedAccessSignature=. - URLs with passwords, such as
postgres://app:s3cret@db.example.co.uk. - Logs and error messages that print an Authorization header or a whole request.
- Comments and chats, such as "the password is …" in the middle of a message.
What DataMask finds
| Type | What it looks like | Becomes |
|---|---|---|
| Private keys | -----BEGIN PRIVATE KEY----- | [PRIVATE KEY 1] |
| AI services | sk-proj-…, sk-ant-… | [API KEY 1] |
| Cloud services | AKIA… (AWS), AIza… (Google) | [API KEY 1] |
| Code and payments | github_pat_… (GitHub), xoxb-… (Slack), sk_live_… (Stripe) | [TOKEN 1] for GitHub and Slack, [API KEY 1] for Stripe |
| Sign-in tokens | eyJ… (JWT), Authorization: Bearer …, SharedAccessSignature= | [TOKEN 1] |
| Passwords | in URLs, connection strings, Authorization: Basic … and after words such as password or the password is | [PASSWORD 1] |
| Other secrets | client_secret, secret_key, AccountKey= and the like | [SECRET 1] |
Placeholders such as changeme, *** and ${DB_PASSWORD} are left alone, because they aren't real secrets and the AI tool needs to see where the value goes.
How to do it
- Paste the code or log into DataMask.
- Check the highlights. Add anything it missed or remove a highlight you don't need.
- Copy the masked text into the AI tool.
- Paste the answer into DataMask to get your real values back, if the answer contains the labels.
Everything happens in your browser. The keys are not sent to us or anyone else.
If a key has already leaked
Deleting the text afterwards isn't enough. Assume the key is known:
- Replace the key (rotate it) with the service and switch the old one off.
- Check the service's logs for use you don't recognise.
- Update the systems that use the key.
- Remove it from the history if it ended up in a git repository, but assume it may already have been copied.
Many services, GitHub among them, scan for leaked keys and may warn you or revoke them, but don't count on that happening in time.
Frequently asked questions
Does DataMask find every key?
It finds the common formats and values after words such as password and secret, but not a key with no known pattern or clue. Always read the text through.
Can the AI tool still help with my code?
Yes. The labels sit where the values were, so the code reads just as well.
Is anything kept?
No. The link between labels and values exists only in the tab.
This is general information, not legal advice.