t0ul

Vibe Coding Securely

Vibe Coding Securely, Ch. 9: Have the AI Review Its Own Code

Part of Vibe Coding Securely, a short, hands-on book about shipping the app an AI built without getting owned.

You have spent eight chapters attacking your own app by hand. It is a fair question to end on: can the AI just do this for you? It built the thing; can it review the thing? The honest answer is yes, partly, and the useful skill is knowing exactly which part. So in this last hands-on chapter we run a real AI review against Vibe Notes, and because we know every weakness in it, we can grade the review. We planted the holes; now we get to mark the reviewer’s work. That tells you the one thing worth knowing about any reviewer, human or machine: what it catches, and what it quietly lets through.

The review, run for real

You do not need anything new. The model from chapter 6 is already on your machine, and the prompt is short. Here is the one I used:

You are a security reviewer. Review this Next.js + SQLite code for security
vulnerabilities. List each issue as: NAME - FILE - why exploitable - fix. Look
for secrets in browser code, broken auth, SQL injection, XSS, AI prompt
injection or over-broad data access, and unsafe dev leftovers.

To give it something worth reviewing, gather the app as the tool first wrote it, before any of our fixes, by pulling each file from its chN-start tag into one text file:

{
  echo "You are a security reviewer. Review this Next.js + SQLite code ..."
  echo; echo "CODE:"
  for f in ch2-start:lib/secrets.ts ch2-start:app/sync-status.tsx \
           ch3-start:lib/auth.ts ch3-start:app/api/login/route.ts \
           "ch4-start:app/api/notes/[id]/route.ts" ch5-start:app/api/search/route.ts \
           "ch5-start:app/notes/[id]/page.tsx" ch6-start:app/api/assistant/route.ts \
           ch7-start:app/api/debug/route.ts ch7-start:middleware.ts; do
    echo "// FILE: ${f#*:}"; git show "$f"; echo
  done
} > review.txt
ollama run qwen2.5:1.5b < review.txt

You can do the same with any assistant you already use. Paste the prompt and your code into Cursor, Claude, or ChatGPT; the point of this chapter is not the model, it is how to read what comes back. Here is what the local model returned, lightly cleaned of the spinner characters a terminal leaves behind and trimmed of one duplicate line (the shouting capitals, and the stray “loves” for “loads,” are its own, and a fair reminder of how small this model is):

NAME: lib/secrets.ts
- THE KEY IS SHIPPED IN BROWSER EVERY TIME A VISITOR LOVES THIS COMPONENT.
- FIXES IT TO SERVER SIDE WHERE USERS CANNOT ACCESS IT.
NAME: lib/auth.ts
- TRUSTS ANYONE WHO ASKS FOR THEIR SESSION.
- FIXES IT BY GENERATING AND STORING THE SESSION ON SERVER, NOT IN BROWSER.
NAME: app/api/notes/[id]/route.ts
- ANYONE CAN READ A NOTE IF THE ID IS CORRECT, AS LONG AS THEY'RE LOGGED IN.
- FIXES IT BY ADDING OWNERSHIP CHECK TO THE SQL QUERY.
NAME: app/api/search/route.ts
- FIXES IT BY BOUND PARAMETER IN SQL STATEMENT, PREVENTING BAD SEARCH PATTERN.
NAME: app/notes/[id]/page.tsx
- ANYONE CAN VIEW AND CHANGE NOTES, INCLUDING OTHER USERS' NOTES.
- FIXES IT BY ONLY ALLOWING LOGIN USERS TO ACCESS THEIR OWN NOTES.
NAME: app/api/assistant/route.ts
- THE ASSISTANT ALLOWS USER TO ACCESS EVERY NOTE IN TABLE WITHOUT FILTERS.
- FIXES IT BY LIMITING VIEWERS TO ONLY THEIR OWN NOTES AND SCOPING TEXT AS DATA.
NAME: app/api/debug/route.ts
- ANYONE CAN GET ALL USERS AND NOTES. FIXES IT BY REMOVING THE DEBUG ENDPOINT.
NAME: middleware.ts
- ANY USER COULD CALL THIS API FROM ANYWHERE. FIXES IT TO REMOVE CORS HEADERS.

That is genuinely not bad, especially from a tiny model running on your laptop for free. Now let us grade it.

The scorecard

Line the review up against the holes we actually planted across the book:

Planted hole (chapter)What the review did
Secret in the browser bundle (2)Caught. Named the file and the server-side fix.
Trusting the client cookie (3)Caught. “Trusts anyone who asks for their session.”
Read any note by its id, IDOR (4)Caught. Even named the ownership-check fix.
SQL injection in search (5)Caught. Named the bound-parameter fix.
Stored XSS in the note page (5)Missed. Called it an access bug and prescribed an ownership check.
AI feature sees everyone’s notes (6)Caught. “Access every note in table without filters.”
Prompt injection (6)Partial. Gestured at “scope text as data,” never named the threat.
Forgotten debug route (7)Caught. Said delete it.
Wide-open CORS (7)Caught. Said remove the headers.
No rate limit (7)Not seen.
No way to see or contain an incident (8)Not seen.

Seven clean catches, one partial, one outright miss, and two it never had a chance at. That split is the whole lesson of this chapter, because the misses are not random. They fall into three shapes, and each one tells you where to stop trusting the machine and start doing the work yourself.

The three blind spots

The first and most dangerous is the confident wrong answer. Look at the note page again. Its real problem is the stored XSS from chapter 5, the dangerouslySetInnerHTML that runs whatever a note contains. The review looked straight at it and saw an access-control problem instead, and prescribed an ownership check that does nothing whatever about the script running in your reader’s browser. This is worse than saying nothing. A missed issue leaves you uneasy and still looking. A wrong diagnosis that sounds right makes you tick the box and move on, with the hole still open and your guard now down. An AI reviewer states everything, the right and the wrong, in the same calm, certain voice. You cannot tell its catches from its misfires by tone, only by checking.

The second is absence. Two of the holes in this book were not bad lines of code, they were missing things: the rate limit that was not there in chapter 7, and the ability to see and contain an incident that we had to build in chapter 8. The review could not flag either, and no review of existing code can, because you are asking “what is wrong with what I wrote,” not “what did I never write.” A reviewer reads the code in front of it. It does not feel the shape of the code that should exist and does not.

Here is a true one from this very book, and it is the sharpest example I have. While I was finishing these chapters, the practice app was running on a version of Node, the program that runs the code, from a release line that had quietly reached end of life. Then, in October 2026, a serious remote-code-execution bug (nicknamed Node2Shell) landed in Node, and the end-of-life lines will never be patched for it. The tool that scaffolded the app never mentioned the runtime. An AI review of the code did not catch it either, and could not, because it is not a flaw in any line of the code. It is a fact about the world outside the files, namely which versions of Node are still supported this week, and that is not something a reviewer reading your code can see. A person caught it, by keeping half an eye on security news. That is the gap in one story: the problems that turn on current, outside context, or on what is simply absent, are the ones a careful human review is for. Reviewing AI-built apps for exactly these blind spots, the confident misdiagnosis and the thing that is missing, is a service I offer.

The third is cross-cutting context. The bugs the review nailed were the ones you can see in a single file: a key in a component, a string glued into SQL. The ones it fumbled, the XSS and the prompt injection, are about how data flows and renders across the app, which is exactly what gets lost when a model reviews files one at a time, the way you do inside an editor. The wider the reasoning a bug needs, the more likely the review walks past it.

Why you do not have to trust it

Here is the reassuring part, and it is the thread that has run through the whole book. You do not have to trust the review, because you have the checks. Every claim it makes, and every silence, you can settle in seconds against a real attack: npm run check:ch5 would have told you in one line that the note page still runs injected HTML, no matter how confidently the review called it an access bug. The AI review is a lead generator. It is a fast, cheap first pass that points you at suspects. The attack, and the check that could have come out either way, is the judge. Run the review to find candidates, then prove each one, exactly the way you have been doing since chapter 2.

Notice what that flips. Without a way to check, a review is something you either believe or ignore, and both are guesses. With checks, the review becomes a to-do list you can burn down with certainty: a green check closes a line for good, a red one keeps it open until it is really fixed, and a hole the review never mentioned still gets caught the moment you attack the app yourself. The review’s score, seven of eleven here, stops mattering as a grade. What matters is that you verified all eleven, and found the four it got wrong or missed, because you were not relying on it to be right. A reviewer you can check is useful at any accuracy. A reviewer you cannot check has to be perfect, and none of them are.

Straight talk. A bigger model does better than this little local one, and it is worth being precise about where. A frontier assistant like the ones in Cursor or Claude will usually name that XSS correctly and speak more sensibly about prompt injection, so it catches more of the single-file bugs. What it does not fix are the other two blind spots: it still states wrong answers in the same confident voice, and it still cannot see the rate limit or the incident tooling you never wrote. It also costs money per review and gives slightly different answers each run, the chapter 6 lesson again. So use the best reviewer you can, treat its output as leads rather than verdicts, and for anything where the stakes are real, a careful human who does this for a living is still worth the money, precisely for the misdiagnoses and the absences a model talks right past.

Try it. Run the review against your own app. Take its list and, for each item, do not fix anything yet. First reproduce it: can you actually make the bad thing happen? Some will be real, some will be the confident-wrong kind, and a few of your worst problems will not be on the list at all because they are things you never built. Then write yourself a one-line check for each real one, the way this book’s checks work, so that from now on the question “is it fixed” has an answer you can run instead of a reviewer you have to believe.

Where this leaves us

That is the method, whole, and it is the thing to carry out of this book. The AI can write the code and even help review it, but you own what ships, so you attack your own app as you build it, you fix what breaks, and you prove each fix with a check that could have failed. Do that and security stops being a frightening final gate and becomes a small, ordinary habit you run as you go.

One page left, and it is the one to keep by your desk: a short checklist you can walk before every deploy, each line a distilled chapter, so that the habit you just learned fits on a single screen.

← Vibe Coding Securely