Reviewing AI-generated code for security: a checklist
AI assistants are confident, fast, and routinely produce subtly insecure code. Here's a pragmatic review checklist.
AI-generated code passes typecheck, passes tests, and often passes review. It also fails the kind of security questions that only get asked when something goes wrong. Here is a checklist short enough to actually use on every PR.
Inputs
- Every external input is validated against an explicit schema, not just type-coerced.
- Bounds and length checks exist on anything user-controlled.
- File uploads have size limits, type checks, and don't trust client-provided names.
Authorization
- Every server endpoint that returns data confirms the caller is allowed to see it.
- IDs in URLs are checked against the current user, not just looked up.
- Admin-only routes verify role server-side, never relying on UI state.
Data handling
- No secrets in logs, error messages, or returned payloads.
- Passwords are hashed with a current algorithm, never stored or echoed.
- PII is only present in responses that the caller is authorized to receive.
Dependencies and execution
AI assistants will sometimes suggest packages that don't exist, or that exist but are abandoned. Verify every new dependency: real maintainer, recent commits, reasonable download count. Watch especially for packages with names close to popular ones — typosquatting is a known supply-chain attack.
Never execute strings constructed from user input as code or shell commands, no matter how 'safe' the assistant claims it is.
Make it routine
Stick this list in your PR template. It takes thirty seconds to run through and catches the majority of preventable issues. Security isn't about brilliant analysis; it's about not skipping the obvious checks.
Comments
0 repliesJoin the conversation
Sign in to leave a comment on "Reviewing AI-generated code for security: a checklist".
Loading comments…