01 · The checklist
What should you check in AI-generated code?
Check five things in every batch of AI-generated code before it merges: tests, secrets, dependencies, licences and input handling. The table gives the check, what to do and where the risk is documented. For the full 40-point version, see the code audit checklist.
| Check | What to do | Why |
|---|---|---|
| Tests | Run the tests; read what they assert; add one for the behavior you asked for | Generated tests can pass without proving anything |
| Secrets | Scan the diff and history for keys, tokens and passwords; rotate anything found | OWASP says a secret found in code should be revoked and rotated |
| Dependencies | Confirm each new package exists, is the one you meant and is maintained | Models can suggest packages that do not exist |
| Licences | Check new packages and any copied blocks for licences you can accept | Suggestions can match public code |
| Input handling | Look for string-built queries, missing validation and open endpoints | A study of Copilot found many insecure suggestions |
02 · Tests
How do you check the tests an AI tool wrote?
Run them, then read what they assert, because a test that only calls the code and checks nothing passes forever.
- 01
Break the code on purpose and confirm a test fails. Also check that the tests cover failure cases, such as bad input and missing data, and not only the path that works. If the tool wrote the code and the tests in one session, treat both as unreviewed. Write one test yourself for the main behavior you asked for. This is a rule of practice, not a finding from a source.
03 · Secrets
How do you keep secrets out of AI-generated code?
Scan every diff and the history for secrets before merge, and rotate any that appear.
- 01
The OWASP Secrets Management Cheat Sheet says a secret found in code should be revoked, rotated and removed, and recommends detecting secrets early, for example with pre-commit hooks (checked 17 Nov 2026). Do not paste live keys into prompts, and keep settings per environment outside the code. If a key reached a repository, assume it is exposed: rotate it first and clean the history second.
04 · Dependencies
What is package hallucination, and how do you catch it?
Package hallucination is when a model recommends a library that does not exist, and catching it means checking every new import against the real registry.
- 01
A study by Spracklen and colleagues tested 16 code-generating models across 576,000 code samples and found average hallucination rates of at least 5.2% for commercial models and 21.7% for open-source ones (arXiv 2406.10279, checked 17 Nov 2026). OWASP describes the attack that follows: someone publishes a malicious package under a commonly hallucinated name and waits for developers to install it.
- 02
For each new dependency, confirm the name, the publisher, the release history and that you meant to add it. Then run a vulnerability scan; OWASP lists not knowing component versions as a sign of exposure.
05 · Licences
Can AI-generated code carry licence problems?
Yes, it can, because suggestions can match existing public code.
- 01
GitHub's documentation says Copilot can generate code that matches public code, that matches can be blocked or shown with licence details depending on policy, and that matches occur in under 1% of inline suggestions (checked 17 Nov 2026). Turn on the matching-code setting your tool offers, and flag any large block you did not write for a licence check.
06 · Input handling
Does AI-generated code have more security flaws?
It can.
- 01
In a study of GitHub Copilot, Pearce and colleagues generated 1,689 programs from 89 scenarios and found about 40% vulnerable (arXiv 2108.09293, checked 17 Nov 2026). That study tested an early Copilot release, so do not read it as today's rate. Its lesson holds: review output for injection, missing validation and weak access checks as you would a new hire's first pull request.
07 · Next step
When should you get an outside review?
Get an outside review when AI-written code is about to carry real users, money or data and nobody on the team has read it all.
- 01
See also code review vs code audit for which check fits. Request a code audit quote and we will agree a fixed price after a short call.