TL;DR
Researchers have developed a new two-stage framework to extract memorized secrets, like API keys, from "black-box" LLMs where only the text output is visible. By distilling a victim model's behavior into a local white-box proxy and applying clever statistical filters, they successfully recovered authentic credentials from commercial systems like OpenAI and Claude Code with significantly higher efficiency than previous methods.
What Problem Does This Paper Address?
Large Language Models (LLMs) are often trained on massive scrapes of public code repositories (like GitHub), which unfortunately contain hard-coded secrets—API keys, private tokens, and credentials. Because LLMs are prone to memorization, they can inadvertently "leak" these secrets when prompted with the right context.
Previous research into secret extraction mostly focused on "white-box" scenarios, where the attacker has access to the model's internal weights or token probability distributions. However, most commercial LLMs (like GPT-4 or Claude) are "black-boxes" accessed via APIs that only return text. The challenge addressed here is: Can we practically extract high-entropy, format-constrained secrets from an LLM when we can only see its final text output?
Methods
The authors propose a two-stage framework designed to overcome the lack of internal model access and the high cost of repeated API queries.
1. Cross-Validated Secret Knowledge Distillation
First, the attacker elicits potential secrets from the black-box "victim" model. Since the exact code context that caused the original memorization is unknown, the authors use Prefix Perturbation—generating many semantic variants of a standard API call (e.g., changing whitespace, renaming variables, or adding comments).
The responses are passed through a Secret API Filter to remove obvious junk based on provider-specific formats (like length and character sets). These validated pairs are then used to fine-tune a smaller, local white-box proxy model. This "distills" the victim's memorized knowledge into a model the attacker fully controls.
2. Proxy-Guided Extraction and Filtering
With a local proxy in hand, the attacker can perform an unlimited, diverse search for candidates using truncated top-p sampling. To separate real keys from "hallucinations" (fake keys generated by the model), they apply two novel statistical filters:
- Minimum-Window Entropy Screening: Real API keys are high-entropy throughout. Hallucinations often contain "collapsed" regions with low randomness.
- Repeated-Substring Suppression: Models often get stuck in loops when hallucinating. This filter prunes candidates that repeat 4-gram sequences more than twice.
Datasets
The study utilized a controlled benchmark and a real-world evaluation:
- Controlled Benchmark: 500 authentic API keys from five providers (OpenAI, Google, DeepSeek, OpenRouter, and Stripe) across four programming languages (Python, Java, JavaScript, PHP).
- Victim Models: Fine-tuned versions of DeepSeek-Coder-7B, LLaMA-3-8B, and Qwen2.5-Coder-7B to simulate real-world training on sensitive data.
- Proxy Models: StarCoder2-7B and Seed-Coder-8B.
- Real-World Targets: Masked credentials were recovered from three independently deployed systems, including OpenAI and Claude Code.
Key Insights and Ideas
- The Proxy Advantage: The most significant "aha moment" is that you don't need to query the expensive black-box API thousands of times to find a secret. You only need enough queries to build a local proxy that "mimics" the victim's memorization patterns.
- Hallucination Signatures: Hallucinated secrets aren't just random; they have distinct statistical signatures. As shown in Figure 2, fake keys are much more likely to have repetitive n-grams and low local entropy compared to genuine, high-entropy cryptographic keys.
- Context Matters: No single prompt variant is best. Combining different types of code perturbations (like changing variable names vs. adding dead code) is essential to "triggering" the specific context the model memorized during training.
Key Results
- Effectiveness: The framework improved the number of recovered real secrets by 11.8% to 25.0% compared to direct-query baselines.
- Efficiency: By moving the heavy lifting (candidate generation and filtering) offline to the local proxy, the authors achieved a 20.7x to 34.8x reduction in latency compared to DESEC, a state-of-the-art white-box baseline.
- Real-World Impact: The researchers successfully recovered masked, provider-specific credentials from commercial black-box LLMs, proving that output-only access is a viable path for attackers to uncover sensitive data.
Limitations and Future Work
- Prefix Dependency: The attack still requires a "canonical invocation snippet"—the attacker needs to know generally how the API is called to craft the initial prompts.
- Probabilistic Nature: Like all extraction attacks, this is not guaranteed; it relies on the model having memorized the data strongly enough to be elicited.
- Defense Research: The authors suggest that this work should motivate stricter pre-training data cleaning and the development of better "unlearning" techniques to prevent LLMs from memorizing secrets in the first place.
Summary updated