SCAN
Your AI coding assistant makes your code less secure: the breakdown
What's happening
AI coding assistants write the code that usually works, the pattern they've seen most often. Plenty of the code they learned from was never safe, so the unsafe pattern comes out looking just as confident as the safe one. And because it looks right, people accept it.
- Stanford researchers (Perry, Srivastava, Kumar, Boneh, ACM CCS 2023) gave 47 participants five security tasks: 33 with an AI assistant, 14 without. On the database task, 36 % of the AI group wrote code open to SQL injection, against 7 % without. The AI group was also more likely to believe their code was secure. The people who did write secure code trusted the AI less, and 87 % of their secure answers needed significant edits to what it gave them.
- NYU researchers (Pearce, Ahmad, Tan, Dolan-Gavitt, Karri, IEEE S&P 2022) had GitHub Copilot complete 89 security-sensitive scenarios, producing 1,689 programs. About 40 % were vulnerable.
Why it matters
The danger isn't only the bad line. It's the confidence: code that compiles and runs feels finished, and a suggestion that appears instantly feels checked. Treat every AI suggestion as a pull request from a stranger: useful, often right, and never merged without a review.
What to do (save this)
- State the security rule in your prompt. Ask for it explicitly: "use parameterised queries", "validate this path stays inside the uploads folder", "use a vetted crypto library".
- Run a scanner on every AI change. A static analysis tool in your editor and in CI catches the common holes (injection, path traversal, weak crypto, hard-coded secrets) before they ship.
- Never build a query by pasting in user input. Use placeholders and pass the values separately.
Set up the check (the step-by-step)
- Pick a scanner for your language. Free, well-known options include Semgrep (many languages), CodeQL (GitHub), Bandit (Python) and ESLint security plugins (JavaScript). One is enough to start.
- Run it locally once on your project and read the findings. Fix the real ones; mark the false alarms so they don't come back.
- Run it on every change. Add it to a pre-commit hook or to your CI so it runs on every pull request, AI-written or not. Make a high-severity finding block the merge.
- Add a prompt rule. Keep a short line at the top of your assistant's instructions (most tools have a rules or instructions file): "Never concatenate user input into SQL, shell commands or file paths. Use parameterised queries and safe APIs."
- Review the risky lines yourself. Anywhere code touches a database, the file system, a shell, authentication or encryption, read the AI's suggestion as if a stranger sent it.
The SQL fix, in one line:
// unsafe: the user's input becomes part of the query
db.query("SELECT * FROM students WHERE name = '" + name + "'");
// safe: a placeholder, the value passed separately
db.query("SELECT * FROM students WHERE name = ?", [name]);
Sources
- Perry, Srivastava, Kumar, Boneh, "Do Users Write More Insecure Code with AI Assistants?", ACM CCS 2023, arXiv 2211.03622
- Pearce, Ahmad, Tan, Dolan-Gavitt, Karri, "Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions", IEEE S&P 2022, arXiv 2108.09293
FREE ONE-TIME UNLOCK
Unlock the full SCAN breakdown
Drop your email once to read the complete step-by-step guide, grab the files, and unlock all 96 Reel breakdowns on this device forever.
✓ Instant reveal right here✓ No spam, unsubscribe any time