Home › Cybersecurity › Review code for vulnerabilities: how to do it with AI
Review code for vulnerabilities: how to do it with AI
From official vendor pages; selected tasks also include dated logged-out free-plan trials. Report an error.
Intermediate Risk: Medium 🛡️ Cybersecurity
Paste a function or point a coding agent at your repo and ask it to look for common insecure patterns: injection, hard-coded secrets, missing input checks, unsafe deserialisation. It's a quick extra pair of eyes, not a replacement for a security review or scanner.
Who it’s for: Developers, security analysts and reviewers checking code before it ships.
Why medium risk: AI misses real flaws and invents others, and the code may be proprietary.
ChatGPT has the highest score on our published rubric (94/100) of the 4 tools listed for this task. Codex includes PR review; Free has limited Codex access.
Step by step
- Pick a focused scope: one endpoint, function or file.
- Remove secrets and anything your employer forbids sharing.
- Ask for issues with line numbers, a severity and a short exploit scenario.
- Ask for the fix as a minimal diff.
- Write or run a test that proves each issue before fixing it.
- Still run your normal scanners and a human review.
AI prompts to review code for vulnerabilities
Replace the [brackets] with your details. See all prompt examples
Review this [language] code for security issues: injection, auth or access-control gaps, secrets, unsafe deserialisation, path traversal, missing input validation. For each: line number, severity, how it could be exploited, minimal fix. Say so if you find nothing. [paste]
For the issue on line [N], write a unit test that fails with the current code and passes after the fix.
List 8 questions a security reviewer would ask about this endpoint (who can call it, what data it touches, what it trusts) and answer what you can from the code.
Illustrative example
You paste
query = "SELECT * FROM users WHERE email = '" + email + "'"
A good answer looks like
Line 1, High: SQL injection. The email value goes straight into the query, so input like ' OR '1'='1 returns every user.
Fix: use a parameterised query, e.g. cursor.execute("SELECT * FROM users WHERE email = %s", (email,)).
Test: call the function with ' OR '1'='1 and assert it returns no rows.Illustrative example written for this guide, not output captured from a specific tool.
Which tool to pick, and why
- Claude (incl. Claude Code): Claude Code includes code review and can read the whole repository; the Free plan handles pasted snippets. Visit official website ↗
- GitHub Copilot: Pro adds code review on pull requests ($10/month, verified); Free includes limited chat and agent usage in your editor. Free plan can do this Visit official website ↗
- Cursor: Premium includes Bugbot code review; its agent can search the codebase for callers of a risky function. Free plan can do this Visit official website ↗
- ChatGPT (incl. Work & Codex): Codex includes PR review; Free has limited Codex access. Free plan can do this Visit official website ↗
Reasons come from the capabilities, free-plan details and prices we've checked on official pages (separate from any dated trial above). Sources: claude.com/pricing · github.com/features/copilot/plans · cursor.com/pricing · chatgpt.com/pricing
Common mistakes
- Treating "no issues found" as proof the code is safe.
- Pasting code containing keys or customer data.
- Applying the fix without a test.
- Reviewing a whole repo in one prompt.
Privacy tip
Remove secrets before sharing code. For private code, turn on Cursor's Privacy Mode or opt out of Copilot training at github.com/settings/copilot/features, and use only tools your employer has approved.
Cursor setting · GitHub Copilot setting · Claude (incl. Claude Code) setting · Sources: cursor.com/help/security-and-privacy/privacy · github.com/features/copilot/plans · privacy.claude.com/en/articles/12109829-how-do-i-change-my-model-improvement-privacy-settings