Cursor-Built Apps: 10 Security Mistakes AI-Written Code Keeps Making
An AI editor writes code that runs, not code that has been threat-modelled. These ten mistakes are common in AI-written code, with the fix for each and a quick way to spot them.
๐ก The short version: an AI editor like Cursor is great at making code that runs. It doesn't know which data is private, who your users are or what an attacker would try. These ten mistakes are worth looking for in any AI-written app, whichever tool wrote it.
Let's be fair to the machine first: it did what you asked. You said "make it work", and it worked. The trouble is that "works" and "safe" are two different tests, and only one of them shows up in the preview. ๐
๐ The ten
1. A secret pasted into the code
The model needs a key to make a call work, so it writes the key in. Fix: environment variables, read on the server. Rotate anything that was ever committed.
2. A secret behind a public prefix
A variable named NEXT_PUBLIC_ or VITE_ is bundled into the browser build on purpose. Fix: only publishable keys get those prefixes.
3. Checks that only hide a button
The admin menu is hidden for normal users, but the endpoint behind it answers anyone. Fix: check permission on the server, on every request.
4. Trusting an id from the browser
The code loads /api/orders/123 for whoever asks. Change the number and you can read someone else's order. Fix: filter by the signed-in user on the server.
5. A database with no rules
Supabase tables without row level security, or Firebase left in test mode. Fix: turn on RLS and write policies, or set Security Rules before launch. (RLS explained, Firebase rules explained.)
6. An open route that spends money ๐ธ
A chat or completion route with no sign-in forwards to a paid model. Fix: require sign-in and set limits per user.
7. SQL or HTML built from user input
String-built queries invite injection, and untrusted HTML invites script injection. Fix: parameterised queries, and escape output. Frameworks do this by default until you opt out with something like dangerouslySetInnerHTML.
8. Chatty error messages
Stack traces and database errors shown to users reveal how your system is built. Fix: log the detail, show a plain message.
9. Debug leftovers in production
Test routes, .env files, source maps and sample admin accounts that were handy in development. Fix: remove them from the deployed build.
10. No limit on sign-in attempts
Without throttling, a login form can be guessed at all day long. Fix: rate limiting, plus a delay or lockout after repeated failures.
๐ค Why asking the AI to review itself isn't enough
You can ask the assistant to check its own code for these problems, and it'll catch some. But it reviews what it can see. It can't see what your live site actually serves, which keys landed in the built JavaScript or what your headers say.
| Question | Who can answer it |
|---|---|
| Is this endpoint checking the user? | A code review (yours or the assistant's) |
| Is a key in the public bundle? | Someone looking at the deployed site |
| Are my headers and certificate sound? | Someone looking at the deployed site |
Is a .env or source map public? | Someone looking at the deployed site |
If a key did slip through, here's how to find and rotate it.
๐ Cover the outside view. Scan your deployed app free and see what a stranger sees.