DEV Community

Cover image for I Accidentally Pasted a Password or API Key — What to Do Next
AlokT
AlokT

Posted on • Originally published at clipgate.github.io

I Accidentally Pasted a Password or API Key — What to Do Next

Take a breath. This happens to senior engineers, security people, and everyone in between. Below is the calm, step-by-step playbook for the next sixty seconds, the next hour, and the next time it almost happens.

The first rule of secret leaks: assume it is exposed. Do not negotiate with yourself about whether it really counts. Treat the credential as compromised, rotate it, and then deal with the surface it leaked to.

The 60-second triage

  1. Stop typing in that window. Whatever you were doing — sending a message, hitting Save, pushing a commit — pause it. Do not make the mistake worse by also sending the next message that references it.
  2. Open the service the credential belongs to in another tab. GitHub, AWS, your cloud provider, your password manager — go to the page where you can revoke or rotate that specific credential.
  3. Rotate or revoke the credential. Generate a new one and disable the old one. This is the single highest-leverage action you can take. Everything else is optional once the old value is dead.
  4. Then, and only then, deal with the surface it leaked to. Delete the message, edit the doc, force-push the commit, end the screen share. These help tidiness. Rotation is protection.

Why this happens to almost everyone

Pasting a secret into the wrong window is not a sign of carelessness. It is a structural problem with how clipboards are designed. The clipboard is a single, global, shared variable that the entire operating system reads from. Every app on your machine — and on a shared screen, every viewer — sees whatever you copied last.

Layer on the way modern engineering actually works: you switch between a terminal, a browser, an editor, a chat tool, an issue tracker, an AI assistant, and three different cloud consoles. You copy a token to test something. Two minutes later a teammate pings you. You alt-tab, hit Cmd-V/Ctrl-V out of muscle memory, and a credential lands somewhere it should never have been.

The four patterns I see most:

  • Tab confusion — the window you thought was your local terminal turns out to be a shared notebook.
  • Stale clipboard — you think you copied the path you just yanked, but you actually still have the token from ninety seconds ago.
  • Reflex pastingCmd-V is muscle memory; by the time your brain catches up, the message is mid-send.
  • Screen-share blindness — you forget the call is still running, paste a key into your terminal, and seven people see it.

The lesson is not "be more careful." The lesson is that any system that quietly stores high-value secrets next to grocery lists is going to leak eventually. The fix has to live below the human, not on top of them.

The 8-step damage-control playbook

Use this after you have already rotated the credential and want to make sure nothing else is hanging open. Ordered roughly from highest leverage to lowest.

  1. Confirm the rotation actually worked. Test the new credential in a real call. Confirm the old one returns an authentication error.
  2. Revoke related sessions and tokens. Many services let you sign out of all devices or invalidate every refresh token at once.
  3. Check the audit log. Look for activity from IPs, regions, or hours that don't match yours.
  4. Clean the surface the secret landed on. Delete the chat message, edit the doc, remove the comment.
  5. If it is in version control, treat it as permanently public. Force-push and history rewriting do not unpublish a value that has already been pushed. Bots index public commits in seconds.
  6. Tell the people who need to know. A short, calm note is better than a quiet rotation that breaks someone else's deploy at midnight.
  7. Capture what happened in two sentences. Not for a postmortem ritual — for your own future memory. You will thank yourself next time you tighten a workflow.
  8. Fix the upstream cause, not just this incident. If your clipboard happily stores secrets next to memes, the next leak is already on the calendar.

Scenario fixes: Slack, GitHub, screen share, Notion

Different surfaces have different exposure profiles.

Where it landed Why it is risky What to do
Slack / Teams DM Stored server-side, indexed for search, mirrored to mobile, often retained in compliance archives. Rotate first. Delete the message. Admin can purge it from search, but treat the value as exposed.
GitHub commit / PR comment Public commits are scraped within seconds. Private repos still leak via forks, integrations, and accidental visibility flips. Rotate immediately — this is the riskiest surface. Edits and history rewrites are tidiness, not protection.
Screen share / livestream Anyone watching saw it. Any recording captured it. Thumbnail previews retain it. Rotate. Tell the room — people respect speed more than silence. Ask for recordings to be edited.
Notion / Confluence / Google Docs Cloud doc with version history. Collaborators may have notifications, mobile drafts, offline copies. Rotate, remove the value, purge version history if supported, tell edit-access collaborators.
Public Jira / GitHub issue Indexed by search engines and often forwarded into Slack via integrations. Rotate. Edit or delete. Search your integrations for forwarded copies.
AI assistant chat Some assistants log conversations for training or debugging. Raw text may live in vendor systems for weeks. Rotate. Stop the conversation. Delete it if the provider exposes that control.

Myths that make leaks worse

Bad advice that feels like protection but isn't:

  • "I deleted the message, so it is gone." Deletion removes the visible message. It does not erase server logs, search indexes, mobile caches, retention archives, push notification previews, or anyone who had the window open at the time.
  • "I force-pushed, so the commit is gone." Force-pushing rewrites the branch tip. It does not unlist the dangling commit from caches, integrations, mirrored forks, or scraper databases that already pulled it.
  • "It was a private repo, so it is fine." Private is not the same as inaccessible. Repos get accidentally flipped public, integrations expand access, former employees keep local clones.
  • "I will rotate it later, after I confirm nothing bad happened." Rotation is the cheap action. Investigation is the expensive one. Do them in that order.
  • "It was just for testing, so it does not matter." If a "test" key can read or write production data, it is a production key with worse hygiene.

The structural fix: a secret-aware clipboard

Tightening your habits helps, but habits break under load. The reason this keeps happening is structural, not personal. The fix has to be structural too.

The single most impactful change is to use a clipboard tool that understands what it is holding. When the value being copied is shaped like a token, key, password, JWT, or cloud credential, it should be treated differently from the moment it enters the clipboard — not after the leak.

Four properties to look for:

  • Auto-classify on capture. The clipboard should detect that ghp_xyz…, sk-ant-…, an AWS access key, or a JWT is not the same as a sentence — the second it lands.
  • Encrypted local vault. If your clipboard manager keeps a flat plaintext database of everything you ever copied, the secret problem is now a file problem.
  • Secrets kept out of searchable history. Generic clipboard history puts every value in the same scrollback. Secret-aware history should hide, mask, or quarantine secret items so they are not the next thing you accidentally arrow-key into.
  • 100% local. Your clipboard should not sync secrets to a vendor cloud, even helpfully, even with end-to-end encryption marketing. The simplest threat model is the one where the data never leaves your machine.

Where ClipGate fits

I built ClipGate because I was tired of the "oh no" feeling. It is a terminal-native clipboard vault for developers that auto-classifies every copy into one of ten content types — secrets, code, URLs, errors, diffs, file paths, JSON, shell commands, SHA hashes, plain text — and flags secrets the moment they enter the vault.

Everything lives in a local SQLite database with owner-only permissions. No cloud, no telemetry, no account. You can cg list, cg search, cg get --type secret, and explicitly pull a secret back only when you need it. There is also an MCP server (cg mcp) that lets Claude Code, Cursor, and friends query your clipboard history without leaking secrets to the model.

pip install clipgate
cg doctor   # sanity check
cg watch    # start the clipboard daemon
cg list     # see what you've copied recently
Enter fullscreen mode Exit fullscreen mode

macOS, Linux, and Windows. Single 4.6 MB statically linked Rust binary. 220+ tests. Source and docs at clipgate.github.io.

Before you close this tab

If you came here because something bad just happened: you have already done the hardest part, which is noticing. Rotate the credential, clean the surface, log what happened, and move on. This is survivable, and you will be a sharper engineer on the other side of it.

If you came here because you want to make sure it doesn't happen at all: the clipboard is the right place to fix it. Pick a tool — any tool — that treats secrets as a different class of data. If you want to try ClipGate, I would love your feedback.

Canonical source: clipgate.github.io/blog/accidentally-pasted-password-or-api-key.

Top comments (0)