Skip to content

Copy profile pictures on Workers and discover missing user info endpoints - #414

Merged
tnkuehne merged 1 commit into
mainfrom
sso-userinfo-discovery
Nov 25, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
sso-userinfo-discovery

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

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.

Reviews (1) · Last reviewed commit: "Copy profile pictures on Workers and dis..." · Reviewed by Greptile

…ints

Picture requests passed redirect: "error", which Workers rejects before
sending. The helpers caught the error and reported an unreadable picture,
so hosted installations never copied a picture and cleared the provider
URLs from sign-up. They now use redirect: "manual": a redirect is a
non-2xx response, so it still reads as unreadable and its target is
never asked. A workerd test checks that the requests leave the runtime.

A company connection saved without a user info endpoint, for example
one its provider added after registration, treated an ID token without a
picture as no picture and removed the copy. The picture lookup now
discovers a missing user info endpoint, with the same checks as sign-in.
A failed discovery keeps the copy.
@tnkuehne
tnkuehne merged commit b91dc78 into main Nov 25, 2026
15 of 16 checks passed
@tnkuehne
tnkuehne deleted the sso-userinfo-discovery branch November 25, 2026 21:15
tnkuehne added a commit that referenced this pull request Nov 25, 2026
…ting (#416)

Hosted Entra group search always failed with "The company directory
could not be queried." Cloudflare Workers accepts only `redirect:
"follow"` and `"manual"` and throws `TypeError: Invalid redirect value`
for `"error"` before sending. Node accepts `"error"`, so the existing
tests passed. #414 fixed the same problem for profile pictures.

## Changes

- **Directory search** (`directory.ts`): the Entra token request and the
Microsoft Graph group search use `redirect: "manual"`. Both failed
independently on Workers. Their existing status checks reject a 3xx, so
credentials never leave the directory's own endpoints. Google Workspace
is unaffected; it takes the group-email path.
- **Installation reporting** (`reporting.ts`): the PostHog transport
uses `"manual"`. A 3xx fails the delivery, which the SDK handles like
any failed send. With reporting enabled on Workers, no batch was ever
sent.
- **Failed responses**: their bodies are released in the background, so
a cancellation that rejects or never settles cannot replace the reported
error, keep a token Graph rejected, or hold later searches.

Node-only calls (`telemetry.ts`, `runtime-management-node.ts`, the docs
IndexNow script) keep `"error"`.

## Tests

- `directory.worker.test.ts` runs the directory search in workerd
through Miniflare and records outbound requests. It covers a successful
token request and Graph search, and redirects from either, whose targets
receive no request. Both tests fail with `"error"` and pass with
`"manual"`.
- `directory.test.ts`: a token error whose body cancellation rejects
still reports the authentication error, and after a Graph 401 whose
cancellation never settles the next search gets a new token.
- `reporting.integration.test.ts` asserts the transport receives
`redirect: "manual"`. A redirect case checks that the batch is attempted
twice at the original URL, never at the target, and that both bodies are
cancelled. It fails without the 3xx handling.
- Type checks, Oxlint and Oxfmt pass.


<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to merge; no
actionable issues remain.</rp></ruby><a
href="https://app.greptile.com/api/retrigger?id=120015466&amp;sig=10a2a291fb6518d5ae673b992f4fe30c3a09187fb0919e3006ae3273e3a61aeb"><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%2F416&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
actionable issues remain.

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

The PR makes directory search and installation reporting work on Workers
without following redirects.
- Entra group searches can reach Microsoft Graph from Workers.
- Installation reports send batches from Cloudflare Workers.

The previous unread-body concern is addressed: both directory failure
branches call `cancel()`. No new actionable issues were found.
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (3) · Last reviewed commit: ["Release failed response
bodies without
w..."](19fe665)
· [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