GitHub Copilot induced to disclose real hard-coded secrets via redaction prompts
CUHK researchers showed Copilot can reconstruct real secrets from redacted public GitHub code; 6.4% of sampled Copilot-active repos leaked live credentials completable via masked prompts.
Description
Researchers at the Chinese University of Hong Kong demonstrated that GitHub Copilot could be induced to reproduce verbatim hard-coded credentials (API keys, tokens, passwords) present in its training data by prompting it to complete redacted portions of public source files. In a sample of ~20,000 repositories where Copilot was active, over 1,200 (6.4%) leaked at least one secret via this technique — a 40% higher incidence than the base rate of public-repo secret leakage. The finding confirmed that LLM code-completion tools can act as a secondary exfiltration channel for credentials independent of any live-system compromise.
Exhibited failure modes
- Security vulnerability — Insecure patterns, injection flaws, weak cryptography, secret leakage.
- Context pollution — Trajectory drift, hallucination spirals, overlong or off-task context.
Affected systems
- GitHub Copilot
Mitigated by
- Semgrep — Fast, rule-based static analysis with a pattern syntax that mirrors source code.
- Snyk — Vulnerability scanning for code, dependencies, containers, and IaC.
Sources
Notes
Date approximate (month of public write-up). Mitigations cite tools whose rules catch committed credentials pre-merge — not tools that prevent the model from emitting a secret at completion time. The latter is a training-data problem the KG does not yet model.