Skip to content

fix: prevent API proxy upstream credential disclosure - #11471

Merged
lpcox merged 4 commits into
mainfrom
lpcox-fix-api-proxy-credential-disclosure
Nov 11, 2026
Merged

lpcox merged 4 commits into
mainfrom
lpcox-fix-api-proxy-credential-disclosure

Conversation

@lpcox

@lpcox lpcox commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Track actual credentials per request, including custom auth headers, OIDC/renewable tokens, trusted-service secret headers, final AWS signing headers, and credentials from previous retry/fallback attempts.
  • Mask exact case-sensitive values and their conventional JSON-escaped spelling before response forwarding, error inspection, usage/routing observation, diagnostic logging, or transport-error reporting. Remove partial-key debug previews.
  • Stream HTTP bodies with bounded credential-prefix lookbehind. Preserve identity byte lengths and successful output; handle gzip/deflate/Brotli by streaming decode/mask/re-encode, remove stale framing/integrity metadata, preserve bodyless responses, and fail explicitly on unsupported or malformed encodings. Keep cancellation/error accounting balanced.
  • Apply bounded, frame-aware masking to WebSocket handshake headers, message fragments, control payloads, and close reasons without changing frame lengths or close codes. Do not negotiate optional WebSocket compression; reject unsupported frames/extensions. Failed upgrades retain their HTTP status but omit opaque diagnostic headers/bodies and terminate even when upstream keeps its socket open.
  • Include both runtime modules in the container COPY list and document compatibility changes and limits.

Reproduction and regression evidence

Reproduced the literal UPSTREAM-DUMMY-CRED echo against an untouched snapshot of current main (32541bf3c), through the actual require('./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 lint and npm 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.

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]>
Copilot AI adaptive review requested due to automatic review settings November 11, 2026 16:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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;
Comment on lines +127 to +128
maskCredentialPrefix(req, control.subarray(start), true);
addFraming(control);
@lpcox

lpcox commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback and fix this failing ci check https://github.com/github/gh-aw-firewall/actions/runs/43059213513/job/130714208632?pr=11471

Addressed the review findings and fixed the generated-assets test fixture in commit 18ee381. Direct Node and syntax checks pass; Jest validation was blocked because npm dependency downloads failed with DNS errors.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@lpcox Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 93.88% 93.88% ➡️ +0.00%
Statements 92.42% 92.43% 📈 +0.01%
Functions 93.11% 93.11% ➡️ +0.00%
Branches 86.81% 86.82% ➡️ +0.01%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/enclave/host-executor-server.ts 91.2% → 91.2% (+0.00%) 89.8% → 90.1% (+0.29%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@lpcox

lpcox commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts

@github github deleted a comment Nov 11, 2026

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@copilot fix these failing ci checks https://github.com/github/gh-aw-firewall/actions/runs/43091136872/job/130768762194?pr=11471 and https://github.com/github/gh-aw-firewall/actions/runs/43091136872/...

Fixed both linked CI failures in commit 6f0d7c4. The tests now reflect local Ping handling and verify that many interleaved Pings do not block a fragmented credential. Direct checks passed; Jest was unavailable in the workspace.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Security Guard completed successfully!

Security Guard

Outcome: reported_no_action

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.

Generated from Security Guard · auto (Claude Sonnet 5.5) · ~18 AIC · ⊞ 9.0K · ◷

Generated by Security Guard for #11471

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

Smoke OTel Tracing

Outcome: reported_action

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.

Generated from Smoke OTel Tracing · auto (Claude Sonnet 5.5) · ~17 AIC · ⊞ 5.5K · ◷

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Smoke Cloud Hypervisor completed. Cloud Hypervisor + Copilot passed.

Cloud Hypervisor + Copilot smoke test by Smoke Cloud Hypervisor

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Build Test Suite completed successfully!

Generated by Build Test Suite for #11471

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Smoke Claude passed

Generated by Smoke Claude for #11471

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

🔌 Service connectivity validated by Smoke Services

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

Smoke Codex

Outcome: reported_action

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.

Generated from Smoke Codex · gpt54 · ~15 AIC · ⊞ 22.5K · ◷

🔮 The oracle has spoken through Smoke Codex

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

Smoke Chroot

Outcome: reported_action

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.

Generated from Smoke Chroot · auto (Claude Sonnet 5.5) · ~14 AIC · ⊞ 8.2K · ◷

Tested by Smoke Chroot

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅

Smoke Copilot Network Isolation

Outcome: reported_action

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.

Generated from Smoke Copilot Network Isolation · auto (Claude Sonnet 5.5) · ~15 AIC · ⊞ 9.8K · ◷

🛡️ Egress verdict from Smoke Copilot Network Isolation

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

Smoke Copilot BYOK

Outcome: reported_action

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.

Generated from Smoke Copilot BYOK · haiku45 · ~7 AIC · ⊞ 7.0K · ◷

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine

  • API status: ✅ PASS
  • GitHub check: ✅ PASS
  • File status: ✅ PASS

Overall result: PASS

Generated by Smoke Claude for #11471 · claude · haiku45 · ~36 AIC · ⊞ 6.3K · ◷
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

OTEL smoke results:

  • ✅ 1. Module loading: otel.js exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, routerCallTracing, shutdown, isEnabled.
  • ✅ 2. Tests: 3 OTEL suites, 75/75 pass.
  • ✅ 3. Env forwarding: GITHUB_AW_OTEL_TRACE_ID and GITHUB_AW_OTEL_PARENT_SPAN_ID in env-passthrough.ts; OTEL_EXPORTER_OTLP_* in api-proxy-env-config.ts.
  • ✅ 4. Token tracker: onUsage hook present in token-tracker-http.js.
  • ✅ 5. Diagnostics: otel.jsonl exists with 1 line (spans written).

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke services: ✅ Redis PONG · ✅ pg_isready · ✅ SELECT 1 — PASS

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Copilot: PR "feat: send each budget notice once to every conversation in the run"

  • ✅ GitHub MCP
  • ✅ GitHub.com connectivity (200)
  • ✅ File write/read

Overall: PASS — @lpcox

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Cloud Hypervisor + Copilot smoke test

  1. Merged PR lookup: PASS
  2. github.com connectivity: PASS (HTTP 200)
  3. File write/read: PASS
  4. example.com blocked: PASS (HTTP 000)

Overall: PASS

Cloud Hypervisor + Copilot smoke test by Smoke Cloud Hypervisor
Add label ready-for-aw to run again

@github-actions github-actions Bot added smoke-cloud-hypervisor smoke-copilot-network-isolation Copilot network-isolation egress smoke test labels Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

EGRESS_RESULT allow=pass deny=pass

  • ✅ Allowed domain (api.github.com): HTTP 200
  • ✅ Blocked domain (example.com): blocked
  • Overall: PASS (cc @lpcox)

🛡️ Egress verdict from Smoke Copilot Network Isolation
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode) ✅

Tests:

Mode: COPILOT_PROVIDER_API_KEY → api-proxy sidecar → api.githubcopilot.com

Status: PASS

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia ✅ 1/1 passed ✅ PASS
Bun hono ✅ 1/1 passed ✅ PASS
C++ fmt ✅ N/A ✅ PASS
C++ json ✅ N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world ✅ N/A ✅ PASS
.NET json-parse ✅ N/A ✅ PASS
Go color ✅ ok ✅ PASS
Go env ✅ ok ✅ PASS
Go uuid ✅ ok ✅ PASS
Java gson ❌ 0 run ❌ FAIL
Java caffeine ❌ 0 run ❌ FAIL
Node.js clsx ✅ passed ✅ PASS
Node.js execa ✅ passed ✅ PASS
Node.js p-limit ✅ passed ✅ PASS
Rust fd ✅ 1/1 passed ✅ PASS
Rust zoxide ✅ 1/1 passed ✅ PASS

Overall: 7/8 ecosystems passed — FAIL

Java failure: Maven could not resolve plugins (maven-resources-plugin:3.4.0 from Maven Central: "Network is unreachable"). The squid-proxy:3128 proxy in ~/.m2/settings.xml was unreachable from this environment. The default ~/.m2/repository was also not writable, so I retried with a disposable repo and with no proxy, and both failed the same way.

.NET needed a writable DOTNET_CLI_HOME and XDG_RUNTIME_DIR to run, after which it passed.

Generated by Build Test Suite for #11471 · copilot · auto (Claude Sonnet 5.5) · ~29 AIC · ⊞ 5.9K · ◷
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke test

  • Merged PRs: ✅
  • PR details: ✅
  • Playwright title check: ❌
  • Temp file write/read: ✅
  • Build (npm ci && npm run build): ✅
  • PR titles: "fix: prevent API proxy upstream credential disclosure", "feat: send each budget notice once to every conversation in the run"

Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Chroot version comparison: ❌ Failed

Runtime Host Version Chroot Version Match?
Python 3.12.16 3.12.16 ✅
Node.js v24.22.2 v22.23.2 ❌
Go go1.22.12 go1.22.12 ✅

Node.js differs between host and chroot, so the smoke-chroot label was not added.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@lpcox
lpcox merged commit 4f77593 into main Nov 11, 2026
129 of 137 checks passed
@lpcox
lpcox deleted the lpcox-fix-api-proxy-credential-disclosure branch November 11, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants