Skip to content

auth: resolve private image tokens through the renderer [6/10] - #22941

Merged
sergiou87 merged 1 commit into
developmentfrom
short-lived-tokens-6-images
Oct 7, 2026
Merged

sergiou87 merged 1 commit into
developmentfrom
short-lived-tokens-6-images

Conversation

@sergiou87

@sergiou87 sergiou87 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Description

Main adds Authorization to GHES avatar and private image requests using the account tokens sent with update-accounts, which can be out of date. It now asks the renderer (AccountsStore) for the token on each request.

  • Main sends resolve-image-token to the main window and waits up to 35 s for resolved-image-token. Replies from other windows, stale ids and untrusted senders are ignored. Pending requests fail when their account signs out.
  • The renderer answers with AccountsStore.resolveToken. Errors are logged without their content, which can include credentials.
  • The filter only uses a reply if the same sign-in still owns the origin. Otherwise, or on failure or timeout, it cancels the request instead of sending it with a stale token or none.
  • update-accounts is only accepted from the main window (AppWindow.webContents).
  • Fix: OrderedWebRequest.onBeforeSendHeaders dropped 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.

  1. auth: add OAuth refresh-token protocol primitives [1/10] #22917 - OAuth protocol primitives
  2. auth: handle rejected API tokens in AccountsStore [2/10] #22937 - Token invalidation in AccountsStore
  3. auth: add versioned secure-storage format for credentials [3/10] #22938 - Versioned credential storage
  4. auth: coordinate OAuth token renewal in AccountsStore [4/10] #22939 - Coordinated token renewal
  5. auth: hand Git fresh credentials [5/10] #22940 - Git credentials
  6. auth: resolve private image tokens through the renderer [6/10] #22941 - Private images (this PR)
  7. auth: let Copilot sessions renew GitHub tokens [7/10] #22942 - Copilot SDK sessions
  8. auth: request refreshable OAuth tokens at sign-in [8/10] #22943 - Sign-in with refreshable tokens (behind flag)
  9. docs: describe refresh-token rollout and recovery [9/10] #22919 - Rollout and recovery documentation
  10. auth: log automatic sign-outs [10/10] #22959 - Log automatic sign-outs

Validation

  • tsc and lint pass.
  • Full suite: 2,002 pass, one skipped, same four Git failures.

Release notes

Notes: no-notes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation safely handles token freshness, sender validation, account changes, failures, and cancellation with focused test coverage.

Review effort: Balanced
Findings: None

@sergiou87
sergiou87 marked this pull request as ready for review September 28, 2026 15:19
@sergiou87
sergiou87 requested a review from a team as a code owner September 28, 2026 15:19
@sergiou87
sergiou87 requested a review from BagToad September 28, 2026 15:19
@sergiou87
sergiou87 force-pushed the short-lived-tokens-6-images branch from 3c55046 to a9fa485 Compare October 2, 2026 11:28
@sergiou87
sergiou87 force-pushed the short-lived-tokens-6-images branch from a9fa485 to 1e2c2c2 Compare October 2, 2026 11:42
@sergiou87 sergiou87 changed the title auth: resolve private image tokens through the renderer [6/9] auth: resolve private image tokens through the renderer [6/10] Oct 2, 2026
@sergiou87
sergiou87 force-pushed the short-lived-tokens-6-images branch from 1e2c2c2 to 556c29b Compare October 2, 2026 12:18
niik
niik previously approved these changes Oct 2, 2026

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sergiou87
sergiou87 force-pushed the short-lived-tokens-6-images branch from 471b26c to c8412d4 Compare October 5, 2026 11:35
Base automatically changed from short-lived-tokens-5-git to development October 7, 2026 12:37
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]>
@sergiou87
sergiou87 force-pushed the short-lived-tokens-6-images branch from f24c2fe to 6ea6ebd Compare October 7, 2026 12:37
@sergiou87
sergiou87 merged commit e840cc6 into development Oct 7, 2026
9 checks passed
@sergiou87
sergiou87 deleted the short-lived-tokens-6-images branch October 7, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants