← All guides

GitHub Copilot Security Review: What It Checks and Misses

GitHub Copilot

GitHub Copilot can write a working endpoint, a form handler or a whole feature in minutes. That speed is real, and so is the catch: Copilot learns from existing code, and existing code includes insecure patterns. GitHub’s own terms say Copilot’s output may be inaccurate or incomplete, that GitHub doesn’t promise it’s free of vulnerabilities, and that checking and testing it before use is on you (GitHub Terms of Service, section J).

This guide is a practical pass for code that Copilot wrote or changed, whether it came from inline suggestions, chat, agent mode in your editor, or a pull request opened by Copilot on GitHub. Each check comes with a small before-and-after example so you know what to look for. For app-level settings such as database policies, storage buckets, webhooks and auth redirects, use our security checklist for vibe-coded apps alongside this one.

What does GitHub Copilot’s security review actually check?

Copilot code review is an AI reviewer, not a security scanner. It combines the pull request’s changes with other context such as the pull request title and body and your repository’s custom instructions, then sends that prompt to a language model. When its project-context gathering runs, it also analyzes the rest of the repository. It then posts comments tied to specific lines, each tagged High, Medium or Low severity, with suggested fixes where it can (GitHub Docs: Responsible use of Copilot agents, GitHub Docs: Using Copilot code review). GitHub lists security vulnerabilities among the issues even its fastest review level looks for, next to bugs and style problems, and its default level spends longer on security-sensitive code (GitHub Docs: Copilot code review).

What it doesn’t do is run GitHub’s rule-based security tools. Secret scanning, CodeQL code scanning and dependency review are separate features that you switch on separately, and each one is covered in the checks below. Copilot’s review also only sees what’s in the repository. Database policies, storage rules and hosting settings that live in a dashboard are outside its view.

What Copilot code review does, and what it doesn’t

Copilot code review works on pull requests on GitHub.com and on local changes in supported editors such as VS Code, Visual Studio and JetBrains IDEs, and you can apply its suggested fixes in a couple of clicks (GitHub Docs: Copilot code review). It’s worth turning on. A few details matter for security, though:

  • By default it only comments. Copilot’s review is posted as a “Comment” rather than “Approve” or “Request changes”, so out of the box it doesn’t count toward required approvals. Each Copilot review ends its overview comment with a view on whether the pull request looks ready to approve, but that assessment alone doesn’t satisfy merge rules. If admins switch on Copilot approvals, Copilot can leave an approving review that counts toward a required-approval rule the way a teammate’s would, and that approval is dismissed when new commits are pushed (GitHub Docs: Using Copilot code review). Think hard before you let a bot be the only approval on code that touches money or user data.
  • It can miss things and invent things. GitHub says Copilot won’t necessarily spot every problem, especially in large or complex changes, that it can flag issues that don’t exist, and that its own suggested fixes can be wrong or insecure. GitHub’s advice is to back it up with careful human review (GitHub Docs: Responsible use of Copilot agents).
  • It skips some files. Dependency manifests and lockfiles (package.json, for example) aren’t reviewed at all, and neither are log files or SVGs. A pull request that quietly adds a package gets no comment from Copilot on that change.
  • It reviews once unless told otherwise. Unless the repository is set to review new pushes, Copilot reviews a pull request one time. Later commits need a manual re-request.
  • Effort levels change depth. You can choose Lite, Balanced (the default) or Max, which is in public preview. GitHub points to Balanced for security-sensitive code and Max for high-risk or release-critical pull requests, and higher levels use more AI credits.

You can also steer it. Copilot code review reads repository custom instructions such as .github/copilot-instructions.md, path-specific instruction files and AGENTS.md, and it can use agent skills stored in the repository, so you can point it at your own security rules. It reads those files from the head branch (the branch with your changes), so you can try a new rule in the same pull request. Treat the result as a first pass that saves a human reviewer time, not as the review itself. Our comparison of AI code review and human review goes deeper on where each one helps.

Check 1: secrets and API keys

Copilot fills in whatever the surrounding code suggests. If a file already has a key in it, or the prompt says “connect to Stripe”, you can end up with a credential typed straight into the source.

// Before: a live key in the source file
const stripe = new Stripe("sk_live_51Hx...");

// After: read it from the server's environment
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

To find hard-coded values, search the working tree and the history, not only the current files:

git grep -n -I -E "sk_live|sk-|api[_-]?key|secret|password|token"
git log -p --all -S "sk_live"

GitHub can do this for you. Secret scanning checks the whole Git history on every branch for known credential types, and runs for free on public repositories (GitHub Docs: Secret scanning). Push protection goes a step further and blocks a push that contains a detected secret before it lands in the repository (GitHub Docs: Push protection). If a real key was ever committed, rotate it first. GitHub notes that scrubbing history is slow and often unnecessary once the credential has been revoked.

Keys in frontend variables

A Copilot suggestion that moves a key into an “environment variable” isn’t always safe. In a Vite app, anything prefixed VITE_ is baked into the JavaScript sent to the browser, and Vite’s docs say not to put API keys or other sensitive values in them (Vite: Env variables and modes).

// Before: anyone who opens DevTools can read this key
const res = await fetch("https://api.openai.com/v1/responses", {
  headers: { Authorization: `Bearer ${import.meta.env.VITE_OPENAI_KEY}` },
});

// After: the browser calls your own backend route, which holds the key
const res = await fetch("/api/summarise", { method: "POST", body });

The server route reads process.env.OPENAI_API_KEY, checks who’s calling, and makes the outside request.

Check 2: injection and string-built queries

Code that glues user input into a query string is easy for a model to produce. It works in testing and it’s open to SQL injection.

// Before: the email from the request becomes part of the SQL text
const rows = await db.query(
  `SELECT * FROM users WHERE email = '${req.body.email}'`
);

// After: a parameterised query keeps the value as data
const rows = await db.query(
  "SELECT * FROM users WHERE email = $1",
  [req.body.email]
);

OWASP’s primary recommendation is parameterised queries for data values, plus fixed, app-owned choices for anything structural such as a column to sort by, and a database account with only the rights it needs (OWASP SQL Injection Prevention Cheat Sheet). While you’re in there, look for the same pattern in other places:

  • Template strings passed to exec, spawn with shell: true, or Python’s subprocess with shell=True.
  • Raw HTML built from user input and dropped into innerHTML or React’s dangerouslySetInnerHTML.
  • An ORDER BY or table name taken straight from a query parameter. Map it through an allow-list instead:
SORTABLE = {"newest": "created_at DESC", "name": "name ASC"}
order = SORTABLE.get(request.args.get("sort"), "created_at DESC")
cur.execute(f"SELECT id, name FROM projects WHERE owner_id = %s ORDER BY {order}", (user_id,))

GitHub’s code scanning with CodeQL is designed to flag patterns like these automatically. CodeQL supports JavaScript and TypeScript, Python and several other languages, and code scanning is available on public repositories and on organisation repositories with GitHub Code Security (GitHub Docs: Code scanning with CodeQL). Copilot Autofix can then suggest fixes for its alerts (GitHub Docs: Code scanning). Read those fixes the same way you’d read any other Copilot change.

Check 3: auth and authorization gaps

This check is hard for automated tools, because the code looks correct. An endpoint can confirm that someone is signed in and still let them read or change another user’s records. OWASP calls this an insecure direct object reference: an object, a reference to it such as an ID in the URL, and no check that this user is allowed to touch it (OWASP IDOR Prevention Cheat Sheet).

// Before: logged in is enough to fetch ANY invoice by ID
app.get("/api/invoices/:id", requireLogin, async (req, res) => {
  const invoice = await Invoice.findById(req.params.id);
  res.json(invoice);
});

// After: the query is scoped to the signed-in user
app.get("/api/invoices/:id", requireLogin, async (req, res) => {
  const invoice = await Invoice.findOne({
    _id: req.params.id,
    ownerId: req.user.id,
  });
  if (!invoice) return res.status(404).end();
  res.json(invoice);
});

When you review, go route by route and ask three questions:

  1. Who is calling? Is there a real session or token check on the server, not just a hidden button in the UI?
  2. Do they own this record? Is every read, update and delete filtered by the user or team, including bulk and export endpoints?
  3. Can they change their own role? Watch for update handlers that save the whole request body, which lets someone send "role": "admin" or "plan": "pro".

The fastest real test is to sign in as two different users and try each other’s IDs. If your app uses Supabase or another backend-as-a-service, row-level policies are part of this check too, and the vibe-coded app security checklist walks through them.

Check 4: dependencies and packages that don’t exist

AI models can suggest packages that were never published. In one study of 576,000 code samples from 16 models, made-up package names averaged at least 5.2% across commercial models, versus 21.7% across open-source ones (Spracklen et al., “We Have a Package for You!”). An invented name is a trap: someone can register it and ship malware under it.

# Before installing anything Copilot added, confirm it's real
npm view some-helper-lib name version repository
pip index versions some-helper-lib

Check that each package exists, has a linked source repository and a real release history, and that the name is spelled exactly like the library you meant. Then lean on GitHub’s tools, since Copilot code review won’t comment on package.json or lockfiles:

  • Dependency review shows what a pull request adds, removes or upgrades, including indirect packages in lockfiles, and flags known vulnerabilities before you merge (GitHub Docs: Dependency review).
  • Dependabot alerts warn you when something already on your default branch has a known vulnerability, and show a fixed version when one exists (GitHub Docs: Dependabot alerts).

Agent mode and the cloud agent: reviewing big pull requests

Inline suggestions are small enough to read as you go. Agents are different. In agent mode, Copilot picks which files to change, edits them and proposes terminal commands, iterating until it thinks the task is done. By default you approve each command before it runs, though settings can allow some to run on their own (GitHub Docs: Using agent mode). On GitHub.com, you point Copilot at a repository and branch, and you can look over its proposed changes before a pull request is created (GitHub Docs: Copilot on GitHub.com).

GitHub has added some guardrails here. The cloud agent runs CodeQL, secret scanning and dependency checks on the code it writes and tries to fix what it finds, Copilot is the author of its commits with you listed as co-author, and every commit links back to the session log (GitHub Docs: Responsible use of Copilot agents). That helps, but those scans don’t understand your business rules, so an ownership check like the one in Check 3 can still be missing.

A workable routine for a large agent pull request:

  1. Read the plan and the session log first. Make sure the agent did what you asked and nothing extra.
  2. Sort the diff by risk. Start with auth, payments, database queries, migrations, config and CI files, then UI.
  3. Look for deleted checks. Watch for a failing test, lint rule or permission check that was “fixed” by removing or loosening it. Scanning the removed lines in middleware and test files is quick.
  4. Run it. Pull the branch, run the tests, and try the two-user test from Check 3.
  5. Keep it reversible. Merge in small pieces where you can. If an agent session goes wrong, the steps in our git recovery guide for AI agents get you back to a known-good commit.

Licences and the public code filter

Now and then Copilot produces code that’s identical, or nearly so, to code in a public repository. GitHub gives you a setting called “Suggestions matching public code” with two options. With Block, GitHub says that in most Copilot products it compares a suggestion plus roughly 150 characters of surrounding code against public code on GitHub and hides it if there’s a match or near match. With Allow, matching suggestions come with a note listing the public repositories involved and any licence GitHub detected (GitHub Docs: Managing Copilot policies). If your Copilot seat comes from an organisation, you inherit its setting.

Keep the limits in mind. GitHub says matches typically show up in less than 1% of inline suggestions, and the public-code index leaves out private repositories and anything hosted outside GitHub (GitHub Docs: Copilot in IDEs). Even with Block set, code from the cloud agent or Copilot CLI may still match public code. For the cloud agent, matches are listed in the session log.

When to get a human review

Copilot’s review, CodeQL, secret scanning and Dependabot each cover a different slice of the risk, and they’re quick to turn on. What they can’t do is know that invoices belong to teams rather than users, that a coupon shouldn’t stack, or that one admin route was meant to be internal. Get a person to look when:

  • The code deals with payments, medical records or other users’ personal details.
  • An agent opened a pull request bigger than you can read in one sitting.
  • You found a live key in the history and can’t tell where else it was copied.
  • Copilot’s review came back clean but nobody has tried the app as two different users.

For the rest of the launch list, such as backups, monitoring and error handling, see our production readiness guide for AI-built apps.

If that sounds like your project, a vetted senior engineer can do a security pass on your Copilot-written code, fix what they find, and walk you through every change. Fixed price, agreed upfront. Start at /fix/github-copilot.

FAQ

Is Copilot-generated code secure?

You can’t assume it. GitHub’s terms state that output may contain vulnerabilities and that reviewing and testing it is your job. Run the four checks above on anything that touches auth, data or money, and turn on code scanning, secret scanning and Dependabot for the repository.

Is Copilot’s security review enough before launch?

No. GitHub’s own guidance is to treat it as a supplement to careful human review, because it may not find every problem, especially in large or complex changes, and it can report problems that aren’t there (GitHub Docs: Responsible use of Copilot agents). Before launch, add secret scanning, code scanning and dependency review, test the app signed in as two different users, and check the settings that live outside your code using the vibe-coded app security checklist.

Does Copilot security review catch exposed API keys or missing RLS policies?

Not reliably. A key typed into a changed line may draw a comment, but there’s no promise it will, and Copilot code review skips some file types entirely. Secret scanning is the GitHub feature built for keys: it checks the full history on every branch, and push protection stops new ones at push time. Row-level security (RLS) policies are a bigger blind spot. Supabase’s docs have you enable RLS and write policies as SQL in the SQL Editor in the Supabase Dashboard or with psql over a direct connection (Supabase Docs: Row Level Security). If that SQL never made it into a migration file in your repository, the review has nothing to read. Our guide to Supabase RLS policies shows how to check them directly.

Does Copilot code review replace a human reviewer?

No. GitHub’s own docs describe it as a supplement: it can miss problems, flag ones that aren’t real, and suggest fixes that are themselves wrong. By default it leaves comments only and doesn’t count as an approval. Use it to clear the obvious issues so a human can spend their time on logic and access control.

How do I find hard-coded API keys in my repo?

Search the current files and the history with git grep and git log -S, and turn on GitHub secret scanning, which checks the full history on all branches. Add push protection so new secrets get blocked before they’re pushed. Rotate every key that has ever been committed, even if the line is gone now.

Who owns code that Copilot writes?

This is a short summary, not legal advice. GitHub’s Terms of Service say GitHub doesn’t claim ownership of your inputs or Copilot’s output. The same section warns that output may resemble code under third-party copyright or open-source licences, and that it’s up to you to work out whether you need a licence and to follow it. If ownership matters for a sale, a client contract or an investor, ask a lawyer. If your organisation’s use of GitHub falls under a GitHub Customer Agreement or a volume licensing agreement, the terms say that agreement controls how your data is used with AI features.

Should I turn on the public code filter?

If you’re worried about licence questions, setting “Suggestions matching public code” to Block is a sensible default, and it’s the stricter of the two options. It doesn’t cover everything: it only compares against public code on GitHub, and agent-generated code can still match. If you choose Allow, check the references Copilot shows and keep any licence notices the matching project requires.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.