Gotcha! This Model Uses My Code! Evaluating Membership Leakage Risks in Code Models

Zhou Yang, Zhipeng Zhao, Chenyu Wang, Jieke Shi, Dongsun Kim, DongGyun Han, David Lo

TL;DR

Researchers have developed GOTCHA, a high-precision attack that can determine if a specific piece of code was used to train a large language model for code (like CodeGPT). The study reveals that code models are highly vulnerable to "membership leakage," achieving an alarming 95% success rate in identifying training data, which raises significant concerns for intellectual property and data privacy in software engineering.

What Problem Does This Paper Address?

As AI-powered coding assistants like GitHub Copilot and Amazon CodeWhisperer become ubiquitous, they are trained on massive datasets including open-source repositories and private corporate code. This raises a critical privacy question: Can an attacker figure out if your private or proprietary code was used to train a specific model?

This is known as a Membership Inference Attack (MIA). If a model "memorizes" its training data too well, it might inadvertently leak sensitive information like API keys, proprietary algorithms, or even security vulnerabilities present in the original source. While MIA has been studied in natural language processing, its impact on code-specific models—which handle structured, logical data—was previously an underexplored "blind spot."

Methods

The authors introduce GOTCHA, a novel MIA framework designed specifically for code completion models. The attack operates in a "black-box" setting, meaning the attacker doesn't need to know the model's internal weights, only its outputs.

The core of GOTCHA involves:

  1. Surrogate Modeling: The attacker trains a "shadow" or surrogate model on a small portion of known data to mimic the behavior of the target (victim) model.
  2. Feature Extraction: Unlike previous attacks that relied on simple statistics, GOTCHA uses CodeBERT to convert three types of information into high-dimensional embeddings:
  3. Model Input: The code prefix.
  4. Model Output: The code the model predicts.
  5. Ground Truth: The actual code that followed the prefix in the dataset.
  6. Binary Classification: A final classifier is trained on these embeddings to distinguish between "member" (used in training) and "non-member" (unseen) code snippets.

Datasets

The study primarily uses the JavaCorpus dataset, a collection of over 14,000 Java projects from GitHub.

  • Victim Models: The researchers evaluated the attack on several popular open-source models, including CodeGPT, CodeGen, CodeParrot, GPT-Neo, and PolyCoder.
  • Fine-tuning: The models were fine-tuned on a 1% subset of JavaCorpus to simulate real-world specialized code models.

Key Insights and Ideas

  • The "Output" is the Smoking Gun: Through an ablation study, the researchers found that the model's output is the most critical factor for a successful attack. If a model reproduces a complex code snippet exactly as it appeared in the training set, it’s a strong signal of membership.
  • Architecture Matters: The attack is most effective when the attacker’s surrogate model shares the same architecture as the victim model. If you know the victim is a Transformer-based model, using a Transformer surrogate significantly boosts your "guessing" power.
  • Perplexity as a Proxy: Successfully attacked code snippets usually have much lower perplexity (a measure of how "surprised" a model is by a sequence). Essentially, if the model finds the code very "predictable," it has likely seen it before.
  • Decoding as a Defense: The way a model chooses its next token (decoding strategy) affects its vulnerability. Standard beam search (which picks the most likely sequence) is highly vulnerable, while top-k sampling (which introduces randomness) can mitigate the risk of leakage by about 40%, albeit with a slight potential hit to code quality.

Key Results

GOTCHA significantly outperforms existing baseline attacks, which often performed no better than a coin flip (random guessing).

  • High Precision: On the CodeGPT model, GOTCHA achieved a True Positive Rate (TPR) of 0.95 with a low False Positive Rate (FPR) of 0.10.
  • Overall Performance: The attack reached an AUC-ROC of 0.98, indicating near-perfect ability to distinguish between training data and unseen data.
  • Generalizability: The attack remained highly effective (AUC > 0.92) across five different model architectures, proving that membership leakage is a systemic issue in current code LLMs.

Limitations and Future Work

The authors acknowledge several areas for further exploration:

  • Language Specificity: The current evaluation is focused on Java. While the method is "language-agnostic," results might vary for languages with different structural properties (e.g., Python or C++).
  • Static vs. Dynamic Models: The study looks at static, fine-tuned models. In the real world, models are often updated or retrained continuously, which might complicate the attack.
  • Defense Development: While the paper suggests top-k sampling as a defense, the authors call for more robust, dedicated defensive mechanisms (like Differential Privacy) specifically tailored for code generation tasks.

This research serves as a "wake-up call" for developers and companies to be more cautious about the data they use to train models and the potential for that data to be "unmasked" by malicious actors.

Summary updated

BibTeX
@article{yang2024gotcha,
  author = {Zhou Yang and Zhipeng Zhao and Chenyu Wang and Jieke Shi and Dongsun Kim and DongGyun Han and David Lo},
  title = {{Gotcha! This Model Uses My Code! Evaluating Membership Leakage Risks in Code Models}},
  journal = {IEEE Trans. Software Eng.},
  year = {2024},
  doi = {10.1109/tse.2024.3482719},
}
Figure