Repository navigation
fix: prevent API proxy upstream credential disclosure - #11471
Conversation
Track credentials actually injected per request and mask upstream responses, diagnostics, streamed payloads, and WebSocket frames before forwarding. Cover synthetic upstreams, refreshed and signed credentials, compression, framing, and cancellation. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects can hang the proxy on whitespace-only tokens and leak non-ASCII credentials echoed in WebSocket upgrade headers.
6 open issues
Whitespace-only auth tokens can hang the proxy event loop · New Non-ASCII credentials in upgrade headers bypass masking · New Zero-length encoded responses fail during decompression · New Brotli responses use unnecessarily slow default compression quality · New Queued payload prefixes can block WebSocket control frames · New Credential-bearing WebSocket pings desynchronize upstream Pong handling · New
What changed in this PR
This PR hardens AWF’s API proxy against upstream responses echoing credentials injected on the agent’s behalf.
Changes:
- Tracks injected credentials across authentication, signing, retries, and provider fallback.
- Adds bounded credential masking for HTTP responses and WebSocket traffic.
- Adds regression coverage, packages the new modules, and documents compatibility limits.
| File | Description |
|---|---|
containers/api-proxy/websocket-tunnel.test.js |
Updates expectations for filtered upstream streams. |
containers/api-proxy/websocket-tunnel.js |
Integrates WebSocket masking and rejection cleanup. |
containers/api-proxy/upstream-response.js |
Redacts stream errors and handles cancellation accounting. |
containers/api-proxy/upstream-http.test.js |
Adapts mocked responses to the protection wrapper. |
containers/api-proxy/upstream-http.js |
Protects HTTP responses and records signing credentials. |
containers/api-proxy/upstream-auth.js |
Records credentials resolved during renewable authentication. |
containers/api-proxy/trusted-service.js |
Marks trusted-service secrets for protection. |
containers/api-proxy/test-helpers/server-mock-factories.js |
Bypasses stream wrapping for legacy response mocks. |
containers/api-proxy/server.websocket.test.js |
Updates socket mocks and filtered-pipe assertions. |
containers/api-proxy/server.credential-isolation.test.js |
Adds real-socket credential-isolation regressions. |
containers/api-proxy/request-headers.js |
Records injected credentials and removes key previews. |
containers/api-proxy/README.md |
Documents masking behavior and compatibility limits. |
containers/api-proxy/proxy-request.js |
Initializes request-scoped credential tracking. |
containers/api-proxy/proxy-error-handler.js |
Redacts logged and client-facing error messages. |
containers/api-proxy/providers/foundry.js |
Marks Foundry API keys for tracking. |
containers/api-proxy/providers/auth-headers.js |
Attaches credential metadata to authentication headers. |
containers/api-proxy/providers/anthropic.js |
Preserves credential metadata when copying headers. |
containers/api-proxy/Dockerfile |
Includes both protection modules in the container. |
containers/api-proxy/cross-provider-fallback.js |
Retains credential protection across provider fallback. |
containers/api-proxy/credential-websocket.js |
Implements bounded, frame-aware WebSocket masking. |
containers/api-proxy/credential-protection.test.js |
Tests stream masking and WebSocket frame handling. |
containers/api-proxy/credential-protection.js |
Implements credential tracking, redaction, and HTTP filtering. |
containers/api-proxy/catalogue-proxy.test.js |
Adapts usage-tracking socket mocks to filtered streams. |
Review effort: Max (auto)
| values.add(value); | ||
| if (name.toLowerCase() === 'authorization') { | ||
| const token = value.replace(/^(?:Bearer|token)\s+/i, ''); | ||
| values.add(token); |
| if (/\r\nsec-websocket-extensions\s*:/i.test(text)) { | ||
| throw new Error('Unrequested upstream WebSocket extension'); | ||
| } | ||
| this.push(Buffer.from(redactCredentialText(req, text), 'latin1')); |
| function protectUpstreamResponse(source, req) { | ||
| if (!credentials.get(req)?.size) return source; | ||
| const headers = protectResponseHeaders(req, source.headers); | ||
| const hasBody = req.method !== 'HEAD' && ![204, 205, 304].includes(source.statusCode); |
| const codecs = { | ||
| gzip: [zlib.createGunzip, () => zlib.createGzip({ flush: zlib.constants.Z_SYNC_FLUSH })], | ||
| deflate: [zlib.createInflate, () => zlib.createDeflate({ flush: zlib.constants.Z_SYNC_FLUSH })], | ||
| br: [zlib.createBrotliDecompress, () => zlib.createBrotliCompress({ flush: zlib.constants.BROTLI_OPERATION_FLUSH })], |
| pending.shift(); | ||
| } else { | ||
| const length = Math.min(safeBytes, part.bytes.length); | ||
| if (!length) break; |
| maskCredentialPrefix(req, control.subarray(start), true); | ||
| addFraming(control); |
|
@copilot address review feedback and fix this failing ci check https://github.com/github/gh-aw-firewall/actions/runs/43059213513/job/130714208632?pr=11471 |
Co-authored-by: lpcox <[email protected]>
Addressed the review findings and fixed the generated-assets test fixture in commit |
|
✅ Copilot review passed with no inline comments. @lpcox Add the |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
|
@copilot merge main and resolve conflicts |
…redential-disclosure Co-authored-by: lpcox <[email protected]>
Co-authored-by: lpcox <[email protected]>
Fixed both linked CI failures in commit |
|
✅ Security Guard completed successfully! Security GuardOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤
|
|
📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅ Smoke OTel TracingOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
Smoke Cloud Hypervisor completed. Cloud Hypervisor + Copilot passed.
|
|
✅ Build Test Suite completed successfully!
|
|
✅ Smoke Claude passed
|
|
🔌 Smoke Services — All services reachable! ✅
|
|
✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟 Smoke CodexOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded. Smoke ChrootOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅ Smoke Copilot Network IsolationOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓 Smoke Copilot BYOKOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
Smoke Test: Claude Engine
Overall result: PASS
|
|
OTEL smoke results:
|
|
Smoke services: ✅ Redis PONG · ✅ pg_isready · ✅ SELECT 1 — PASS
|
|
Smoke Copilot: PR "feat: send each budget notice once to every conversation in the run"
Overall: PASS — @lpcox
|
|
Cloud Hypervisor + Copilot smoke test
Overall: PASS
|
|
EGRESS_RESULT allow=pass deny=pass
|
Smoke Test: Copilot BYOK (Direct Mode) ✅Tests:
Mode: COPILOT_PROVIDER_API_KEY → api-proxy sidecar → api.githubcopilot.com Status: PASS
|
🏗️ Build Test Suite Results
Overall: 7/8 ecosystems passed — FAIL Java failure: Maven could not resolve plugins ( .NET needed a writable
|
|
Smoke test
Overall status: FAIL
|
Chroot version comparison: ❌ Failed
Node.js differs between host and chroot, so the
|


Summary
Resolves githubnext/gh-aw-security#3386.
Prevent upstream diagnostics from exposing credentials that the API proxy injected on the agent's behalf. This is an independent change based on
main; it does not add agent-facing caller authentication, change model-keyed budget policy, or modify security-repository workflows/pins.Reproduction and regression evidence
Reproduced the literal
UPSTREAM-DUMMY-CREDecho against an untouched snapshot of current main (32541bf3c), through the actualrequire('./server').createProviderServer(adapter)facade, real OpenAI adapter, loopback upstream, and loopback CONNECT proxy selected before module load. The baseline regression fails because the client receives the injected credential in a 502 diagnostic.Added 51 focused regressions: 35 production-facade/socket cases and 16 bounded-filter/frame cases. Positive controls assert the credential or actual signing material reached the synthetic upstream; exact-output assertions verify it does not return to the client or diagnostics. Coverage includes all supported provider families, custom auth headers, dynamically resolved and refreshed tokens, trusted-service secrets, actual SigV4 signing, cross-provider fallback, headers, JSON escaping, every chunk split, compression, live SSE, large ordinary frames, fragmented WebSocket messages, close reasons, rejected upgrades, malformed streams, and cancellation.
Existing mocked-network tests bypass only the response-stream wrapper because their manually emitted fake responses are not Readable streams; the new socket suite does not mock the request/response transport under test.
Validation
cd containers/api-proxy && npm test -- --runInBand: 160 suites passed; 4,113 tests passed, 2 skipped.npm run lintandnpm run lint -- --quiet: passed (the normal invocation reports existing repository warnings).npm run build: passed.git diff --check: passed.Scope and limitations
All reproduction/regression traffic used isolated loopback services and dummy credentials. No real secrets, provider inference, shared/live exploit traffic, or manual workflow dispatches were used. This does not establish behavior of any specific third-party provider, verify released container-image provenance, or constitute Docker/VM runtime validation.
The filter protects against accidental literal credential echoes, not arbitrary encoding or deliberate exfiltration by a malicious upstream. WebSocket handshakes are bounded to 16 KiB, and framing/control bytes retained behind a partial credential are bounded to 64 KiB. No auto-merge is enabled.