Skip to content

Show profile pictures in apps - #409

Merged
tnkuehne merged 5 commits into
profile-picture-storefrom
app-profile-pictures
Nov 25, 2026
Merged

tnkuehne merged 5 commits into
profile-picture-storefrom
app-profile-pictures

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 Copy profile pictures from every sign-in provider #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 Copy profile pictures from every sign-in provider #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.

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

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

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.

Diagram

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
Loading

Reviews (5) · Last reviewed commit: "Keep the app picture when user info disc..." · Reviewed by Greptile

Comment thread packages/auth-proxy/src/picture.ts Resolved
Comment thread packages/auth-proxy/src/picture.ts Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs bfd0447 Nov 25 2026, 08:10 PM

Comment thread packages/auth-proxy/src/picture.ts Resolved
@tnkuehne
tnkuehne force-pushed the app-profile-pictures branch 2 times, most recently from 2e63741 to bfd0447 Compare November 25, 2026 20:09
Apps could not show people's pictures: the app CSP allows only the app's
own origin, and people who use only apps may never sign in to the control
plane. The app sign-in proxy now copies the picture at sign-in and
renewal and serves it itself:

- Entra photos come from Graph; Google and OIDC pictures from the ID
  token's picture URL, asked only at the provider's origin or Google's
  picture host. Widefleet's own app sign-in names the control plane's
  copy, which accepts that sign-in's access token for its own picture.
- Copies live in a new USER_PICTURES KV namespace, keyed by organization,
  issuer and subject. Each expires 30 days after its last write, and the
  provider is asked again at most once a day.
- /oauth2/pictures/{subject} on app origins serves them after the usual
  session and access checks, to everyone who may use the app.
- Apps receive x-auth-request-picture with the path and version; both
  starters expose it as user.picture.

Hosted provisioning creates the namespace and binds it to the runtime;
the self-hosted agent binds widefleet-user-pictures.
Missing and unreadable pictures now record when the provider was asked, so the daily limit applies to them too, and a provider that names no picture removes the copy. Embedded sign-in copies the Graph photo with the host token's access. The picture route moves out of the (auth) pages, which redirect requests without a browser session, so the app proxy's access token reaches it. The provisioning tests cover the new namespace.
Parallel renewals of one session asked the provider and wrote the same KV key at once. A write over KV's per-key limit failed the refresh and saved the session without its picture. Refreshes in one isolate now share their work, and a failed write keeps the stored version.
App sign-in through Google Workspace never named a picture: Google leaves it out of Workspace ID tokens. The proxy now reads the user info when the ID token names none, Google's for Workspace and the discovered endpoint for other OIDC providers, before it reports that there is no picture.
A failed discovery of the user info endpoint fell back to the ID token and removed the copy. It now keeps it, like a failed user info request.
@tnkuehne
tnkuehne force-pushed the app-profile-pictures branch from bfd0447 to 7ddc76b Compare November 25, 2026 20:17
@tnkuehne
tnkuehne merged commit 76c10e2 into main Nov 25, 2026
14 of 16 checks passed
@tnkuehne
tnkuehne deleted the app-profile-pictures branch November 25, 2026 20:24
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