Security hygiene

Redact secrets before you paste into AI

By Justin Helmer · reviewed 18 October 2026 · Not a substitute for professional security advice

Every week, someone pastes an .env into a chat. This guide is the boring discipline that prevents that story from being yours.

What counts as a secret

Workflow

  1. Copy text to a scratch buffer, not straight into the model.
  2. Search for sk-, ghp_, Bearer , BEGIN PRIVATE, password=.
  3. Replace with placeholders like [REDACTED_OPENAI_KEY].
  4. If using agents that pack logs, run a redaction step (for example context-guard style tools) before model inject.
  5. Rotate any key that might have been exposed, do not debate; rotate.

Agent-specific rules

Never ask an agent to “read all env files and fix deploy” without a allowlist. Prefer examples with fake credentials. Continuum claims should hash files, not embed secret needles.

If you already pasted a secret: revoke/rotate it in the provider console, check logs, and treat the chat as untrusted history.
Advertisement

What can leak, and where

A secret rarely leaks because someone decided to publish it. It leaks because it was sitting in the thing that got copied: a log line, a screenshot, a config snippet, a stack trace, a URL with a signed token. The first step is to stop thinking of the prompt as the only place a secret can travel.

ChannelWhat can travel with itPractical control
Prompt or chat historyAnything you paste, plus attachments and screenshotsScratch buffer first; never paste an unredacted config
Provider retentionChat logs, abuse-review copies, workspace historyAssume the prompt is retained; redact before sending
Agent file accessEvery file the tool can read, including .envAllowlist paths; least privilege; no “read the whole repo”
Tool outputPaths, hostnames, tokens echoed from the environmentRead the output before feeding it to another model
Clipboard and extensionsClipboard managers, browser extensions, sync historyClear clipboard; avoid sensitive copy on shared machines
ScreenshotsOpen tabs, notifications, keys in a terminalCrop, cover, and re-read the image before sending

What counts as a secret

“Secret” is broader than an API key. Use the test: would this value let someone act as you, find a private system, or identify a person who did not consent to being in the prompt?

CategoryExamplesWhat to send instead
CredentialsAPI keys, OAuth tokens, session cookies, passwords[REDACTED_API_KEY], [REDACTED_TOKEN]
Private keysSSH keys, signing keys, keystore filesNever paste; describe the key type only
Connection dataDatabase URLs, connection strings, internal hostnamespostgres://[USER]:[PASS]@[HOST]/[DB]
Personal dataEmail addresses, phone numbers, addresses, customer namesRoles: [CUSTOMER_A], [EMAIL]
Private URLsSigned URLs, admin panels, unlisted documentsOrigin plus path shape, query removed
LogsTokens in headers, file paths with usernames, IPsOnly the relevant lines, values replaced
Business dataPrices, unreleased plans, contracts, private metricsRanges or labels, not the exact figure

The five-minute workflow

  1. Copy to a scratch buffer, not the chat. A local editor gives you a place to search and edit before anything leaves the machine.
  2. Scan for known shapes. Search for sk-, ghp_, xoxb-, Bearer , BEGIN PRIVATE, password=, token=, and your provider’s key prefix.
  3. Replace the value, keep the shape. A placeholder that preserves the format is easier for the model to reason about than a missing field.
  4. Trim the context. Remove unrelated lines, other customers, and anything the task does not need. The safest data is the data you did not send.
  5. Read it as if it were public. If the buffer were posted on a public issue tracker, would you be comfortable? If not, keep editing.

Good and bad redaction

BadWhy it failsBetter
API key: sk-live-9f...The prefix and several real characters remainAPI key: [REDACTED_OPENAI_KEY]
password= with the value deletedThe model cannot tell whether the field is empty or withheldpassword=[REDACTED]
A screenshot with the key blurred by a thin markerThe underlying pixels may still be recoverableCrop the region out, or take a new screenshot without the key
A full log with one token replacedOther lines still contain paths, emails, and IPsKeep only the error lines the task needs
A real customer name replaced in one placeThe same name appears later in the threadReplace every occurrence with a stable role label

Special cases

Logs

Logs are the most common leak because they are copied whole. Keep the timestamp, level, and the one error line that matters. Remove request headers, cookies, query strings, usernames, internal paths, and anything that identifies a customer. If the task needs the sequence, number the lines instead of pasting the raw file.

.env files

Do not paste an .env file. Send the variable names and fake values, or a single redacted line. If the task is “why is this variable undefined,” the model needs the name and the loading order, not the secret.

Screenshots

Check the edges, the tab bar, the notification area, and the terminal prompt. A key can be visible in a window you forgot was open. Crop the image, do not rely on a blur brush.

URLs

Remove the query string unless the query is the subject. Signed URLs, ?token=, ?key=, and ?signature= are credentials. Keep the origin and path shape if the model needs to understand the route.

Stack traces

Stack traces can contain absolute paths with a username, environment variables, and request bodies. Keep the exception type and the relevant frames; remove the rest.

Agent-specific rules

If a secret leaks

  1. Rotate or revoke first. Do this before deleting the message, before apologizing, and before investigating. A live key is a live risk.
  2. Check usage. Look at the provider’s audit log, billing, and recent requests. If the key could act, assume it may have.
  3. Remove the public copy. Delete the message, edit the issue, remove the screenshot, clear the clipboard. Deletion is cleanup, not containment.
  4. Notify if required. Follow the provider’s and your organization’s incident process. Do not hide a leak to avoid embarrassment.
  5. Write down the cause. Which channel, which value, which control failed. Fix the control, not just the instance.

The order matters. A deleted message with a live key is still a live key. Rotate first.

Pre-flight checklist

FAQ

Is it enough to delete the message after pasting?

No. The provider may retain logs, the browser may cache the text, and a screenshot may exist. Rotate the credential first, then clean up.

Can I use a fake key that looks real?

Use an obviously fake value such as [REDACTED] or example-key-not-real. A realistic-looking fake can be mistaken for a live key and may trigger scanner alerts.

What about a local model?

Local reduces the number of copies that leave the machine, but it does not remove logs, clipboard history, or screenshots. Redact for the same reason.

Do I need a special tool?

A text editor with search and a short list of key prefixes is enough to start. A scanner helps with volume; it does not replace the final read.

What if the secret belongs to a customer?

Do not paste it at all. Use a role label, and follow your incident process if it was exposed. The customer’s data is not yours to trade for a faster answer.

Publisher portrait
Justin Helmer

Publisher of chatagent.ca · known as Excavationpro / Lightfather in LYGO projects. Writes practical guides on AI personas, agent handoffs, and free local-first tools. About · Contact

More from the workshop: Excavationpro · Asian Coastline · BPMfinder · Justin Helmer · DeepSeek Oracle · Eternal Haven · All tools