Home › Cybersecurity › Review code for vulnerabilities: how to do it with AI

Review code for vulnerabilities: how to do it with AI

Last checked

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.

Best pick

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

  1. Pick a focused scope: one endpoint, function or file.
  2. Remove secrets and anything your employer forbids sharing.
  3. Ask for issues with line numbers, a severity and a short exploit scenario.
  4. Ask for the fix as a minimal diff.
  5. Write or run a test that proves each issue before fixing it.
  6. 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

Focused review
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]
Prove it
For the issue on line [N], write a unit test that fails with the current code and passes after the fix.
Threat questions
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

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

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

Related tasks

Report an error on this page