AI Khazna
Guides

Ten security mistakes AI makes in your code (and how to catch them)

A practical review list for vibe-coded apps, before real users arrive

ATAI Khazna Team7 min read

Your app works: sign-up, dashboard, the AI feature. That is the moment to slow down. AI coding tools are good at making things work and less reliable at making them safe: the shortest path to a working demo often skips the dull parts that stop strangers reading your data or running up your bills.

The same mistakes keep coming back. Here are ten, each with what it looks like, how to check and what to ask the AI. You do not need to be a security engineer, just an hour and the patience to read what the AI wrote.

1. Secret keys in client code or the repo

Looks like: an API key pasted into a component, or stored in a variable the framework ships to the browser. In Next.js, variables prefixed with NEXT_PUBLIC_ are inlined into the JavaScript sent to the browser; Vite does the same with VITE_ and warns against putting API keys there. A committed .env file leaks too.

Check: search the code and the live site's scripts for NEXT_PUBLIC_, VITE_, secret and key. Confirm every .env file is listed in .gitignore.

Ask the AI: "Move every secret to server-only code and tell me which exposed keys I must rotate."

2. Supabase tables without row level security

Looks like: Supabase lets the browser query your database with a publishable key (older projects call it the anon key). That key is meant to be public; what protects your data is row level security (RLS), and Supabase's documentation says to enable it on every table in an exposed schema such as public. Without it, anyone with the public key can read and write that table. Worse still: the AI "fixes" a permission error by using the secret key (legacy name service_role) in the browser. Supabase is explicit that this key bypasses every RLS policy and must never sit in a browser or source control.

Check: in the Supabase dashboard, confirm every table has RLS on and sensible policies. Search the frontend code for service_role and sb_secret_. An empty result right after enabling RLS is expected until you add policies.

Ask the AI: "Enable RLS on every table and write policies so users can only read and change their own rows. Explain each policy before applying it. Never use the secret key outside server code." The Supabase Postgres Best Practices skill gives your agent this knowledge up front.

3. Trusting client-side checks

Looks like: the price, the user's role or an isAdmin flag decided in the browser and sent to the server, which believes it. A hidden button is not a permission.

Check: copy a request from the Network tab, change the price or role and resend it. If the server accepts it, it trusts the client.

Ask the AI: "Recalculate prices, roles, limits and ownership on the server. Treat every value from the browser as untrusted."

4. Missing auth on API routes

Looks like: a route such as /api/orders/123 returns any order to anyone who guesses the number. Is the caller signed in, and is this record theirs? AI often checks the first and forgets the second.

Check: sign out and call each API route directly. Then sign in as user A and request a record that belongs to user B.

Ask the AI: "Make every API route and server action check the session and that the record belongs to the current user. List what each route checks."

5. No rate limits on forms and AI endpoints

Looks like: sign-up, password reset, contact forms and, above all, endpoints that call a paid AI model can be hit thousands of times by a script, giving you spam or a large bill.

Check: for each endpoint that sends email, costs money or calls a model, ask what stops one person calling it a thousand times a minute.

Ask the AI: "Add per-user and per-IP rate limits to these endpoints, bot protection on public forms and a hard spending cap on AI calls. Prefer what our hosting platform already provides."

6. Unvalidated input and injection

Looks like: SQL built by joining strings with user input, user text rendered as raw HTML, uploads with no type or size limit, or user text fed to an AI prompt that can trigger actions.

Check: search for string-built queries, innerHTML and dangerouslySetInnerHTML. Type a quote mark, a very long string and a <script> tag into your forms.

Ask the AI: "Validate every input on the server against a schema, use parameterised queries only, escape output and limit uploads by type and size."

7. Overly permissive CORS

Looks like: Access-Control-Allow-Origin: * on an API that relies on cookies or tokens, or code that echoes back any origin. MDN notes that the wildcard only works for requests without credentials,, and AI tools sometimes "solve" the error by echoing the origin instead.

Check: search the code and hosting config for Access-Control-Allow-Origin and cors(.

Ask the AI: "Restrict CORS to an explicit list of our own domains."

8. Leaking error details

Looks like: users see stack traces, database errors naming your tables, or raw third-party responses.

Check: send a wrong ID, an empty form or an expired session, and read what the page and network response show.

Ask the AI: "Show users short, generic errors and log details on the server only."

9. Outdated or hallucinated packages

Looks like: the AI adds a package that is abandoned, has known vulnerabilities, or does not exist at all. Attackers register names that models tend to invent and fill them with malicious code, a tactic known as "slopsquatting".

Check: open each new dependency on the official registry and confirm the exact name, a real maintainer and recent activity. Run npm audit.

Ask the AI: "Before adding any package, tell me why it is needed and link its official page. List dependencies we can remove."

10. Missing logging and backups

Looks like: something goes wrong and there is no record, or a bad migration deletes data and there is nothing to restore.

Check: can you say who did what, and when, for sign-ins, payments and admin actions? Do you know what backups your plan includes, and have you tried a restore?

Ask the AI: "Add server logs for sign-in, payment and admin actions without logging passwords, tokens or personal data, and write a short restore guide for our database."

A review prompt you can paste

When a feature is finished, paste this into your coding agent, then read its report carefully.

Review this project for security before launch. Do not change code yet. 1) Confirm no secret reaches the browser or the repository. 2) Confirm every table has row level security with owner-only policies. 3) For each API route and server action, state its authentication and ownership checks. 4) Flag values the server trusts from the client. 5) Flag endpoints without rate limits, especially AI and email. 6) Flag unvalidated input, string-built queries and unescaped HTML. 7) Show the CORS configuration. 8) Show what users see on errors. 9) List risky or unverified dependencies. 10) Describe logging and backups. Order findings by severity and wait for my approval.

Make the fixes stick

The AI does not remember your last session, so it may repeat a fixed mistake. Put the rules where it reads them every time: CLAUDE.md for Claude Code, .cursor/rules or AGENTS.md for Cursor. Short lines work best, such as "Every new table gets RLS and owner-only policies". Our guide to writing a rules file for CLAUDE.md and Cursor shows how to set one up.

Next step: before you share the link with real users, work through the launch checklist in the Vibe Coding hub.

Frequently Asked Questions

Is the Supabase publishable or anon key safe to put in my frontend?
Yes. Supabase designs the publishable key (legacy name anon) to be public, and row level security decides what it can reach. The secret key (legacy name service_role) bypasses RLS and must only live in server code.
Can I just ask the AI to make my app secure?
A vague request gets a vague result. Ask for specific checks, such as RLS on every table or ownership checks on every API route, ask it to report before changing code, and then verify the findings yourself.
What is slopsquatting?
It is when attackers publish packages under names that AI models tend to invent. If you install a suggested package without checking it, you may run malicious code. Always confirm a package on its official registry page before installing.
How often should I run this review?
Run it before your first launch, then after any feature that touches sign-in, payments, uploads, AI calls or the database schema. Putting the key rules in your project rules file prevents most repeats.
securityvibe codingsupabasecode reviewlaunch checklist