Skip to main content
Kiran Brahma
All writing

O9X Build Log 15: The Security Audit - Securing AI Code with Standards

Published Part 15 of O9X Build Logs Personal Essays

In Log 14, I cleaned up the code during Attempt two of my Three-Attempt Protocol. Clean code still breaks under attack. A neat login form with proper variable names can remain open to SQL injection or a session hijack, so Attempt three hardens the code to survive.

I am not a security researcher, and I do not track exploit patterns in Node.js libraries or session management. When I ask an AI if my code is secure, it checks syntax and gives a polite yes. I had to separate finding risks from fixing code.

I split Attempt three into two phases and leave the code untouched until Phase 2. In Phase 1, I build a threat model from the design alone. I use Perplexity or Google to research the exact feature I just built.

I run a direct query: "I am building a User Enrollment System using Next.js and Supabase. List the top 10 most common security vulnerabilities and Critical Vulnerability and Exposures associated with this specific architecture." Out of the 10 items it returned, five applied to my build.

The first was Insecure Direct Object References (IDOR), where User A opens User B's profile by changing the ID in the URL. The second was missing rate limiting, which lets a bot spam the "Create User" endpoint. The third was broken function-level authorisation, where a regular user hits the "Delete User" API by guessing the path.

The fourth was sensitive data exposure, such as bank account numbers showing up in plain text in server logs. The fifth was mass assignment, where a user force-updates the "is_admin" field by adding it to the JSON payload. Those five risks gave me a clear Hit List.

In Phase 2, I paste the clean code from Attempt two alongside that Hit List. I give the AI a narrow prompt: "Review this code specifically against these 5 security risks. For each risk, tell me if the code is vulnerable. If it is, rewrite the code to patch it."

The audit caught a flaw in my "Get Associate Details" API right away. I had assumed Supabase handled permission checks on its own, and it did not. Once I put the right question in front of the right tool, the IDOR fix took 45 seconds.

I cannot fix a flaw until I name it. Attempt three requires building a Hit List before writing a patch. I do not need to know how to break into a system, as long as I know what to look for.