If a secret key has leaked, replace it first. Cleaning up the code comes later. Anyone who copied the key can still use it after you delete the file. Then check what was used, set a spending limit and fix the cause.
Do not paste the leaked key into a chat to ask if it is safe. That gives it to one more place.
Key leaked? Do this now
The first hour
- 1Find the ownerWhich service is it, and which app uses the key?
- 2Under attack? Turn it offDo this even if the app stops.
- 3Otherwise, swap it safelyCreate a new key, put it in the app, test, then turn the old one off.
- 4Read the usage logLook for strange times, places, amounts and downloads.
- 5Lower the spending limitSo the bill cannot grow overnight.
- 6Check for personal dataIf any was reachable, call your data protection officer.
- 7Fix the causeMove the key to the server and scan every project.
What is an API key?
It is a password that lets one program use another. If your app uses Claude, the Claude key proves it is your account. Anyone with the key may be able to spend your money or read your data.
Safe
- On your server
- In a secret manager
- One key per app
- With a spending limit
Unsafe
- In web page code
- In VITE_ or NEXT_PUBLIC_
- In a chat or screenshot
- In a public project
How common is it?
GitGuardian, a company that sells secret scanning, counted 28.65 million new secrets in public code on GitHub in 2025. That is 34% more than the year before. Secrets for AI services rose 81%. Of the keys that worked in 2022, over 64% still worked in January 2026.
Which keys may be public?
| Key or setting | Can visitors see it? | Safe? |
|---|---|---|
| Claude, OpenAI or Gemini API key | Must not | Keep it on your server |
| Supabase publishable or anon key | Yes, it is made for that | Only if Row Level Security is on and correct for every table |
| Supabase secret or service_role key | Must not | It skips the security rules |
| Anything starting with VITE_ | Yes, it can go into the web page | Never put a secret there |
| Anything starting with NEXT_PUBLIC_ | Yes, it can go into the web page | Never put a secret there |
| Database password | Must not | Keep it on your server |
Row Level Security is a database rule that decides which rows each person can see.
Where keys leak
- In web page code, because AI put the key in the front end to make a demo work.
- In a
.envfile uploaded to GitHub. - In a screenshot, slide or screen recording.
- In a chat, support ticket or WhatsApp group.
- In logs that print the whole request.
- In a workflow file shared as a template.
Check your app in 15 minutes
- Open your live site. Press F12, then choose Sources or Network.
- Search for
sk-,AIza,service_roleandsecret. These are only clues; finding nothing does not prove you are safe. - Check that
.envis listed in.gitignore. - Look at GitHub’s Security tab for alerts.
- Log in as customer A. Try to open customer B’s record.
- Check who can see your keys in n8n, Vercel, Supabase and shared folders.
Only test apps you own or have permission to test.
Copy this prompt
Check this project for exposed secrets. Do not print any secret; show only the file, line and type. Check: front-end code, VITE_ and NEXT_PUBLIC_ settings, .env files, .gitignore, logs, test files, workflow exports and git history if you can see it. For each: what it opens, who can see it, how urgent, and how to replace it. Then say what you could not check. Do not change files or call any service.
Build this feature so that no secret reaches the browser. Put all AI and database-admin calls on the server. Check the user's login and permission on the server for every request. Add a rate limit, a daily spending cap and logs that never print keys or personal data. List every environment setting, say if it is public or secret, and show me how to test that a visitor cannot see it.
Set a limit on every AI account
| Provider | What you can set | Watch out |
|---|---|---|
| Claude API | Your own limits for the organisation and each workspace | Standard monthly caps start at US$500, so set a lower one |
| OpenAI API | Hard limits for the organisation, project or key | An alert only warns you. A hard limit stops use, though it may go slightly over |
| Gemini API | Project caps, still experimental | They can be about 10 minutes late |
GitHub can help, but not with everything
Secret scanning is free and automatic for public projects. GitHub also blocks many known secrets when you push to a public project, but people can bypass the warning. Private company projects need a paid add-on. Anthropic says it turns off Claude keys that GitHub finds in public projects. Do not wait for that.
After replacing a key, you usually do not need to rewrite the project history. Copies may still exist, which is why replacing it comes first.
Did personal data leak too?
A leaked key is not always a personal data breach. It may be one if somebody could reach customer or staff records. Malaysia’s guideline gives 72 hours to tell the Commissioner about a breach that meets its rules. If it is likely to cause significant harm, the people affected must be told within 7 days after that. The guideline treats more than 1,000 people as significant scale. Parts of it count the clock differently, so get advice at once. See our PDPA and AI guide.
Seven habits that prevent it
- One key for each app, and one for testing.
- Give each key the least access it needs.
- Store keys in a secret manager or the host’s secret settings.
- Turn on secret scanning before the first upload.
- Set spending caps on day one.
- Remove old keys every three months.
- Write down who replaces which key, and practise once.
Next, read how to review AI-written code and how to defend against prompt injection.
Build with Claude and keep access under control.
Next public class: 14–15 January 2027 at Worq TTDI · seats available
Making apps with AI? See our AI vibe coding course.
HRD Corp claimable. AITraining2U is an HRD Corp registered training provider. Our public and in-house courses are claimable under the HRD Corp Claimable Courses (SBL-KHAS) scheme, and we prepare the grant paperwork with you. See HRDC-claimable AI training: courses, costs and how to claim.