Skip to content

fix(client-web-kit): observe the promise-share wrapper's derived promise - #3214

Merged
tada5hi merged 2 commits into
masterfrom
fix/store-promise-share-rejection
Jul 10, 2026
Merged

tada5hi merged 2 commits into
masterfrom
fix/store-promise-share-rejection

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Plan-045 PR 1 (characterization pass) — the new store lifecycle specs exposed a real defect, fixed here alongside the suite that caught it.

Fix: createPromiseShareWrapperFn (the dedup wrapper around resolve() / refreshSession()) attached its clear-callback via .finally() and dropped the derived promise. Whenever the shared promise rejected — any failed refresh or resolve — that derived promise rejected unobserved, producing an unhandledrejection alongside the properly handled one (console noise in browsers, and a potential process-level unhandled rejection during SSR with restored cookies). The callback now rides .then(clear, clear), which never rejects. No behavioral change otherwise.

Characterization tests (test/unit/core/store/lifecycle.spec.ts, install-cookies.spec.ts) pin the store's current observable behavior ahead of the plan-045 auth-state redesign:

  • login dispatcher event order, incl. expire-date-before-token and the missing REALM_UPDATED on introspection (the realm cookie is never persisted from that path)
  • login failure modes: dangling LOGGING_IN; the tokenResolved latch that leaves a token-only session whose realm never resolves
  • logout() local-only semantics: both token revokes, swallowed revoke failures, no /sessions request (plan-041 invariant)
  • resolve(): refresh-failure cleanup (no RESOLVED), the refresh retry branch, the anonymous RESOLVING/RESOLVED no-op, promise-sharing across concurrent calls
  • exchangeAuthorizationCode: success-path cleanup revoking the previous tokens with no lifecycle events; failure leaves prior state intact
  • id_token retention across a refresh grant end-to-end
  • installStore cookie bridge: synchronous hydration (incl. the write-back echo), per-event persistence on login, full unset on logout

Test plan

  • npm run test --workspace=packages/client-web-kit — 12 files, 69 tests green
  • new specs type-checked strict via ad-hoc vue-tsc --noEmit (kit has no check:types script)
  • npm run build -w packages/client-web-kit green

tada5hi added 2 commits July 10, 2026 10:30
createPromiseShareWrapperFn attached its clear-callback via .finally() and
dropped the derived promise — every rejected refreshSession()/resolve()
produced an unobserved rejection alongside the handled one (console noise
in browsers, a potential process-level unhandledRejection during SSR).
Attach the callback via .then(clear, clear) instead.
…idge

Plan-045 PR 1 — pin current observable store behavior before the
auth-state redesign:

- login dispatcher event ORDER incl. the expire-date-before-token
  ordering and the missing REALM_UPDATED on introspection (realm cookie
  is never persisted from that path)
- login failure modes: dangling LOGGING_IN, and the tokenResolved latch
  that leaves a token-only session whose realm never resolves
- logout local-only semantics: both token revokes, swallowed revoke
  failures, and the absence of any /sessions request
- resolve(): refresh-failure cleanup (no RESOLVED), the refresh retry
  branch after a failed introspection, the anonymous RESOLVING/RESOLVED
  no-op, and promise-sharing across concurrent calls
- exchangeAuthorizationCode: success-path cleanup revoking the previous
  tokens with no lifecycle events, and failure leaving prior state intact
- id_token retention across a refresh grant via resolve()
- installStore cookie bridge: synchronous hydration (incl. the write-back
  echo), per-event cookie persistence on login, full unset on logout
Copilot AI review requested due to automatic review settings July 10, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tada5hi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a34a7b8e-6c5f-4c29-a35a-0aa96c667c73

📥 Commits

Reviewing files that changed from the base of the PR and between f138d4c and 1fd6078.

📒 Files selected for processing (3)
  • packages/client-web-kit/src/core/store/create.ts
  • packages/client-web-kit/test/unit/core/store/install-cookies.spec.ts
  • packages/client-web-kit/test/unit/core/store/lifecycle.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/store-promise-share-rejection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3214

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3214

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3214

@authup/access

npm i https://pkg.pr.new/@authup/access@3214

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3214

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3214

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3214

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3214

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3214

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3214

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3214

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3214

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3214

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3214

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3214

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3214

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3214

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3214

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3214

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3214

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3214

commit: 1fd6078

@tada5hi
tada5hi merged commit 4b6d65d into master Jul 10, 2026
12 checks passed
@tada5hi
tada5hi deleted the fix/store-promise-share-rejection branch July 10, 2026 08:58
@github-actions github-actions Bot mentioned this pull request Jul 10, 2026
tada5hi added a commit that referenced this pull request Jul 10, 2026
…ore-apply contract

The #3214 characterization spec pinned the pre-047.3 login lifecycle; login()
now clears previous identity state between the grant and the apply, so the
unset events precede the apply sequence and REALM_UPDATED legitimately fires
exactly once (the cleanup unset — introspection still bypasses setRealm).
tada5hi added a commit that referenced this pull request Jul 10, 2026
…#3216)

* fix(server-core): reject clients without registered redirect_uri patterns at /authorize

OAuth 2.1 posture: a pattern-less client left data.redirect_uri entirely
unchecked (any attacker-supplied URI passed, merely flagged
redirectUriVerified=false) — the server would issue a code to an arbitrary
redirect target. The code-request verifier now throws redirect_uri_mismatch
for a client with no registered patterns, before any code issuance.
redirectUriVerified is false only when the request carries no redirect_uri.

* fix(client-web-kit): gate the authorize abort redirect on a verified redirect_uri

Every other redirect in the authorize ladder is gated on redirectUriVerified,
but AuthorizeForm.abort() navigated to codeRequest.redirect_uri
unconditionally — for a pattern-less client a user click on Deny was an open
redirect (error params only). The form now takes a fail-closed
redirectUriVerified prop threaded from Authorize.vue and renders a localized
stay-on-page notice instead of navigating when the redirect_uri is unverified.

* fix(client-web-kit): escape the select_account chooser when the user never resolves

loggedIn/realmId are truthy for ANY identity type, but the chooser needs the
resolved user — a non-user (client/robot) lingering session, or a transient
userinfo failure (userResolved latched true before the call), left the page
on a permanent spinner with no way forward; buildAuthorizeURL defaults
prompt=select_account, so this was the default path. A failed resolveUser()
no longer latches, the page re-resolves once, and a settled null user now
renders the account prompt in switch-only mode (AAccountPrompt hides
"Continue as" for an empty identityName) instead of the loading text. Also
fixes the promise-share wrapper spawning an unhandled rejection from its
internal .finally() chain whenever the shared promise rejects.

* fix(client-web-kit): clear previous identity state before applying a password grant

applyTokenGrantResponse deliberately retains an existing id_token when a
response carries none (the refresh path) — but login() applied the
password-grant response without a preceding cleanup(), so a stale id_token
survived onto a newly-authenticated user. Reused for account switching, an
RP-logout would then send the OLD user's id_token as id_token_hint and revoke
the wrong session. login() now runs cleanup() between the grant succeeding
and applying the response, mirroring exchangeAuthorizationCode.

* fix(server-core): fail closed on the end-session aud cross-check and resolve name-form client ids

Three fail-open shapes in OAuth2EndSessionService.verify():

- an aud-less verified hint paired with a request client_id silently skipped
  the cross-check (guarded on audiences.length > 0) — it now counts as
  unverified;
- the id_token aud is the client UUID, so a name-form client_id (web) always
  failed the cross-check and silently degraded the logout to the confirm
  page — a non-UUID client_id is now resolved (realm from the request hint,
  else the VERIFIED hint's own realm claim; never claims of an unverified
  hint, no master fallback) and compared by its resolved UUID, failing closed
  when it does not resolve;
- a supplied-but-unknown realm key degraded to an UNSCOPED client name lookup
  — it now skips client resolution entirely (no name, no redirect), and a
  name-form client_id with no realm key anywhere fails closed too (ambiguous:
  every realm has a built-in web client — same rule as the /authorize
  verifier). UUID client ids, including the sole-aud-derived one, resolve
  globally as before.

* fix: require a user sub_kind for the end-session auto-clear gate

The forced-logout CSRF gate in AEndSessionForm compared hintSub against the
local USER id but ignored the subject kind — the server revoke checks both
sub and sub_kind. The logout controller now forwards hintSubKind (verified
hints only) through the SSR page into the form, and the auto-clear requires
hintSubKind === 'user' in addition to the sub match; a missing kind fails
closed (no auto-clear).

* fix(server-core): fail closed on dangling realm relations in the authorize flow

The realm-binding gate dereferenced identity.data.realm.id unguarded, and the
code issuer read realm id/name the same way — a realm row deleted out from
under a live identity produced a raw TypeError → HTTP 500. The gate now
treats a missing realm relation as a mismatch (clean login_required, still no
identity data in the body) and the issuer throws identityInvalid before
building the code.

* fix(server-core): derive the at_hash digest from the id_token signing algorithm

buildOAuth2TokenHash hardcoded SHA-256 with a 16-byte left half — only
coincidentally correct while every key is RS256. The digest (and its
half-length, per OIDC Core §3.1.3.6) now follows the id_token's JWS alg
(*256→SHA-256/16, *384→SHA-384/24, *512→SHA-512/32; an unrecognized alg
throws instead of silently defaulting), and the authorization_code grant
passes the realm signing key's signature_algorithm, resolved via a
DI-injected key repository. Behavior today is unchanged; a future
multi-algorithm key can no longer silently mint wrong hashes.

* test(server-core): pin the prompt=login freshness window as the deliberate contract

The 60s promptLoginMaxAge window is a documented stateless approximation, not
an accident: a sub-window session satisfies prompt=login without re-auth (it
absorbs the hosted login→consent round-trip), an over-window session throws
login_required, and max_age=0 stays stricter than prompt=login (the
documented inversion). Also covers the dangling-realm login_required guard.

* docs: record the plan 047 hardening contracts in the architecture notes

- end-session aud cross-check: fail-closed shape + name-form client_id
  resolution and the fail-closed realm-key rules
- pattern-less clients rejected at /authorize; redirectUriVerified semantics
- AuthorizeForm abort gate, select_account chooser escape hatch, login()
  cleanup-before-apply, hintSubKind auto-clear gate
- at_hash digest derived from the signing alg; note that no c_hash is minted
  (code-only flow)
- prompt=login window pinned as deliberate contract; prompt=none client-side
  enforcement recorded as a known limitation (server-side silent path scoped
  separately)
- post_logout_redirect_uri column is text, the 2000-char cap is the request
  param validator's
- client-web logout page comment updated for the name-form client_id
  resolution

* test(client-web-kit): repin the login event order for the cleanup-before-apply contract

The #3214 characterization spec pinned the pre-047.3 login lifecycle; login()
now clears previous identity state between the grant and the apply, so the
unset events precede the apply sequence and REALM_UPDATED legitimately fires
exactly once (the cleanup unset — introspection still bypasses setRealm).
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.

2 participants