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