UndieGravity LogoUndiegravity

How to Review AI-Generated Code: A Security Checklist

A checklist for reviewing code from AI assistants before it ships: secrets, input validation, auth checks, invented packages, error handling, and tests.

By UndieGravity, , 2 min read

AI assistants write code that usually runs. Running is not the same as safe. The mistakes they make are predictable, which means a short checklist catches most of them. Use this before merging anything an assistant wrote, especially code that touches users or data.

1. Secrets

  • No API keys, passwords, or tokens written into the code.
  • No secrets in browser-visible variables (NEXT_PUBLIC_, VITE_).
  • .env files are in .gitignore.

2. Input validation

Every value from a user, URL, or form must be checked on the server: type, length, and format. Client-side validation is for convenience; it is skipped by anyone calling your API directly.

3. Authorization on the server

Look at every API route and Server Action and ask: who is allowed to call this? AI code often hides a button in the UI but leaves the endpoint open. The check must be in the server code that changes the data.

4. Injection and unsafe HTML

  • Database queries use parameters or an ORM, never string concatenation.
  • dangerouslySetInnerHTML and innerHTML only with content you control or have sanitized.
  • JSON inside a script tag has < escaped.

5. Packages that do not exist

Assistants sometimes suggest package names that look plausible but do not exist, and attackers register those names with malicious code. Before installing, check the package on npm or PyPI: real download counts, a linked repository, and a known maintainer.

6. Error handling

  • Errors are caught and logged on the server, and users see a friendly message, not a stack trace.
  • Failures in optional features (analytics, email) do not crash the main request.
  • Network calls have timeouts.

7. Rate limits on public endpoints

Login, signup, contact forms, and anything that sends email need a rate limit. Without one, a script can send thousands of requests a minute.

8. Tests and types

Run the type checker and linter, and ask the assistant to write tests for the edge cases: empty input, wrong types, unauthorized users. Then read the tests; an assistant can write tests that pass without checking anything meaningful.

Static analysis tools such as Semgrep can scan for many of these patterns automatically. Run one on every pull request.

Keep reading