How to stop API keys and secrets leaking into Cursor, Copilot and ChatGPT
An API key in a pasted stack trace is easy to miss and hard to take back. Here is how it happens and how to stop it.
By Inveil ·
Summary
API keys leak into AI coding tools through pasted code, logs, .env files and screenshots of terminals. Rotating a leaked key is the cleanup, but the better approach is a check on the developer machine that blocks keys before the request leaves.
How keys end up in prompts
- Pasting a stack trace or log that includes an Authorization header.
- Pasting a config or .env file to ask why it is not loading.
- Sharing a screenshot of a terminal or dashboard with a key visible.
- Attaching a file that contains a hard-coded secret.
Why this is hard to catch by hand
The key is usually not the point of the question. The developer is asking about an error, and the secret is just part of what was copied. Nobody reads every line before they paste.
What to do about it
- Keep secrets out of code and logs where you can, and rotate any key that has been pasted.
- Check prompts, files and screenshots on the developer machine before they are sent.
- Block requests that contain keys, rather than relying on people to notice.
- Add your own patterns, such as internal token formats.
Where Inveil fits
Inveil detects API keys in prompts, images and attachments on the device and can block the request or strip the key. You can add your own patterns, and it works alongside tools like Cursor. Code-level protection for specific files, functions and repositories is coming soon.
Inveil is data loss prevention (DLP) for AI. It checks prompts, files and screenshots on each employee's machine before they reach an AI tool, blocks or redacts sensitive data by your rules, and logs every event.
Common questions
- Can ChatGPT or Cursor see my API keys?
- If a key is in text, a file or a screenshot you send, it goes to the AI provider with the rest of the request. Block keys before they are sent.
- What should I do if I pasted an API key into an AI tool?
- Treat it as exposed and rotate it. Then put a check in place so it does not happen again.
- Can Inveil block API keys in screenshots?
- Yes. Inveil reads images and screenshots on the device with built-in OCR and applies the same block or redact rules as for text.
More blogs
- Smaller companies are more likely to put customer data into public AI tools
- How to stop employees pasting customer data into ChatGPT
- How to stop screenshots with personal info going to AI tools
- What is shadow AI, and how do you stop it?
- What to put in an AI usage policy for a small business
- A Microsoft Purview alternative for small businesses protecting AI use
- AI data protection for small business: where to start
- How to stop employees leaking company data to AI: a practical guide