GitHub Copilot security used to mean one question: is the suggested code safe? Today Copilot also runs shell commands, opens pull requests, reads issues and installs packages on its own. Every one of those actions happens with your permissions, and every one is a new way in for an attacker.
The numbers show the shift. In 2025 and 2026, researchers disclosed a critical flaw that let a hidden prompt in a pull request leak private code through Copilot Chat, and command injection bugs in the Copilot CLI and the JetBrains plugin. Repositories that use Copilot also leak secrets more often than the average. None of this means you should switch Copilot off. It means you need controls that work at the same speed as the assistant.
TL; DR
GitHub Copilot security: from code suggestions to an assistant that acts
GitHub Copilot no longer just suggests code. It runs commands, opens pull requests and installs packages with your permissions, so GitHub Copilot security now means controlling what it does, not only what it writes.
- Prompt injection is real: CamoLeak (CVSS 9.6) used a hidden comment in a pull request to make Copilot Chat leak private code and secrets.
- Agents can execute: in 2026, command injection flaws hit the Copilot CLI (
CVE-2026-29783) and the JetBrains plugin (CVE-2026-21516). Both are fixed, but only once you upgrade. - Secrets leak more: GitGuardian found a 6.4% secret leakage rate in public repositories that use Copilot, about 40% higher than the average.
- Packages that don't exist: 19.7% of AI-generated code samples in a USENIX study referenced at least one hallucinated package, a gap attackers fill with malicious lookalikes.
- Built-in controls have limits: GitHub's dependency checks rely on known advisories, and much of the cloud agent's protection can be disabled. Code from the IDE and agent mode needs its own checks.
Det første steget: scan AI-written code before it is committed, block secrets and malicious packages at the source, and give Copilot's agents only the access they need.
Why GitHub Copilot security is a different problem now
Copilot is no longer one product. It is a family of tools, and each one carries a different level of risk:
One name, five Copilot surfaces
The more Copilot can do on its own, the more GitHub Copilot security depends on controlling its actions.
| Copilot surface | Hva det kan gjøre | Main security question |
|---|---|---|
| Code completion in the IDE Autonomy: low | Suggests code as you type | Is the suggested code secure, and does it add risky dependencies? |
| Copilot Chat Autonomy: low to medium | Answers questions using your repository and issues as context | Can hidden text in that context steer what it reveals? |
| Agent mode in the IDE Autonomy: medium | Edits files, runs terminal commands, calls MCP tools | What can it execute without asking you? |
| Copilot CLI Autonomy: high | Runs shell commands from natural language | Can a crafted command slip past its safety checks? |
| Cloud coding agent Autonomy: very high | Works on issues in GitHub Actions and opens pull requests | What can it reach, push and install while nobody watches? |
The pattern is clear: Copilot security in the IDE used to be a code review problem. With agents, it is also an identity and permissions problem. An assistant that acts with a developer’s tokens, network access, and repository rights is a privileged user, and it needs to be treated like one.
Gå dypere: Se vår SafeDev Talk Blast Radius: Når agenten berører det du ikke ba om, om hva som skjer når en agents tillatelser går lenger enn oppgaven dens.
The 5 biggest GitHub Copilot security risks
1. Prompt injection through your own repositories
Copilot reads issues, pull requests, comments, and files to build its context. An attacker who can write text there can try to steer it. In CamoLeak, a hidden comment in a pull request description made Copilot Chat search the victim’s private repositories, encode what it found and leak it through image URLs, character by character. The researcher demonstrated the theft of an undisclosed zero-day and searched for AWS_KEY values. Legit Security rated it CVSS 9.6, and GitHub fixed it by disabling image rendering in Copilot Chat.
2. Command execution in agents and plugins
When Copilot can run commands, a crafted input can become code execution:
- CVE-2026-29783 (CVSS 7.5): crafted bash parameter expansions let commands in the Copilot CLI pass as read-only and run without approval. Fixed in version 0.0.423 (GitHub-veiledning).
- CVE-2026-21516 (CVSS 8.8): Copilot for JetBrains passed model suggestions into command construction without sanitizing shell characters, so instructions hidden in a repository or an MCP endpoint could lead to execution. Fixed in version 1.5.63 (analyse).
3. Secrets in AI-written code
Assistants reproduce what they see, including hardcoded credentials. GitGuardian’s State of Secrets Sprawl report found a 6.4% secret leakage rate in public repositories that use Copilot, about 40% higher than the average across public repositories (GitGuardian). One leaked token is enough to turn a code review gap into an account takeover.
4. Hallucinated and malicious packages
Code generators sometimes import packages that don’t exist. A USENIX Security 2025 study of 2.23 million samples from 16 models found that 19.7% contained at least one hallucinated package, with 205,474 unique fabricated names. 43% of those names came back on every run, which makes them easy for attackers to predict and register, a technique known as hukebukk. In agent mode, Copilot can install that package itself. We explain the attack in detail in Slopsquatting: Hvordan angripere bevæpner AI-hallusinasjoner.
5. Insecure patterns at scale
Copilot learns from public code, and public code is full of SQL injection, weak crypto, and missing authorization checks. Research cited across the industry estimates that around 40% of AI-generated code can contain security vulnerabilities. The problem is not that each suggestion is worse than human code. It is the volume: more code, written faster, reviewed less.
What GitHub’s built-in controls cover, and what they leave open
GitHub has added real safeguards, especially to the cloud coding agent. According to its risks and mitigations documentation, the agent works behind a firewall that restricts internet access, pushes only to its own copilot/ branch, cannot approve or merge its own pull requests, and needs a human to approve workflow runs. Its output is checked with CodeQL, secret scanning, and a dependency check against the GitHub Advisory Database.
Those are good defaults. But a GitHub Copilot security strategy should not stop there:
GitHub's built-in Copilot controls: covered and left open
GitHub secures what Copilot does inside GitHub. Your team still owns the rest of GitHub Copilot security.
In short: GitHub secures what Copilot does inside GitHub. Your team still owns what Copilot writes in the IDE, what it installs on laptops, and what reaches your pipeline.
How to secure GitHub Copilot in 7 steps
Here is a practical checklist to improve GitHub Copilot security without slowing your developers down.
- Keep every Copilot component updated. Patch the IDE extensions, the JetBrains plugin, and the Copilot CLI quickly. Several 2026 fixes, such as CVE-2026-29783 and CVE-2026-21516, only protect you once you upgrade.
- Scan AI-written code before it is committed. Kjør SAST, secrets detection, and dependency checks in the IDE and inside the agent’s loop, not only in CI weeks later. A fix is cheapest while the change is still in the editor.
- Block secrets at the source. Enable push protection, keep credentials in a secrets manager, and use short-lived, narrowly scoped tokens. Rotate any credential that ends up in code, even in a private repository.
- Verify every new dependency. Check that a package exists, how old it is, and who publishes it before installing it. Set a minimum age for new versions, and block packages flagged as malicious, whether a developer or an agent runs the install.
- Limit what agents can run and reach. Review what agent mode and the CLI may execute without approval, keep the cloud agent’s firewall on, and grant MCP servers only the tools they need.
- Treat repository text as untrusted input. Problemer, pull request descriptions, and comments can carry hidden instructions. Be careful when asking Copilot to act on content written by people outside your team.
- Exclude sensitive files and keep humans on merges. Use content exclusion for files Copilot should never read, require reviews on protected branches, and never let an agent approve its own changes.
Keep Copilot fast, and keep it in check
GitHub Copilot security is not about trusting the assistant less. It is about checking its work at the same speed it produces it: in the editor, inside the agent’s loop, and at the moment a package is installed.
That is exactly what Xygeni is built for. The Xygeni MCP Server works with any AI coding agent that supports MCP, including GitHub Copilot agent mode, so Copilot can scan the code it just wrote with AI SAST, get AI Triage verdicts, and request fixes before anything is committed, with the approvals your team sets. The Xygeni IDE plugins bring the same findings to developers in VS Code, JetBrains IDEs, and Visual Studio. Hemmeligheter Sikkerhet catches hardcoded credentials, and Forsvar mot skadelig programvare flags malicious packages before a signature exists, whether they are installed by a developer or Copilot.
Want to see it with your own code? Start gratis:AI SAST, the IDE plugins, and malware detection on open-source packages, no credit card required.
GitHub Copilot security FAQs
Is GitHub Copilot safe to use?
Yes, with controls in place. The main risks are insecure suggestions, leaked secrets, hallucinated or malicious packages, and prompt injection through repository content. Scanning AI-written code before commit, blocking secrets, and verifying new dependencies address most of them.
Does GitHub Copilot leak secrets?
It can reproduce or introduce hardcoded credentials. GitGuardian found a 6.4% secret leakage rate in public repositories that use Copilot, about 40% higher than average. Push protection, secrets detection in the IDE, and short-lived tokens reduce the risk.
Can GitHub Copilot be hit by prompt injection?
Yes. CamoLeak showed that a hidden comment in a pull request could make Copilot Chat leak private code. GitHub fixed that case, but any assistant that reads untrusted text can be steered, so treat issues, comments, and pull request descriptions as untrusted input.
What is the difference between Copilot security and Microsoft 365 Copilot security?
Microsoft 365 Copilot security is about protecting business data in documents, email, and SharePoint. GitHub Copilot security is about the code, commands, and dependencies an AI coding assistant produces in your development workflow.
How do I scan code written by GitHub Copilot?
Run security scans in the IDE and connect a security tool to Copilot’s agent mode through MCP, so the agent checks its own code before commit. Keep the same scans in CI so every change meets the same policies.







