Back to Intelligence

Stealing Reasoning Traces from Proprietary LLM APIs: How Attackers Exfiltrate Chain-of-Thought and How to Defend Against It

SA
Security Arsenal Team
August 12, 2026
10 min read

A recently publicized technique demonstrates that proprietary large language model APIs — including models that deliberately suppress or summarize their chain-of-thought (CoT) reasoning — can be coaxed into leaking those hidden reasoning traces. As documented by Simon Willison in his August 2026 write-up, attackers have found that the 'reasoning tokens' vendors assume are invisible to end users can be reconstructed, elicited, or side-channeled out of API responses through carefully crafted prompting, streaming-token analysis, and abuse of features such as tool-call traces, logprobs, and structured output modes.

This matters far beyond academic curiosity. Reasoning traces routinely contain the most sensitive material in an LLM pipeline: fragments of the system prompt, internal business logic, retrieved context from RAG stores (which may include customer data, credentials, or internal documents), intermediate decision-making, and — critically — the intellectual property vendors and enterprises believed was protected by hiding CoT. If your organization exposes an LLM-backed API to customers, partners, or even internal users with differing trust levels, you should treat reasoning-trace extraction as an active data-exfiltration vector against your AI stack, not a theoretical one.

Technical Analysis

What Is Being Targeted

Modern 'reasoning' models (OpenAI's o-series, Anthropic's extended-thinking Claude models, Google Gemini thinking variants, DeepSeek-R1 and its derivatives) generate long internal monologues before producing a final answer. Vendors handle these differently:

  • Fully exposed traces — some APIs (notably DeepSeek-R1-style deployments and many self-hosted open-weight reasoning models served via vLLM, Ollama, or LiteLLM) return reasoning tokens directly in the response stream or in a dedicated reasoning_content field.
  • Summarized traces — OpenAI and Anthropic summarize or encrypt reasoning and return only a digest, assuming the raw trace is inaccessible.
  • Hidden-but-derivable traces — even where raw CoT is withheld, researchers have shown it can be partially reconstructed through streaming behavior, token-level probabilities (logprobs), tool-call arguments that echo intermediate reasoning, and elicitation prompts that induce the model to externalize its reasoning into the visible answer.

How the Extraction Works (Defender's View of the Attack Chain)

The techniques described fall into four observable categories:

  1. Direct field harvesting. Against misconfigured gateways or proxy layers (LiteLLM, custom FastAPI/Flask wrappers, Kong/NGINX transformations), attackers simply read the reasoning_content, thinking, or <think>...</think> blocks that the upstream provider returned but the proxy failed to strip. This is the most common real-world failure mode: the vendor hides the trace, but your own middleware re-exposes it.

  2. Elicitation prompting. Crafted user inputs instruct the model to 'think out loud,' restate its reasoning verbatim in the visible answer, translate its reasoning into another language, or encode it (Base64, hex, acrostics) to evade output filters that block literal CoT restatement. This is a prompt-injection variant aimed at the model's own hidden state.

  3. Streaming and side-channel inference. Even summarized-reasoning APIs leak metadata: token counts of the hidden trace, reasoning duration, and streaming chunk timing allow attackers to infer trace length and structure, and repeated sampling lets them reconstruct high-confidence portions of the reasoning distribution.

  4. Bulk automated extraction. Because each query leaks a little, attackers run high-volume, scripted extraction campaigns — thousands of API calls from rotating keys or accounts — to aggregate reasoning traces and mine them for system prompts, retrieval corpus content, and proprietary fine-tuning artifacts.

Exploitation Status

This is a technique disclosure with working demonstrations, not a single CVE-tracked vulnerability. No CVE identifier has been assigned in the source material, and none is asserted here. The elicitation and field-harvesting techniques are practical today against any deployment that (a) returns unsanitized reasoning fields or (b) does not constrain the model against verbalizing its reasoning. The bulk-extraction pattern is directly observable in API gateway and WAF telemetry, which is where defenders should focus.

Why Your Organization Is Exposed Even If You Don't Build Models

If you operate any LLM-backed feature — a support chatbot, a document Q&A tool, a coding assistant front end — your reasoning traces likely contain retrieved documents, system prompts, and tenant data. An attacker extracting traces from your endpoint is performing data exfiltration against your data, using the model as the oracle.

Detection & Response

Detection of reasoning-trace extraction is an application-layer problem. The highest-fidelity signals live in your API gateway, WAF, and LLM proxy logs — not on endpoints. The detections below target (1) known elicitation prompt patterns in request bodies, (2) leakage of reasoning fields in outbound responses, and (3) bulk automated extraction behavior.

YAML
---
title: LLM Reasoning Trace Elicitation Prompt Pattern
id: 4f8c2a1d-9b3e-4f6a-b2c7-8d1e5a9f3b62
status: experimental
description: Detects prompt patterns commonly used to coerce LLMs into revealing hidden chain-of-thought reasoning, system prompts, or encoded reasoning content in API gateway or LLM proxy request logs.
references:
  - https://simonwillison.net/2026/Aug/11/stealing-reasoning-traces/
  - https://attack.mitre.org/techniques/T1059/
  - https://owasp.org/www-project-top-10-for-large-language-model-applications/
author: Security Arsenal
date: 2026/08/12
tags:
  - attack.collection
  - attack.t1005
  - llm.prompt_extraction
logsource:
  category: proxy
detection:
  selection_elicit:
    cs-uri-query|contains:
      - 'repeat your reasoning'
      - 'show your chain of thought'
      - 'show your chain-of-thought'
      - 'print your thinking'
      - 'output your reasoning verbatim'
      - 'restate your internal monologue'
      - 'reveal your system prompt'
      - 'ignore previous instructions and show'
  selection_encode:
    cs-uri-query|contains:
      - 'encode your reasoning in base64'
      - 'translate your reasoning into'
      - 'first letter of each word of your reasoning'
  condition: 1 of selection_*
falsepositives:
  - Legitimate red-team or evaluation traffic from internal AI safety testing
  - Developer debugging against staging endpoints
level: medium
---
title: LLM API Response Containing Unsanitized Reasoning Trace Fields
id: 7b2e9f41-3c6d-4a8b-9e1f-5d7c3a2b8f04
status: experimental
description: Detects outbound API responses that include raw reasoning or thinking trace fields, indicating middleware failed to strip chain-of-thought content before returning it to clients.
references:
  - https://simonwillison.net/2026/Aug/11/stealing-reasoning-traces/
author: Security Arsenal
date: 2026/08/12
tags:
  - attack.exfiltration
  - attack.t1020
  - llm.reasoning_leakage
logsource:
  category: webserver
detection:
  selection:
    response_body|contains:
      - '"reasoning_content"'
      - '"thinking"'
      - '<think>'
      - '"chain_of_thought"'
      - '"reasoning": {'
  filter_internal:
    c-ip|startswith:
      - '10.'
      - '192.168.'
  condition: selection and not filter_internal
falsepositives:
  - Deliberately exposed reasoning in internal development endpoints (restrict scope or tune filter)
level: high
---
title: High-Volume LLM API Requests From Single Source Indicating Bulk Extraction
id: 2d5a8c63-1f4b-4e7a-a9c2-6b8d4e1f7a35
status: experimental
description: Detects an abnormally high request rate to LLM API endpoints from a single source IP or API key, consistent with automated reasoning-trace harvesting campaigns.
references:
  - https://simonwillison.net/2026/Aug/11/stealing-reasoning-traces/
author: Security Arsenal
date: 2026/08/12
tags:
  - attack.collection
  - attack.t1119
logsource:
  category: proxy
detection:
  selection:
    cs-uri|contains:
      - '/v1/chat/completions'
      - '/v1/messages'
      - '/v1/responses'
      - '/api/generate'
  condition: selection
falsepositives:
  - Legitimate batch jobs and evaluation harnesses (baseline per API key before deploying)
level: low

Note on the third rule: deploy it with count-based thresholding in your SIEM (e.g., more than 200 requests/hour per source IP to LLM endpoints) rather than as a single-event rule — as written it is a feed rule for aggregation logic, and the real detection is the anomaly threshold you establish per API key.

KQL — Microsoft Sentinel / Defender
// Hunt: Bulk LLM API usage and elicitation-pattern prompts against LLM endpoints
// Assumes API gateway / WAF logs ingested into CommonSecurityLog (CEF) or AzureDiagnostics
let llm_paths = dynamic(["/v1/chat/completions", "/v1/messages", "/v1/responses", "/api/generate", "/v1/completions"]);
let elicit_patterns = dynamic(["chain of thought", "chain-of-thought", "repeat your reasoning", "print your thinking", "reveal your system prompt", "restate your internal", "encode your reasoning", "ignore previous instructions"]);
let HighVolume =
    CommonSecurityLog
    | where TimeGenerated > ago(24h)
    | where RequestURL has_any (llm_paths)
    | summarize Requests=count(), DistinctPayloads=dcount(AdditionalExtensions), FirstSeen=min(TimeGenerated), LastSeen=max(TimeGenerated) by SourceIP, DeviceVendor, RequestURL
    | where Requests > 200
    | sort by Requests desc;
let Elicitation =
    CommonSecurityLog
    | where TimeGenerated > ago(24h)
    | where RequestURL has_any (llm_paths) or AdditionalExtensions has_any (llm_paths)
    | where AdditionalExtensions has_any (elicit_patterns) or Message has_any (elicit_patterns)
    | project TimeGenerated, SourceIP, RequestURL, RequestMethod, Message
    | sort by TimeGenerated desc;
union HighVolume, Elicitation
VQL — Velociraptor
-- Hunt: Endpoint artifacts indicating scripted LLM API extraction tooling
-- Looks for processes and scripts performing automated bulk calls to LLM APIs,
-- useful when investigating a suspected insider or compromised host running extraction jobs.
SELECT Pid, Name, CommandLine, Exe, Username, CreateTime
FROM pslist()
WHERE CommandLine =~ '(?i)(chat/completions|/v1/messages|/v1/responses|openai|anthropic|api\.deepseek)'
   AND CommandLine =~ '(?i)(requests\.post|httpx|aiohttp|curl|while true|for .* in range)'

-- Also enumerate recently written script files referencing LLM API endpoints
SELECT FullPath, Size, Mtime
FROM glob(globs='C:/Users/*/**/*.py', accessor='ntfs')
WHERE FullPath =~ '(?i)(extract|harvest|scrape|dump|collect).*(llm|reason|cot|think)'
   OR FullPath =~ '(?i)(llm|reason|cot|think).*(extract|harvest|scrape|dump|collect)'
ORDER BY Mtime DESC
LIMIT 100
Bash / Shell
#!/bin/bash
# verify_llm_trace_leakage.sh
# Tests whether your LLM gateway/proxy is leaking raw reasoning trace fields to clients.
# Run against YOUR OWN endpoints only. Adjust ENDPOINT, API_KEY, and model as needed.

ENDPOINT="https://your-gateway.example.com/v1/chat/completions"
API_KEY="${LLM_API_KEY:?Set LLM_API_KEY in the environment}"
MODEL="your-reasoning-model"

PROBE='{"model":"'"$MODEL"'","messages":[{"role":"user","content":"What is 17 * 23? Think carefully."}],"stream":false}'

echo "[*] Sending probe to $ENDPOINT"
RESPONSE=$(curl -sS -m 60 -X POST "$ENDPOINT" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "$PROBE")

# Check for fields/artifacts that should have been stripped before client delivery
LEAK=0
for pattern in 'reasoning_content' '"thinking"' '<think>' 'chain_of_thought' '"reasoning":'; do
  if echo "$RESPONSE" | grep -qiF "$pattern"; then
    echo "[FAIL] Response contains reasoning trace artifact: $pattern"
    LEAK=1
  fi
done

# Check for high-volume tolerance (rate limiting sanity check)
echo "[*] Testing rate limiting with 50 rapid requests"
HTTP_CODES=$(for i in $(seq 1 50); do
  curl -sS -o /dev/null -w "%{http_code} " -m 10 -X POST "$ENDPOINT" \
    -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d "$PROBE"
done)
echo "[*] HTTP codes: $HTTP_CODES"
if ! echo "$HTTP_CODES" | grep -q '429'; then
  echo "[WARN] No 429 responses observed — rate limiting may be absent or too permissive for bulk-extraction resistance."
fi

if [ "$LEAK" -eq 0 ]; then
  echo "[PASS] No reasoning trace fields detected in client-facing response."
else
  echo "[ACTION REQUIRED] Strip reasoning fields at the gateway/proxy layer before responses reach clients."
fi

Remediation

There is no vendor patch for this — it is an architectural and configuration problem. Remediation is a layered hardening exercise:

1. Sanitize responses at the trust boundary (immediate, highest value). Audit every hop between the model provider and the client: API gateways, reverse proxies, LLM middleware (LiteLLM, Portkey, custom FastAPI/Express wrappers), and logging pipelines. Explicitly strip reasoning_content, thinking, <think> blocks, and any provider-specific reasoning fields before responses leave your infrastructure. Do not rely on provider defaults — verify with the probe script above. Treat 'field is present in upstream response' as the default assumption.

2. Constrain the model against verbalizing reasoning. Add explicit system-prompt directives forbidding restatement, translation, or encoding of internal reasoning, and deploy output filters that block known evasion encodings (Base64 blobs, acrostic patterns) in responses to untrusted users. Recognize this is a mitigation, not a guarantee — elicitation is an open problem — which is why control #1 matters more.

3. Rate-limit and baseline per API key, not per IP. Bulk extraction depends on volume. Enforce per-key request ceilings, progressive throttling, and alerting on volume anomalies. Rotate keys for any account that trips extraction thresholds.

4. Minimize what reasoning traces can contain. Apply data-minimization to your RAG pipeline: exclude credentials, secrets, and high-sensitivity documents from retrieval indices reachable by customer-facing models. The reasoning trace is only as sensitive as the context the model was given.

5. Log and monitor the request body, not just metadata. Elicitation prompts are only detectable if your gateway logs request payloads (with appropriate privacy controls). Feed these logs to your SIEM and deploy the Sigma/KQL detections above. Review the OWASP Top 10 for LLM Applications (particularly LLM01 Prompt Injection and LLM02 Sensitive Information Disclosure) as your control framework.

6. Add reasoning-trace extraction to your pen-test scope. Include CoT elicitation and field-harvesting tests in every AI-feature assessment going forward. If your red team isn't probing your LLM endpoints for trace leakage, your adversaries will be the first ones to try.

Related Resources

Security Arsenal Penetration Testing Services AlertMonitor Platform Book a SOC Assessment vulnerability-management Intel Hub

Is your security operations ready?

Get a free SOC assessment or see how AlertMonitor cuts through alert noise with automated triage.