src/vs/platform/agentHost/node/claude/claudeProxyAuth.ts
58 LOC · 58 covered · 0 uncovered · 9 ranges · 1392 concepts · 8 introducers · 686 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
claudeProxyAuth.ts ×1
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type * as http from 'http';
/**
* Result of {@link parseProxyBearer}. `valid` is `true` only when the
* `Authorization` header contains `Bearer <expectedNonce>.<sessionId>`
* with a non-empty `sessionId`.
*
* Phase 2 deliberately does NOT accept the legacy `Bearer <nonce>` (no
* dot) format that the Copilot extension's `extractSessionId` accepts —
* the agent host always issues full `nonce.sessionId` tokens.
*/
export interface ProxyBearerAuth {
readonly valid: boolean;
readonly sessionId: string | undefined;
}
const INVALID: ProxyBearerAuth = Object.freeze({ valid: false, sessionId: undefined });
/**
* Parses + validates the inbound Bearer token on Claude proxy requests.
*
* Accepts only `Authorization: Bearer <nonce>.<sessionId>` where the
* leading nonce equals `expectedNonce` and `sessionId` is non-empty.
* The `x-api-key` header is ignored to prevent a user's
* `ANTHROPIC_API_KEY` env var from interfering with proxy auth.
*
* Rejects (returns `{ valid: false, sessionId: undefined }`):
* - missing or non-`Bearer` `Authorization`
* - `Bearer <nonce>` (no dot)
* - `Bearer <nonce>.` (empty sessionId)
* - `Bearer <wrong-nonce>.<sessionId>`
*/
export function parseProxyBearer(headers: http.IncomingHttpHeaders, expectedNonce: string): ProxyBearerAuth {
if (typeof authHeader !== 'string' || !authHeader.startsWith('Bearer ')) {
}
const token = authHeader.slice('Bearer '.length);
const dotIndex = token.indexOf('.');
if (dotIndex === -1) {
return INVALID;
}
const nonce = token.slice(0, dotIndex);
const sessionId = token.slice(dotIndex + 1);
}
return { valid: true, sessionId };
}