Skip to content

feat(secrets): session proxy wiring — fake creds, hooks, leak guard, bootstrap (Plan 5)#206

Merged
erans merged 12 commits intomainfrom
plan-05-session-proxy-wiring
Apr 9, 2026
Merged

feat(secrets): session proxy wiring — fake creds, hooks, leak guard, bootstrap (Plan 5)#206
erans merged 12 commits intomainfrom
plan-05-session-proxy-wiring

Conversation

@erans
Copy link
Copy Markdown
Collaborator

@erans erans commented Apr 9, 2026

Summary

  • Fake credential generator (internal/proxy/secrets/fakegen.go): format-string-driven generation with {rand:N} syntax, crypto/rand, base62 alphabet, 24-char minimum entropy enforcement
  • Hook pipeline (internal/proxy/hooks.go, proxy.go): HookAbortError for typed hook aborts (400-599 only), hookRegistry wired into ServeHTTP (pre-hook after DLP) and ModifyResponse (post-hook after body read)
  • ContainsFake (internal/proxy/credsub/table.go): substring scan returning (serviceName, bool) — never exposes real credential bytes
  • CredsSubHook (internal/proxy/credshook.go): fake→real on request, real→fake on response, infallible
  • LeakGuardHook (internal/proxy/credshook.go): scans body, URL query, and all header values (Header.Values, not Header.Get) for fakes; returns 403 via HookAbortError
  • Session bootstrap (internal/session/secrets.go): BootstrapCredentials fetches secrets, generates fakes, populates table, returns cleanup fn; zeros table on failure
  • Session wiring (internal/session/manager.go, llmproxy.go): SetLLMProxy/SetProxyInstance deferred until after bootstrap succeeds; CloseLLMProxy stops proxy before zeroing table

Out of scope (future plans)

  • SSE streaming substitution
  • Cross-service fake credential detection

Test plan

  • go test ./internal/proxy/secrets/... -v -race — 17 tests for format parsing, generation, entropy
  • go test ./internal/proxy/... -v -race — hook abort, plain error, status code validation (table-driven), CredsSubHook, LeakGuardHook (body/query/headers/duplicates)
  • go test ./internal/proxy/credsub/... -v -race — ContainsFake substring scanning
  • go test ./internal/session/... -v -race — bootstrap happy path, fetch error cleanup, invalid format, length mismatch, multiple services, integration test (end-to-end substitution + leak detection)
  • GOOS=windows go build ./... — cross-compilation clean

🤖 Generated with Claude Code

erans and others added 12 commits April 9, 2026 15:15
Covers fake generator, hook wiring in proxy, CredsSubHook/LeakGuardHook,
session startup credential bootstrap, and cleanup semantics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds GenerateFake and ParseFormat for producing length-preserving
fake credentials from format templates like ghp_{rand:36}. Uses
crypto/rand with base62 alphabet, enforces 24-char minimum entropy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PreHook can return *HookAbortError to abort with a specific status
code (e.g. 403 for leak detection). Other errors still produce 502.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ContainsFake scans a byte buffer for any registered fake as a
substring. Used by LeakGuardHook to detect credential exfiltration
in request bodies, URLs, and headers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds hookRegistry field to Proxy, calls ApplyPreHooks after DLP and
ApplyPostHooks after response body read. HookAbortError produces
the specified status code; other errors produce 502.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validates HookAbortError.StatusCode is in 100-599 range, falls back
to 502 for invalid values. Changes ContainsFake to return only the
service name string instead of a full Entry, preventing Real credential
bytes from leaking to callers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PreHook replaces fakes with reals in request bodies. PostHook
replaces reals with fakes in response bodies. Both are infallible
and use the credsub.Table's single-pass longest-match algorithm.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Scans request body, URL query, and select headers for known fake
credentials. Returns 403 via HookAbortError and logs audit event
secret_leak_blocked when a fake is detected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BootstrapCredentials fetches secrets, generates length-preserving
fakes, and populates a credsub.Table. StartLLMProxy registers
LeakGuardHook and CredsSubHook when service configs are provided.
Session cleanup zeros the table on close.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Uses Header.Values instead of Header.Get to scan all values for
a given header name. Prevents bypass via duplicate Authorization
or X-Api-Key headers hiding a fake in a non-first value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Moves SetLLMProxy/SetProxyInstance to after BootstrapCredentials
succeeds, preventing stale session fields on bootstrap failure.

Reorders CloseLLMProxy to stop the proxy (draining in-flight
requests) before zeroing the credential table, preventing hooks
from seeing an empty table during teardown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1xx-3xx status codes are not valid abort responses. Tightens
validation to only allow client/server error codes (400-599),
falling back to 502 for anything outside that range.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erans erans merged commit 7944d0d into main Apr 9, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant