Abstract
Neural Code Completion Tools (NCCTs) have reshaped software engineering by accurately suggesting contextually relevant code snippets. However, these models may emit training data verbatim during inference, raising significant privacy concerns regarding hard-coded credential leakage. We propose the Hard-coded Credential Revealer (HCR), an evaluation tool that constructs test prompts from GitHub code files to identify memorization in NCCTs. HCR utilizes four filters to identify ill-formatted credentials and checks the validity of non-sensitive credentials. Our evaluation of commercial NCCTs, open-source models, and chatbots reveals that these tools can leak precise training data and additional secret strings. Notably, we identified two valid credentials during our experiments, highlighting a severe privacy risk in the training data of commercial NCCTs.
Introduction: The Threat of Memorization
As AI-driven productivity tools like GitHub Copilot and Amazon CodeWhisperer become standard in software development, they bring a hidden security risk. These tools are built on Large Language Models (LLMs) that act as "sponges," memorizing snippets of their training data. This phenomenon, known as verbatim emission, can lead to the accidental disclosure of sensitive information.
This paper addresses the high-stakes risk of hard-coded credentials (CWE-798). If a developer committed an API key to a public repository that was later used for training, an adversary could potentially "prompt" the AI to reveal that secret, gaining unauthorized access to systems or networks.
Methodology: The HCR Framework
To systematically evaluate this risk, we developed the Hard-coded Credential Revealer (HCR). HCR operates through a five-phase pipeline designed to extract and validate secrets from NCCTs.
- Identification: Selection of 18 representative secret types (e.g., AWS, GitHub, Stripe).
- Regex Design: Creation of precise regular expressions to define secret formats.
- Prompt Construction: HCR scrapes real-world code contexts from GitHub, "hollowing out" existing secrets to create prompts that mimic natural development environments.
- Querying: Testing across six major NCCTs, including commercial tools (Copilot), open-source models (Code Llama), and chatbots (ChatGPT).
- Validation: A multi-stage filtering process (Regex, Entropy, Pattern, and Word filters) separates "hallucinations" from plausible secrets, followed by API-based validity checking.
Experimental Setup and Datasets
The study utilized a custom-built prompt set derived from GitHub, consisting of 900 unique prompts (50 per secret type) across 10 programming languages. By using real-world code context, the prompts ensure that the evaluation mimics the exact environments where secrets are typically found.
Key Insights: Strong vs. Weak Memorization
Our analysis distinguishes between two types of leakage:
- Strong Memorization: The AI reproduces the secret alongside its original training context.
- Weak Memorization: The AI suggests a real secret within a new or different context. This is particularly concerning as it suggests secrets are stored within the model's weights and can be triggered by any relevant code pattern.
We also found a correlation between model confidence and plausibility; "Top-1" suggestions in tools like Copilot had higher rates of plausible secrets. Furthermore, while safety alignments in chatbots often block secret generation, they can be bypassed through specific instruction tuning (e.g., asking the model to "make the code runnable").
Results: Real-World Impact
The experimental results confirm that memorization is pervasive across all tested models. Key findings include:
- Valid Leaks: We successfully extracted two valid Stripe test secret keys that passed authentication.
- High Plausibility: Gemini demonstrated a Plausible Rate (PR) of 0.81 for certain prompts, meaning 81% of its suggestions resembled real credentials.
- Defense Limitations: Existing "public code blocking" features in commercial tools failed to stop all leaks, particularly those resulting from "weakly memorized" secrets where the surrounding code did not perfectly match the training data.
Conclusion and Future Work
HCR demonstrates that NCCTs pose a genuine threat to credential security. While this study focused on 18 secret types, the true scope of the risk is likely much larger. Future research should focus on "Machine Unlearning" to help models forget sensitive data points and the development of more robust post-processing filters to prevent the emission of memorized secrets.
Summary updated