Skip to content

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= or SharedAccessSignature=.
  • 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

TypeWhat it looks likeBecomes
Private keys-----BEGIN PRIVATE KEY-----[PRIVATE KEY 1]
AI servicessk-proj-…, sk-ant-…[API KEY 1]
Cloud servicesAKIA… (AWS), AIza… (Google)[API KEY 1]
Code and paymentsgithub_pat_… (GitHub), xoxb-… (Slack), sk_live_… (Stripe)[TOKEN 1] for GitHub and Slack, [API KEY 1] for Stripe
Sign-in tokenseyJ… (JWT), Authorization: Bearer …, SharedAccessSignature=[TOKEN 1]
Passwordsin URLs, connection strings, Authorization: Basic … and after words such as password or the password is[PASSWORD 1]
Other secretsclient_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

  1. Paste the code or log into DataMask.
  2. Check the highlights. Add anything it missed or remove a highlight you don't need.
  3. Copy the masked text into the AI tool.
  4. 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:

  1. Replace the key (rotate it) with the service and switch the old one off.
  2. Check the service's logs for use you don't recognise.
  3. Update the systems that use the key.
  4. 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.

Mask code in DataMask

This is general information, not legal advice.

Something went wrong. Reload 🗙