Repository navigation
auth: resolve private image tokens through the renderer [6/10] - #22941
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Cross-process credential handling and request authorization are security-sensitive and warrant final human review despite strong test coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Routes private-image token resolution through AccountsStore so main uses fresh credentials safely.
Changes:
- Adds trusted, timeout-bounded IPC token resolution.
- Cancels requests when credentials become stale or unavailable.
- Fixes cancellation propagation and adds comprehensive unit coverage.
| File | Description |
|---|---|
app/src/lib/authenticated-image-token-handler.ts |
Resolves tokens in the renderer. |
app/src/lib/ipc-shared.ts |
Defines token-resolution IPC channels. |
app/src/main-process/app-window.ts |
Exposes main renderer web contents. |
app/src/main-process/authenticated-image-filter.ts |
Uses fresh tokens and validates account continuity. |
app/src/main-process/authenticated-image-token-resolver.ts |
Coordinates secure IPC requests and timeouts. |
app/src/main-process/main.ts |
Wires token resolution and sender validation. |
app/src/main-process/ordered-webrequest.ts |
Preserves request cancellation responses. |
app/src/ui/index.tsx |
Installs the renderer token handler. |
app/test/unit/*.ts |
Covers IPC contracts, resolution, filtering, and cancellation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| response = await listener(details) | ||
| if (response.cancel === true) { | ||
| break | ||
| return response |
There was a problem hiding this comment.
break stopped later filters, but execution then reached return details in ordered-webrequest.ts. That dropped { cancel: true }, so Electron could still send request.
return response stops filters and passes cancellation back to Electron. This matters when authenticated-image-filter.ts cancels request after credential refresh fails or account changes.
3c55046 to
a9fa485
Compare
a9fa485 to
1e2c2c2
Compare
1e2c2c2 to
556c29b
Compare
niik
left a comment
There was a problem hiding this comment.
The main/renderer token-resolution design looks robust. IPC replies are correlated and restricted to the active trusted renderer, account and token state are rechecked after asynchronous resolution, concurrent renewals are deduplicated, and requests fail closed rather than sending stale or unauthenticated credentials. Redirect/header handling and error redaction also look sound.
One adjacent non-blocking observation: OrderedWebRequest.onHeadersReceived appears to retain the same dormant cancel-response handling pattern fixed here for onBeforeSendHeaders, though no current production listener cancels in that phase.
471b26c to
c8412d4
Compare
Desktop's main process adds an `Authorization` header to requests for
GitHub Enterprise avatars and private repository images, using the
tokens the renderer sends with `update-accounts`. With short-lived
tokens, that snapshot can hold an expired access token, and only the
renderer's AccountsStore can renew it.
The image filter now asks the renderer for the token to use on each
authenticated image request:
- main (`authenticated-image-token-resolver.ts`) sends
`resolve-image-token` with a request id, the endpoint and the token
it knows about to the main window, and waits up to 35 seconds for
`resolved-image-token`. Replies from other windows, stale or unknown
request ids, and senders that aren't trusted are ignored. Pending
requests for an endpoint that disappears from `update-accounts`
(sign-out) are failed right away;
- the renderer (`authenticated-image-token-handler.ts`, installed in
index.tsx) answers with `AccountsStore.resolveToken`, which renews
the token if needed. Failures are logged without the error, which
can contain credentials, and answered with null;
- the filter only uses the reply if the account on that origin is
still the same sign-in (tracked with a per-origin session symbol
that survives token rotation but not sign-out). Otherwise, or if
resolution fails or times out, the request is cancelled rather than
sent with a stale token or none.
For existing plain tokens, `resolveToken` returns the token unchanged,
so images authenticate as before. The difference is one IPC round trip
per authenticated image request, and a cancelled request (a broken
image) instead of an unauthenticated one when the renderer can't
answer.
Supporting changes:
- `update-accounts` is only accepted from the main window's
WebContents, now exposed as `AppWindow.webContents`;
- `OrderedWebRequest.onBeforeSendHeaders` now returns a listener's
`{ cancel: true }` response. It used to break out of the loop and
return the request details, so a cancellation was silently dropped
and the request went ahead. No existing listener cancelled, so only
the new image cancellations are affected;
- the two new channels are added to the IPC channel contract.
Tests cover the filter (header injection, origin mapping for
github.com, cancellation on failure, sign-out and account changes
while resolving), the main-process resolver (timeouts, foreign or
stale replies, sign-out), and the renderer handler.
Co-authored-by: Copilot <[email protected]>
f24c2fe to
6ea6ebd
Compare
Description
Main adds
Authorizationto GHES avatar and private image requests using the account tokens sent withupdate-accounts, which can be out of date. It now asks the renderer (AccountsStore) for the token on each request.resolve-image-tokento the main window and waits up to 35 s forresolved-image-token. Replies from other windows, stale ids and untrusted senders are ignored. Pending requests fail when their account signs out.AccountsStore.resolveToken. Errors are logged without their content, which can include credentials.update-accountsis only accepted from the main window (AppWindow.webContents).OrderedWebRequest.onBeforeSendHeadersdropped a listener's{ cancel: true }. No existing listener cancelled.Behavior change for plain tokens: one extra IPC round trip per authenticated image, and a broken image instead of an unauthenticated request if the renderer can't answer.
Stack
Merge in order, starting with 1. Each PR builds, passes tests, and keeps production behavior on its own.
Validation
Release notes
Notes: no-notes