8000 GitHub - hriday/trace: Defensive proof of concept: how encrypted LLM reasoning blocks can leak if not bound to their context, and how to fix it. Live at trace.moosha.org · GitHub
[go: up one dir, main page]

Skip to content
hridayPublic

About

Defensive proof of concept: how encrypted LLM reasoning blocks can leak if not bound to their context, and how to fix it. Live at trace.moosha.org

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Trace — Encrypted Reasoning Block Defense PoC

A defensive proof-of-concept demonstrating vulnerabilities and mitigations for reasoning trace extraction from proprietary LLM APIs, as described in "Stealing Reasoning Traces from Proprietary LLM APIs" (arXiv:2608.09867).

What This Is

Trace showcases how encrypted reasoning blocks (the hidden step-by-step reasoning inside Claude and other LLMs) can leak information if not cryptographically bound to their context. It demonstrates both vulnerable scenarios and defended mitigations using AEAD (Authenticated Encryption with Associated Data) context-binding.

Safety & Scope

  • Synthetic data only: No real API keys are leaked; the demo uses mock reasoning traces and cryptographic simulations.
  • Mock provider: The app does not attack real Anthropic services.
  • Educational: Designed to help practitioners understand how to defend reasoning-block APIs.

What It Shows

Three Attack Scenarios

  1. Secret Extraction: Attacker replays an encrypted block in a different context to extract embedded secrets.
  2. Distillation: Attacker uses encrypted blocks to extract patterns from reasoning, building a smaller local LLM.
  3. Prompt Injection: Attacker crafts a message that causes a reasoning block to reveal injected instructions.

Distillation lab

The "Reasoning distillation" scenario includes a deeper distillation lab (below the verdict card) that models the paper's actual distillation attack, not just a single leaked trace: a scalable harvest of 8 synthetic teacher problems, each replayed through the same real AEAD encrypt/decode path as the rest of the demo — so the Vulnerable/Defended toggle genuinely gates it. A tally makes the cost asymmetry explicit (traces stolen, dense supervision tokens, frontier-model queries: 0, decoder calls), and in Defended mode every blob is rejected and the tally stays at zero. Harvesting at least one trace in Vulnerable mode unlocks a teacher → student illustration comparing an output-only student (wrong/shallow) against a reasoning-distilled student (reproduces the stolen method) on a held-out problem — clearly captioned as illustrative, since no model is actually trained; it only demonstrates why a reasoning trace is a denser training signal than final answers alone. All data — the 8 teacher problems, their reasoning, and the held-out comparison — is synthetic.

Defense: AEAD Context-Binding

The defended path uses AEAD to bind each reasoning block to its original request context (hash of user message, model, system prompt). Replay attempts in a different context fail cryptographic verification—preventing all three attacks above.

Local Development

Prerequisites

  • Node.js 18+ and npm, or Docker + Docker Compose

Option 1: Two Development Servers

npm install

# Terminal 1: Start the backend server
npm run dev --workspace server

# Terminal 2: Start the web frontend
npm run dev --workspace web

Visit http://localhost:3000 (or the port shown in your terminal).

Option 2: Docker Compose

docker compose up

The app will be available at http://localhost:8019 inside the container.

Environment Variables

Variable Default Notes
ANTHROPIC_API_KEY (optional) Used only for authenticated replays — see Access Model. If set and the request is authenticated, the real decoder analyzes the trace; if unset, that authenticated path degrades gracefully to decoderSkipped. Anonymous replays never touch this key at all, regardless of whether it's set.
DECODER_MODEL claude-haiku-4-5 Model used for reasoning-block analysis.
PORT 8019 HTTP port for the server (Docker Compose).
AUTH_PASSWORD_HASH_B64 (unset) base64-encoded argon2id hash of the shared login password (base64 avoids the $ that docker-compose would strip from an env_file). Set via set-password. Unset ⇒ auth is not configured.
SESSION_SECRET (unset) Hex string (≥32 bytes) used to HMAC-sign session cookies. Unset ⇒ auth is not configured.
SESSION_TTL_HOURS 168 Session cookie lifetime, in hours.

Example .env

ANTHROPIC_API_KEY=sk-ant-...
DECODER_MODEL=claude-3-5-sonnet-20241022
PORT=8019
AUTH_PASSWORD_HASH_B64=JGFyZ29uMmlkJHY9MTkkbT0xOTQ1Ni4uLg==   # base64 of the argon2id hash
SESSION_SECRET=<64 hex chars>

Access Model

Trace is open to everyone. GET /api/scenarios, POST /api/replay, and all /api/distill/* routes are public — no login required to explore any attack scenario, in either mode.

What login controls is narrower and more specific: whether a replay spends the real Anthropic key.

  • Anonymous request → the crypto verdict (ALLOWED/REJECTED) is computed exactly as before, for real, but if the block is ALLOWED the "decoder" step is a simulated decode — a deterministic, offline echo of the same (synthetic) reasoning that a real decode would leak. No network call, no Anthropic import path, zero key spend. Anonymous visitors still see exactly what the attack would leak; they just don't trigger a real model call to show it.
  • Authenticated request (valid trace_session cookie) → the ALLOWED path calls the real decoder (runDecoder, an actual Claude call) and transcribes the leak live.

The decision is server-side, always. The /api/replay handler computes auth.isAuthenticated(req) — the same signed-cookie verification requireAuth uses — and passes that boolean into runReplay. It is never taken from anything the client sends (no flag, header, or body field can turn on the real decoder); only a cookie that verifies against SESSION_SECRET can.

Fail closed on the login endpoint itself: if either AUTH_PASSWORD_HASH_B64 (or raw AUTH_PASSWORD_HASH) or SESSION_SECRET is missing, auth is considered "not configured" — POST /api/login returns 503 rather than ever accepting a password, and isAuthenticated always returns false. A half-configured deploy just means every visitor gets the simulated decoder — it never falls open into spending the key without a valid session.

The password itself is never stored in plaintext or committed to git — only its Argon2id hash (@node-rs/argon2) lives in .env. Provision it with the bundled CLI (see deploy/DEPLOY.md for the exact production command):

TRACE_ENV_FILE=./.env node server/dist/cli/set-password.js

It prompts for the password twice (masked, ≥15 chars, must match), hashes it, and upserts AUTH_PASSWORD_HASH_B64 into the target env file — generating SESSION_SECRET too if one isn't already present. It never prints the password or the hash to stdout.

Testing

npm test

Runs the test suite for the app.

Production Deployment

For instructions on deploying Trace to a production server (trace.moosha.org), see deploy/DEPLOY.md.

References

About

Defensive proof of concept: how encrypted LLM reasoning blocks can leak if not bound to their context, and how to fix it. Live at trace.moosha.org

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0