Coding agent

How to security test code written with GitHub Copilot

Updated

Copilot is a pattern mirror: it completes the way the surrounding code already does, including its mistakes. Test the recurring patterns — string-built queries, unescaped output, unchecked ids — rather than individual lines.

Where this class of bug actually lives in Copilot-assisted code

  • Repeated patterns. One raw SQL example becomes twenty completions of the same shape.
  • Trusting the variable name. userId from a request is completed straight into a query without being checked against the session.
  • Escaping gaps. String concatenation in a template or a query, completed because the surrounding file does it.
  • Tests that mirror the bug. A generated test asserts the current behaviour, including the missing check.

What to try first

  1. Grep for the dangerous shapes across the codebase, not per file: execute( with an f-string, innerHTML, dangerouslySetInnerHTML, raw(.
  2. Trace every request-derived id into every query it reaches.
  3. Pick the three most-copied functions and test each with two accounts.
  4. Check whether the tests would pass with the access check removed.

A reproduction you can keep

Pattern counts are the useful metric here. Count, then test the top hit:

Find the repeated shape, then test it
# the shapes Copilot reproduces
grep -rnE 'execute\(f["'\'']|execute\(.*% *\(|innerHTML *=|dangerouslySetInnerHTML|raw\(`' app/ lib/ src/ | head

# then the id path on the file with the most hits
curl -sS -i https://staging.example.com/<route>/1003 -H 'Authorization: Bearer ***'

# vulnerable: a query built by concatenation, and a 200 on the foreign id
# fixed: bound parameters everywhere, and identical 404s

What "fixed" has to look like

Fix the pattern once in the shared helper and re-run the grep until the count is zero, then verify the id paths with two accounts. A per-line fix does not hold because the next completion copies the neighbours again.

Where people get this wrong

  • Reviewing only the added lines misses that the pattern already existed on forty other lines.
  • A suggestion that looks idiomatic can be a deprecated API with a known flaw.
  • Generated tests encode current behaviour, so they can lock a bug in place.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Is Copilot-generated code more vulnerable?

Not by itself, but it reproduces the patterns already present. Insecure neighbours produce insecure completions.

How should I review Copilot code?

By pattern count across the codebase, not line by line. Fix the shape in one place and re-grep.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.