MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / installBearerAuthHeader

Function installBearerAuthHeader

apps/desktop/src/main/index.ts:403–438  ·  view source on GitHub ↗
(origin: string, token: string | null)

Source from the content-addressed store, hash-verified

401};
402
403const installBearerAuthHeader = (origin: string, token: string | null) => {
404 authHeaderUnsubscribe?.();
405 authHeaderUnsubscribe = null;
406 if (!token) return;
407 const headerValue = `Bearer ${token}`;
408 session.defaultSession.webRequest.onBeforeSendHeaders(
409 { urls: [`${origin}/*`] },
410 (details, callback) => {
411 // Scope the bearer to the app's OWN renderer. OAuth popups run in this same
412 // session but load third-party provider pages; auto-attaching the bearer to
413 // any request they make to the sidecar would make it an ambient credential
414 // (a CSRF vector) for untrusted content — the very thing the bearer model
415 // exists to avoid. The popup only ever needs the bearer-exempt
416 // /oauth/callback and hands its result back via same-origin browser
417 // channels (localStorage/postMessage), so withholding the bearer from any
418 // non-app webContents is safe. Requests with no webContentsId (main
419 // process / network service) still get it.
420 const fromOtherWebContents =
421 details.webContentsId !== undefined &&
422 (mainWindow === null || details.webContentsId !== mainWindow.webContents.id);
423 if (fromOtherWebContents) {
424 callback({ requestHeaders: details.requestHeaders });
425 return;
426 }
427 callback({
428 requestHeaders: {
429 ...details.requestHeaders,
430 Authorization: headerValue,
431 },
432 });
433 },
434 );
435 authHeaderUnsubscribe = () => {
436 session.defaultSession.webRequest.onBeforeSendHeaders({ urls: [`${origin}/*`] }, null);
437 };
438};
439
440/**
441 * Resolve the on-disk path to the Executor app icon. Packaged builds get

Callers 4

armSupervisedMonitorFunction · 0.85
createWindowFunction · 0.85
restartSidecarAndReloadFunction · 0.85
registerIpcHandlersFunction · 0.85

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected