Harden Copilot proxy auth normalization to avoid malformed Authorization headers#3322
Conversation
🧪 Smoke Test Results
Overall: PASS — Pre-step smoke file confirmed:
|
Smoke Test Results❌ Test 1 (GitHub API): gh CLI authentication failed — network/firewall constraint Summary: 2/3 tests passed. GitHub API test failed due to network constraints in the AWF sandbox environment.
|
Smoke Test Results (Gemini)
Overall status: FAIL PR Titles: N/A (Failed to retrieve) Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
There was a problem hiding this comment.
Pull request overview
This PR hardens GitHub Copilot provider auth handling in the api-proxy sidecar to prevent malformed Authorization headers and to correctly ignore non-credential placeholder/dummy BYOK values, reducing 400s from upstream providers.
Changes:
- Extend auth token normalization to strip both
Bearerandtokenprefixes (case-insensitive). - Treat
COPILOT_API_KEY=dummy-byok-key-for-offline-modeas a non-credential sentinel (like the AWF placeholder), falling back toCOPILOT_GITHUB_TOKEN. - Add regression tests covering
tokenstripping and dummy BYOK fallback behavior.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/providers/copilot.js | Expands token prefix stripping and ignores the offline dummy BYOK key during API key resolution. |
| containers/api-proxy/server.auth.test.js | Adds unit coverage for token prefix stripping and dummy BYOK sentinel fallback/ignoring behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
| function resolveApiKey(env) { | ||
| const key = stripBearerPrefix(env.COPILOT_API_KEY); | ||
| return key === COPILOT_PLACEHOLDER_TOKEN ? undefined : key; | ||
| return key === COPILOT_PLACEHOLDER_TOKEN || key === COPILOT_DUMMY_BYOK_KEY ? undefined : key; | ||
| } |
| function stripBearerPrefix(value) { | ||
| return ((value || '').replace(/^\s*Bearer\s+/i, '').trim()) || undefined; | ||
| return ((value || '').replace(/^\s*(?:Bearer|token)\s+/i, '').trim()) || undefined; | ||
| } |
Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Overall: FAIL — GitHub MCP returned 401; pre-step smoke data template variables were not expanded.
|
|
Overall status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Version Comparison Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results — FAIL
|
Copilot requests routed through the AWF API proxy could fail with
400 bad request: Authorization header is badly formattedwhen the sidecar received non-credential placeholder/dummy BYOK values or pre-prefixed auth tokens. This change tightens Copilot auth token normalization and fallback behavior so injected headers are consistently valid.Auth token normalization
stripBearerPrefixnow normalizes bothBearer <token>andtoken <token>inputs (case-insensitive), preventing malformed forwarded headers from prefix artifacts.Placeholder/dummy BYOK handling
COPILOT_API_KEY=dummy-byok-key-for-offline-modeas non-credential input (same class as the AWF placeholder token), so the adapter does not use it as upstream auth material.COPILOT_GITHUB_TOKENwhen a real BYOK key is absent.Regression coverage
tokenprefix stripping