Skip to content

Copy profile pictures from every sign-in provider - #407

Merged
tnkuehne merged 6 commits into
mainfrom
profile-picture-store
Nov 25, 2026
Merged

tnkuehne merged 6 commits into
mainfrom
profile-picture-store

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Each Google, Microsoft or company SSO sign-in now copies the person's picture into the control plane's own store. Pages load it from Widefleet, never from the provider. Microsoft and Entra pictures, which have no URL, appear as well.

Why

The control plane showed provider picture URLs directly (#404). Microsoft and Entra supply the photo only as bytes from Microsoft Graph, and apps cannot load pictures from another origin. One copy per person covers every provider and gives apps a picture to serve (follow-up PR).

Changes

  • Copy on sign-in: The sign-in-picture plugin runs after /callback/:id and /sso/callback/:providerId.
    • Microsoft and Entra: it fetches /me/photos/120x120/$value from Graph with the sign-in's access token.
    • Google and company OIDC: it reads the ID token's picture claim. When the ID token names none, it reads the user info with the sign-in's access token: Google's (openidconnect.googleapis.com/v1/userinfo) for personal Google sign-in, because Google leaves picture out of Workspace accounts' ID tokens, and the connection's discovered endpoint for company SSO.
    • Which hosts it asks (fetchPictureUrl): only the provider's own origin, which receives the access token like its other endpoints, and Google's account picture host. Other hosts are never contacted, so no DNS check is needed. Redirects are not followed.
  • Scopes: Personal Microsoft sign-in requests User.Read. Saving an Entra company SSO connection adds User.Read, which its registration already grants for app membership checks.
  • Validation: PNG, JPEG, GIF or WebP up to 100 KB. The bytes decide the type; SVG is never stored. The fetch and validation live in @platform/auth-proxy/picture, so the app proxy can use them in the follow-up.
  • Store: A new user_picture table holds one row per user, outside the user row that Better Auth reads on every session lookup.
    • Deleting a user deletes the row (foreign key cascade).
    • Each write locks the user's row, so concurrent sign-ins leave the copy and user.image in agreement.
    • A sign-in whose picture cannot be read keeps the current copy. A provider that reports none (no picture in the ID token or user info, or Graph 404) removes it.
  • user.image: Holds /users/{id}/picture?v={version}, never a provider URL. The contract profileImage accepts only that path. A provider URL that Better Auth stores at sign-up is cleared when no copy can be made.
  • Claims: Widefleet's own ID tokens and user info carry picture as an absolute URL on the installation.
  • Route /users/{id}/picture:
    • Who sees what: a person always sees their own picture; others see it only as an administrator of an organization both belong to, the same rule as the member list. An organization that requires company SSO counts only for a company sign-in.
    • Caching: ETag with Cache-Control: private, no-cache, so the check runs on every view and removal from an organization takes effect.
    • Safety headers: nosniff, a sandboxing CSP and same-origin resource policy.
    • users joins the reserved organization slugs like the other top-level pages.

Existing Entra connections request User.Read after their next save in Company sign-in. Company OIDC providers that host pictures elsewhere than their own origin or Google's picture host show initials.

Documentation

apps/docs/docs/reference/social-sign-in.md says Microsoft sign-in requests openid, profile and email. It now also requests User.Read. Draft docs PR: #411.

Verification

  • packages/auth-proxy/src/picture.test.ts:
    • Fetching: type detection by bytes (SVG and HTML rejected), size limit, 404 vs. failure, no redirects.
    • Hosts: only the provider origin, which gets the bearer token, and Google's picture host; other, private and credentialed hosts are never requested.
    • Graph: request with the bearer token.
  • social-sign-in.test.ts: Google copies the picture and leaves name and email unchanged. SVG and http pictures are not copied. A Workspace sign-in without the claim copies the picture from Google's user info, keeps the copy when user info fails, and reports none when user info names none. Microsoft asks Graph with the stored access token.
  • company-sso-plugin.integration.test.ts: a company OIDC sign-in stores a copy from its ID token; a returning sign-in that names a new picture only in its user info replaces the copy. Both cover registered and migrated (runtime-discovered) connections.
  • user-pictures.integration.test.ts: replacing and removing a copy; cascade on user deletion; visibility for the owner, an administrator of a shared organization, and not for members, other organizations, an organization that requires company SSO, or after leaving.
  • organization-settings.integration.test.ts: a saved Entra connection requests User.Read.
  • organization-sso.integration.test.ts: Widefleet's app sign-in ID token and user info carry the absolute picture URL.
  • Rendered the member list and sidebar from a real server with copied pictures: all three images load through the route with the session cookie. The look is unchanged from Show profile pictures from sign-in providers in the control plane #404.
  • svelte-check, Oxlint and Oxfmt are clean. runtime-errors.integration.test.ts needs a built server and fails on main the same way locally.

Not verified against a real Microsoft tenant: the Entra and personal Microsoft Graph calls are covered with synthetic responses.

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.

Summary

Copies provider pictures into user_picture during sign-in and serves them through an access-checked route.

  • Sign-ins copy profile pictures into Widefleet’s own store.
  • The control plane serves profile pictures through a checked Widefleet route.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Provider sign-in] --> B[Read picture claims or Graph photo]
  B --> C[Check host, size and image type]
  C --> D[Lock user row]
  D --> E[Save picture and local path together]
  E --> F[Picture request]
  F --> G[Check current access]
  G --> H[Return image or 304]
Loading

Reviews (6) · Last reviewed commit: "Keep the picture when user info discover..." · Reviewed by Greptile

Comment thread packages/auth-proxy/src/picture.ts Resolved
The control plane showed provider picture URLs directly. Microsoft and
Entra have no picture URL, and apps cannot load pictures from other
origins. Each Google, Microsoft or company SSO sign-in now copies the
user's picture into a user_picture table:

- Google and company OIDC: the picture URL from the ID token, or the
  sign-up copy for providers that name it only in their user info. Only
  HTTPS URLs on public hosts are fetched, without following redirects.
- Microsoft and Entra: the photo from Microsoft Graph. Personal Microsoft
  sign-in and Microsoft company SSO connections request User.Read.

Only PNG, JPEG, GIF and WebP up to 100 KB are kept; the bytes decide the
type. A sign-in whose picture cannot be read keeps the current copy, and
a provider that reports none removes it.

user.image names the copy at /users/{id}/picture with a version, never a
provider URL. The route shows a picture to its owner and to
administrators of an organization both belong to. It sends an ETag and
revalidates, so that check runs on every view. Pictures live outside the
user row, which Better Auth reads on every session lookup, and are
deleted with the user.
Picture URLs were fetched from any host that resolved to public addresses,
but the connection could resolve again to a private one, and a stalled DNS
lookup held up sign-in. Pictures now come only from the provider's own
origin, with its access token, or from Google's account picture host. The
fetch moves to @platform/auth-proxy/picture for the app proxy.

Company SSO sign-ins without a picture claim read the user info, so
providers that name the picture only there keep it current.

Saving locks the user's row, so concurrent sign-ins leave the copy and
user.image in agreement.
A sign-in whose ID token, or user info for company SSO, names no picture now removes the copy instead of keeping it. A failed read still keeps it.
Google leaves the picture claim out of the ID tokens of Workspace accounts, so personal Google sign-in never refreshed their pictures and, since the copy is removed when no picture is named, removed it. Sign-ins whose ID token names no picture now read the provider's user info: Google's for personal Google sign-in, the connection's for company SSO. No picture is reported only when the user info names none; unreadable user info keeps the copy. The user-info reading lives in @platform/auth-proxy/picture for the app proxy.
A company connection whose user info endpoint could not be discovered fell back to the ID token, which names no picture, and removed the copy. A failed discovery now keeps it.
@tnkuehne
tnkuehne force-pushed the profile-picture-store branch from 211c41b to b6e9332 Compare November 25, 2026 20:17
@tnkuehne
tnkuehne merged commit bc81678 into main Nov 25, 2026
16 checks passed
@tnkuehne
tnkuehne deleted the profile-picture-store branch November 25, 2026 20:24
tnkuehne added a commit that referenced this pull request Nov 25, 2026
Apps now get each signed-in person's profile picture from their own
address. The app sign-in proxy copies the picture when someone signs in
to an app. It serves it at `/oauth2/pictures/{subject}` on every app
origin of the organization and names it in a new
`x-auth-request-picture` header.

Stacked on #407.

## Why

The control plane keeps its own copy of each person's picture (#407),
but apps cannot use it:
- The app CSP allows images only from the app's own origin.
- People who only use apps through company SSO may never sign in to the
control plane.

The proxy already holds the company sign-in's tokens and serves every
app origin, so it copies and serves the picture itself. It never asks
the control plane.

## Changes

- **Copy at app sign-in and renewal:** `getUserInfo` in the auth proxy
reads the picture with the shared `providerPicture`:
- Entra: Graph `/me/photos/120x120/$value`. The proxy already requests
`User.Read`.
- Google Workspace and company OIDC: the ID token's `picture`, or the
user info when the ID token names none (Google's endpoint for Workspace,
whose ID tokens never carry `picture`; the discovered endpoint for
OIDC). Only the provider's own origin, with the access token, or
Google's account picture host is asked for the picture.
- Widefleet's own app sign-in: the absolute `picture` claim from #407.
The proxy fetches it from the installation with the sign-in's access
token. `/users/{id}/picture` accepts that token for the person's own
picture only (`tokenViewer`). The route moves out of the `(auth)` pages,
which would send a request without a browser session to sign-in.
- Embedded sign-in (Microsoft Teams): the photo from Graph with the host
token's access, saved in the embedded session too.
  - A sign-in that names no picture reports none and removes the copy.
  - Failure handling: a failed picture never blocks sign-in or renewal.
- **Storage:** A new KV namespace, `USER_PICTURES`, bound to the app
runtime.
- Key: organization, issuer hash and subject. Value: the bytes, with
content type, version and check time as metadata.
- Each entry expires 30 days after its last write. People who stop
signing in lose their copy without cleanup code.
- Sign-in and renewal ask the provider at most once a day, whatever it
answered last time. No picture is stored as an entry without bytes; a
failed read rewrites the current copy with the new check time.
- **Serving:** `/oauth2/pictures/{subject}` on app origins.
- The proxy answers after the normal session, renewal and app-access
checks. Everyone who may use the app sees the pictures of the
organization's people.
- It sends `ETag`, `private, no-cache`, `nosniff`, a sandboxing CSP and
`same-origin` resource policy. The request never reaches app code.
- **Identity:** The session identity carries the picture version. Apps
receive `x-auth-request-picture: /oauth2/pictures/{subject}?v={version}`
when the person has one, without a KV read per request.
- **Starters:** `locals.user` / `context.user` gain `picture` (path or
`null`). Local development uses `null`.
- **Bindings:**
- Hosted: provisioning creates `{installation}-user-pictures` and binds
it to the runtime.
- Self-hosted: the agent binds `widefleet-user-pictures` (`runtime.rs`,
`execution.rs`).
  - Development: `wrangler.jsonc` declares the binding.

## Documentation

Draft docs PR #411 describes `user.picture` for app creators and the
`User.Read` permission.

## Verification

- `edge/auth-proxy-sessions.test.ts`, run for OIDC and for Entra:
- Signing in through the proxy copies the provider's picture (OIDC on
the issuer origin with the bearer token, Entra through Graph) and
forwards `x-auth-request-picture`.
- The path returns the PNG and answers `304` for its ETag; without a
session it answers `401`.
- `edge/auth-proxy-google.test.ts`: a Workspace app sign-in copies the
picture named in Google's user info and serves it on the app's origin.
- `organization-sso.integration.test.ts`: the access token of
Widefleet's app sign-in reads its own picture through `tokenViewer`, not
another person's; an invalid token reads nothing.
- `packages/auth-proxy/src/picture.test.ts`: the shared fetch rules
(from #407) and the store, which asks at most once a day for a picture,
no picture or a failure.
- `edge/auth-proxy-embedded.test.ts`: embedded sign-in forwards the
copied Graph photo.
- `cloudflare/hosted-installation.test.ts`: the runtime binds
`USER_PICTURES`, the control plane only `AUTH_CONFIG`; provisioning
creates and reuses both namespaces.
- Typecheck, Oxlint and Oxfmt are clean for the control plane, auth
proxy, app runtime and both starters. The vitest suite for
`apps/control-plane` and `packages` passes except
`runtime-errors.integration.test.ts`, which needs a built server and
fails on `main` locally.
- Not run locally: Rust (`cargo` is not installed here), so CI checks
`runtime.rs` and `execution.rs`. The installed self-hosted runtime with
the new namespace is not exercised end to end.




<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to merge; no
new actionable issues remain.</rp></ruby><a
href="https://app.greptile.com/api/retrigger?id=119742796&amp;sig=d07b89cc4d981b4bff8c1b9dcc46b0d19055e16dab1fcedab98bf0726dd53226"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F409&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no new
actionable issues remain.

<details open><summary><h3>Summary</h3></summary>

Apps receive profile pictures through their own origin.
- App sign-ins copy the picture reported by their provider.
- Apps can load organization pictures from their own origin.
- App runtimes receive a separate picture store.

The current code addresses all six previous unnumbered findings. No new
actionable issues were found.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
sequenceDiagram
  participant Provider
  participant Proxy as App sign-in proxy
  participant KV as USER_PICTURES
  participant App
  participant Browser
  Provider->>Proxy: Verified identity and access token
  Proxy->>KV: Read last picture check
  opt Daily check is due
    Proxy->>Provider: Request picture
    Proxy->>KV: Save result and check time
  end
  Proxy->>App: Forward identity and picture path
  Browser->>Proxy: Request picture on app origin
  Proxy->>Proxy: Check session and app access
  Proxy->>KV: Read picture
  Proxy-->>Browser: Picture bytes or 304
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (5) · Last reviewed commit: ["Keep the app picture when
user info
disc..."](7ddc76b)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
tnkuehne added a commit that referenced this pull request Nov 25, 2026
…ints (#414)

Hosted installations never copied a profile picture after #407 and #409.
Every sign-in cleared the provider URL from sign-up and left people with
initials.

## Cause

The picture fetches in `packages/auth-proxy/src/picture.ts` passed
`redirect: "error"`. Cloudflare Workers accepts only `"follow"` and
`"manual"` and throws `TypeError: Invalid redirect value` before
sending. The helpers caught it and reported an unreadable picture, so
image downloads, user info requests and the app proxy's discovery never
left the Worker. Node accepts `"error"`, so the existing tests passed.

## Changes

- **Redirect mode.** The three picture fetches (image, user info,
discovery) use `redirect: "manual"`. A redirect is a non-2xx response,
so it still reads as unreadable and its target is never requested.
- **Missing user info endpoint.** A company connection saved without
`userInfoEndpoint` treated an ID token without `picture` as no picture
and removed the copy. This happens, for example, when the provider adds
the endpoint after registration: same-issuer saves keep the three
sign-in endpoints and skip discovery.
- `prepareCompanyOidc` takes `{ discoverMissingUserInfo: true }`, which
also discovers when the user info endpoint is missing. Saved endpoints
keep precedence and every endpoint gets the same checks as at sign-in.
- Only the picture lookup passes the option, and a failed discovery
keeps the copy.

## Tests

- `packages/auth-proxy/src/picture.worker.test.ts` runs the shared
helpers in workerd through Miniflare and records the outbound requests.
It covers OIDC through discovery and user info, the Microsoft Graph
photo, and redirects from user info and from a picture URL, whose
targets receive no request. With `"error"` all three tests fail; with
`"manual"` they pass.
- `company-sso-plugin.integration.test.ts` adds a `partial` connection.
It is registered while discovery advertises no user info endpoint, then
the endpoint appears and a returning sign-in without an ID-token picture
copies the user info picture. A failed discovery keeps the copy, and
discovery that still omits the endpoint removes it. Without the source
changes the case fails. The `registered` connection still refreshes from
its saved endpoint without discovery.
- `picture.test.ts` checks the redirect mode and that a 302 reads as
unreadable.
- Type checks, Oxlint and Oxfmt pass. The `packages` and
`apps/control-plane` suites pass except
`runtime-errors.integration.test.ts`, which needs a built server and
fails on `main` the same way locally.


<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to
merge.</rp></ruby><a
href="https://app.greptile.com/api/retrigger?id=119991947&amp;sig=8ae276a82c3b297d32f0a6b03f0d34e2a4d6434c9fe714f3a305a18a13f4d627"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F414&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge.

<details open><summary><h3>Summary</h3></summary>

Fixes picture downloads on Cloudflare Workers and finds missing company
user info endpoints during picture lookup.
- Provider pictures can now be fetched from Workers without following
redirects.
- Company sign-ins can find user-info endpoints added after connection
setup.

No actionable issues were found. Tests were inspected but not run during
this review.
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (1) · Last reviewed commit: ["Copy profile pictures on
Workers and
dis..."](c5a4aad)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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.

1 participant