Skip to content

Commit 0d79261

Browse files
lpcoxCopilot
andcommitted
fix: case-insensitive auth header lookup for debug logging
Address PR review feedback: - Make injected-key detection case-insensitive so auth_inject debug logs fire for OpenAI/Copilot (which use capital-A 'Authorization') in addition to Anthropic and Gemini. - Clarify stripGeminiKeyParam guard comments explaining why absolute/protocol-relative URLs are rejected before parsing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5425032 commit 0d79261

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

containers/api-proxy/server.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,15 @@ function buildUpstreamPath(reqUrl, targetHost, basePath) {
182182
*/
183183
function stripGeminiKeyParam(reqUrl) {
184184
// Only operate on relative request paths that begin with exactly one slash.
185-
// Returning other inputs unchanged preserves downstream validation behavior.
185+
// Returning other inputs unchanged lets proxyRequest's relative-URL check reject them.
186+
// The guard prevents absolute URLs (e.g. 'http://evil.com/path?key=…') and
187+
// protocol-relative URLs ('//host/path') from being normalized into a relative path.
186188
if (typeof reqUrl !== 'string' || !reqUrl.startsWith('/') || reqUrl.startsWith('//')) {
187189
return reqUrl;
188190
}
189191
const parsed = new URL(reqUrl, 'http://localhost');
190192
parsed.searchParams.delete('key');
193+
// Reconstruct relative path only — never emit the scheme/host from the dummy base.
191194
return parsed.pathname + parsed.search;
192195
}
193196

@@ -509,7 +512,8 @@ function proxyRequest(req, res, targetHost, injectHeaders, provider, basePath =
509512
Object.assign(headers, injectHeaders);
510513

511514
// Log auth header injection for debugging credential-isolation issues
512-
const injectedKey = injectHeaders['x-api-key'] || injectHeaders['authorization'] || injectHeaders['x-goog-api-key'];
515+
// Use case-insensitive lookup since providers use mixed casing (e.g. 'Authorization' vs 'authorization')
516+
const injectedKey = Object.entries(injectHeaders).find(([k]) => ['x-api-key', 'authorization', 'x-goog-api-key'].includes(k.toLowerCase()))?.[1];
513517
if (injectedKey) {
514518
const keyPreview = injectedKey.length > 8
515519
? `${injectedKey.substring(0, 8)}...${injectedKey.substring(injectedKey.length - 4)}`

0 commit comments

Comments
 (0)