Deploy, Convert & Scale

Security Audit for AI-Generated Code: OWASP, Secrets and RLS

Auditing AI-generated code means checking the same OWASP risks as any web app, but with extra focus on the mistakes AI tools make most often: secrets in the frontend, missing or permissive row-level security, authorization checks only in the UI, unvalidated input and outdated or hallucinated dependencies. A structured audit combines automated scanning with manual tests of access control.

neooutput editorial team 4 min read Auf Deutsch lesen

Why AI-generated code needs a specific audit focus

AI tools optimize for code that works in the demo, so security controls that are invisible during a demo are the ones most often missing.

Typical patterns: API calls made directly from the browser with a secret key, database tables readable by anyone with the public key, admin features hidden in the UI but reachable via the API, and server actions that trust a user ID sent by the client. None of these break the happy path, which is exactly why they survive until someone looks.

The audit scope should therefore include the whole system, not only the repository: hosting configuration, database settings, storage buckets, third-party integrations, preview deployments and the accounts that can change them. Many real incidents in AI-built apps come from a misconfigured dashboard setting rather than from a line of code.

Step 1: Find and rotate secrets

Start by scanning the repository, its full Git history and the built frontend bundle for credentials.

Run a secret scanner such as gitleaks or trufflehog over the whole history, then open the production site, view the JavaScript bundles and search for key patterns. Anything found must be rotated, not just deleted, because old commits and cached bundles keep it alive. Move every secret into a server-side store and access it only from server code.

  1. Scan the repository including history.
  2. Inspect production bundles and network calls.
  3. Rotate every exposed key at the provider.
  4. Move calls behind server functions.
  5. Add secret scanning to CI and pre-commit.

Step 2: Broken access control and RLS

Broken access control is the top OWASP risk and the most common serious flaw in AI-built apps, so test it manually with real accounts.

For Supabase, list every table in exposed schemas and confirm RLS is enabled with policies per operation that rely on auth.uid() and membership tables, not on client-supplied values. Check storage bucket policies and any functions declared as security definer. For Firestore, review Security Rules and test them with the emulator. Then try it: log in as user A, capture a request, change the ID to user B's record and see what happens. Repeat for updates and deletes, and for every admin endpoint as a normal user.

  • RLS enabled on every exposed table.
  • Separate policies for select, insert, update, delete.
  • No policies that are simply 'true' for authenticated users on private data.
  • Service role keys never in client code.
  • Admin checks enforced on the server.

Step 3: Injection, XSS and input validation

Check every place where user input reaches a query, a shell, HTML or an LLM prompt.

Look for string-built SQL, raw HTML rendering (dangerouslySetInnerHTML or equivalents), file uploads without type and size checks, and URL fetches that allow server-side request forgery. Validate inputs with schemas on the server. For AI features, treat model output as untrusted: never render it as raw HTML or let it trigger privileged actions without server-side checks, because prompt injection can steer it.

Step 4: Dependencies and configuration

Audit dependencies for known vulnerabilities and for packages that should not be there at all.

AI tools sometimes add abandoned packages or invent package names that attackers later register. Run npm audit or your ecosystem's equivalent, remove unused dependencies and verify unfamiliar packages manually. Review configuration: security headers, CORS rules, cookie flags, debug modes, verbose error messages and publicly accessible preview deployments.

Step 5: Make the audit repeatable

A one-time audit decays with every new prompt, so build the checks into the workflow.

Add secret, dependency and static analysis scanning to CI, write automated tests that try cross-user access, and put security rules into the agent instructions file your team uses (CLAUDE.md, AGENTS.md, Cursor or Windsurf rules). Tools like Claude Code's security review command or Lovable's security scan help, but a human with an attacker's mindset should still review sensitive changes. Teams working under ISO 27001 or similar frameworks should document these controls as part of their secure development process.

Frequently asked questions

Is AI-generated code less secure than human code?

Not inherently, but it is often produced without security requirements in the prompt and without review. That leads to predictable gaps such as missing authorization and exposed secrets.

What is Row Level Security and why does it matter?

RLS is a Postgres feature, used heavily by Supabase, that restricts which rows a user can access. Because the Supabase anon key is public, RLS policies are what actually protect your data.

Can I rely on automated scanners alone?

No. Scanners find secrets and vulnerable dependencies well, but broken access control usually needs manual testing with real accounts and an understanding of the business rules.

All insights