Skip to content

Require the client secret again when an SSO update moves its destination - #417

Merged
tnkuehne merged 4 commits into
mainfrom
fix/sso-secret-destination
Nov 26, 2026
Merged

tnkuehne merged 4 commits into
mainfrom
fix/sso-secret-destination

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The SSO plugin keeps a saved client secret when an update omits it (mergeOIDCConfig), and sign-in sends that secret to the token endpoint. An administrator could therefore change the issuer without entering a new secret, and the next sign-in sent the saved secret to the new issuer, although the secret is never shown to administrators. Better Auth refuses issuer changes once accounts are linked, so this applied to connections without linked accounts, for example during setup.

Changes

  • SSO update hook (plugin-authentication.ts). An update of a provider with a saved client secret must supply the secret again when it changes the issuer, the token endpoint or the discovery endpoint. Otherwise it fails with Enter the client secret again to change the issuer or token endpoint. The check runs for every /sso/update-provider call, including saves through the settings service.
  • Updates that keep the destination still keep the saved secret, so other changes save without re-entering it.
  • One SSO save per organization at a time (sso-settings.ts). The hook checks the saved provider before its DNS lookups, and the plugin merges the update after them. A save held up in between, for example by a slow DNS answer for a host the administrator controls, could otherwise merge a secret that another save entered meanwhile. saveSsoProvider now holds a transaction-scoped advisory lock per organization around the whole save. A second save fails with Another SSO change is still in progress. Try again shortly. instead of waiting, because waiting saves would hold the pool connections the running save needs. The settings service is the only caller of the SSO plugin endpoints, which are not reachable over HTTP.
  • Connection form (SsoConnectionFields.svelte). The form only exposes the issuer, not the endpoints. Once the issuer differs from the saved one, the client secret field is required and its hint reads The issuer changed. Enter the client secret again. instead of Leave blank to keep the saved secret.

Testing

  • pnpm check
  • tests/company-sso-plugin.integration.test.ts: a new case changes the issuer through the settings service, and the token and discovery endpoints through the plugin API, each without a secret. All are refused and the stored configuration stays unchanged. A mapping change without the secret and an issuer change with a new secret are saved. The new case fails without the fix.
  • tests/company-sso-plugin.integration.test.ts: a save while the organization's SSO lock is held is rejected, and succeeds once the lock is released. The case fails without the lock.
  • tests/settings.integration.test.ts: twelve concurrent saves, more than the pool's connections, all settle. At least one succeeds and the others are rejected with the conflict message.
  • tests/organization-settings.integration.test.ts, tests/self-hosted-sso.integration.test.ts
  • tests/e2e/onboarding.spec.ts: editing a saved connection, a changed issuer makes the secret required with the new hint, and restoring the issuer brings back the old hint. The steps fail without the form change.

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

The PR requires administrators to re-enter the client secret when an SSO update changes its destination.

  • SSO updates require a new secret when their sign-in destination changes.
  • SSO saves for one organization run one at a time.

Both earlier, unnumbered findings are addressed: saves share the organization lock, and the mapping test now saves and checks given_name.

Reviews (3) · Last reviewed commit: "Ask for the client secret again when the..." · Reviewed by Greptile

The SSO plugin keeps a saved client secret when an update omits it, and
sign-in sends that secret to the token endpoint. An update that changed the
issuer without a new secret therefore sent the saved one to the new issuer.
Updates that change the issuer, token endpoint or discovery endpoint now
have to supply the client secret.
@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 85c596c Nov 26 2026, 09:47 AM

The update check reads the saved provider before its DNS lookups, and the
plugin merges the update after them. A save held up in between could merge
a client secret that another save entered into a destination the check had
accepted against the earlier state. SSO saves now hold an advisory lock per
organization. A second save is rejected instead of waiting, because waiting
saves would hold the pool connections the running save needs.
The connection form said to leave the secret blank to keep the saved one,
also after the issuer was changed, and the save then failed. Once the
issuer differs from the saved one, the secret field is required and its
hint says to enter the secret again.
@tnkuehne
tnkuehne merged commit e5f88f6 into main Nov 26, 2026
14 of 16 checks passed
@tnkuehne
tnkuehne deleted the fix/sso-secret-destination branch November 26, 2026 09:51
tnkuehne added a commit that referenced this pull request Nov 26, 2026
#417 runs the SSO saves of one organization one at a time and rejects a
save that overlaps a running one with `Another SSO change is still in
progress. Try again shortly.`
`shared-sso-registration.integration.test.ts` still expected the
overlapping save to finish after the first one, so it fails on `main`.

## Changes

- `keeps the native provider and app claims together when settings saves
overlap` becomes `rejects an overlapping settings save and keeps the
running save's provider and app claims together`. The second save,
started while the first waits between the native provider and the
remaining settings write, is now expected to fail with the conflict
message. The saved provider and the published app claims both carry the
first save's values.
- The first save keeps the OIDC claim type and the rejected one switches
to Entra, so the final state is checked against an issuer that does not
need to be tenant-specific.

## Testing

- `pnpm check`
- `tests/shared-sso-registration.integration.test.ts`


<!-- 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=120634052&amp;sig=723a23ae5b49c67f771a2774a5ff5dd4e6a38d40ca4df40fc7c0623bc99eb559"><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%2F420&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>

Updates the overlapping SSO save test to match the existing rejection
behavior.
- The SSO overlap test now expects the second save to be rejected.
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (1) · Last reviewed commit: ["Expect an overlapping SSO
save to be
rej..."](30311a5)
· [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