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

Function installBearerAuthHeader

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

Source from the content-addressed store, hash-verified

325};
326
327const installBearerAuthHeader = (origin: string, token: string | null) => {
328 authHeaderUnsubscribe?.();
329 authHeaderUnsubscribe = null;
330 if (!token) return;
331 const headerValue = `Bearer ${token}`;
332 session.defaultSession.webRequest.onBeforeSendHeaders(
333 { urls: [`${origin}/*`] },
334 (details, callback) => {
335 // Scope the bearer to the app's OWN renderer. OAuth popups run in this same
336 // session but load third-party provider pages; auto-attaching the bearer to
337 // any request they make to the sidecar would make it an ambient credential
338 // (a CSRF vector) for untrusted content — the very thing the bearer model
339 // exists to avoid. The popup only ever needs the bearer-exempt
340 // /oauth/callback and hands its result back via same-origin browser
341 // channels (localStorage/postMessage), so withholding the bearer from any
342 // non-app webContents is safe. Requests with no webContentsId (main
343 // process / network service) still get it.
344 const fromOtherWebContents =
345 details.webContentsId !== undefined &&
346 (mainWindow === null || details.webContentsId !== mainWindow.webContents.id);
347 if (fromOtherWebContents) {
348 callback({ requestHeaders: details.requestHeaders });
349 return;
350 }
351 callback({
352 requestHeaders: {
353 ...details.requestHeaders,
354 Authorization: headerValue,
355 },
356 });
357 },
358 );
359 authHeaderUnsubscribe = () => {
360 session.defaultSession.webRequest.onBeforeSendHeaders({ urls: [`${origin}/*`] }, null);
361 };
362};
363
364/**
365 * 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