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

Function installBearerAuthHeader

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

Source from the content-addressed store, hash-verified

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