Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,17 @@ describe('Request', () => {
assert((auth.ensureAccessToken as sinon.SinonStub).calledWith('https://graph.microsoft.com'));
});

it('sends no authorization header when routing through the external Graph base URL', async () => {
it('keeps the authorization header when routing through the external Graph base URL', async () => {
// The external token is the caller's credential toward the proxy (an
// OpenShell placeholder or the inter-VM bearer), so the rewritten request
// must still carry it: the proxy authenticates the caller with it.
process.env.CLIMICROSOFT365_ACCESS_TOKEN = 'inter-vm-bearer';
process.env.CLIMICROSOFT365_GRAPH_BASE_URL = 'http://127.0.0.1:18080';
auth.connection.cloudType = CloudType.Public;
let actualUrl = '';
let actualHeaders: any;
sinon.stub(_request as any, 'req').callsFake((requestOptions: any) => {
actualUrl = requestOptions.url as string;
actualHeaders = requestOptions.headers;
return { data: {} };
});
Expand All @@ -640,7 +645,8 @@ describe('Request', () => {
headers: {}
});

assert.strictEqual(actualHeaders.authorization, undefined);
assert.strictEqual(actualUrl, 'http://127.0.0.1:18080/v1.0/me/messages?$top=10');
assert.strictEqual(actualHeaders.authorization, 'Bearer ABC');
});

it('routes a headerless Graph request through the external Graph base URL', async () => {
Expand Down
15 changes: 9 additions & 6 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,15 @@ class Request {

options.url = `${proxyUrl.origin}${requestUrl.pathname}${requestUrl.search}${requestUrl.hash}`;

// The proxy owns the caller's credential; whatever token this process
// holds must never ride toward it. Strip the header at the same moment
// the destination changes, so no request can carry both.
if (options.headers) {
delete options.headers.authorization;
}
// The authorization header stays on the rewritten request. Under the
// governed deployment CLIMICROSOFT365_ACCESS_TOKEN is not a Graph token
// but the caller's credential toward the proxy itself (an OpenShell
// provider placeholder that the sandbox supervisor substitutes on the
// inspected hop, or the inter-VM bearer the proxy authenticates). The
// proxy holds the real Graph credential and only ever sees this
// process's value as its own front-door bearer, so stripping it here
// produced 401s from the proxy for every built-in command while
// `m365 request --url <proxy>/...` kept working.
}

private updateRequestForCloudType(options: AxiosRequestConfig, cloudType: CloudType): void {
Expand Down
Loading