@sparkvault/sdk-js 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -497,14 +497,16 @@ declare class IdentityModule {
497
497
  * Decode an identity token's claims WITHOUT verifying its signature.
498
498
  *
499
499
  * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
500
- * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
501
- * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
502
- * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
503
- * result MUST NOT be trusted for any authorization decision.
500
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (accepting
501
+ * only the algorithms the Identity server signs with, so an unsigned or
502
+ * algorithm-confused token cannot masquerade as valid). It does NOT verify the
503
+ * signature, so its result MUST NOT be trusted for any authorization decision.
504
504
  *
505
505
  * To trust a token (e.g. before keying records by `claims.svid`), verify the
506
- * Ed25519 signature server-side against the Identity JWKS endpoint
507
- * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
506
+ * signature server-side against the Identity JWKS endpoint
507
+ * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`), which
508
+ * publishes the EdDSA and RS256 keys and selects the verifying key by `kid`.
509
+ * See docs/SDK.md.
508
510
  */
509
511
  decodeToken(token: string): TokenClaims;
510
512
  /**
@@ -579,7 +581,7 @@ declare class IdentityModule {
579
581
  private consumeSignInPending;
580
582
  /** Remove the result fragment from the URL bar (and history entry). */
581
583
  private clearUrlFragment;
582
- /** Drop the one-shot PKCE state/verifier (+ recovery hint) a bounce staged. */
584
+ /** Drop the one-shot PKCE state/verifier a bounce staged. */
583
585
  private clearOneShotAuthState;
584
586
  private consumeRedirectResult;
585
587
  /**
package/dist/index.mjs CHANGED
@@ -8569,23 +8569,16 @@ function attachClickHandler(selector, onClick) {
8569
8569
  * sv.products.identity.attach('.login-btn');
8570
8570
  */
8571
8571
  const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
8572
+ // The exact algorithms the Identity server signs identity tokens with: EdDSA by
8573
+ // default, RS256 when a client opts in via `id_token_signed_response_alg`. The
8574
+ // unverified client-side decode gates on this set so an unsigned (`none`) or
8575
+ // algorithm-confused token cannot masquerade as valid.
8576
+ const ACCEPTED_TOKEN_ALGS = ['EdDSA', 'RS256'];
8572
8577
  // A sign-in is "pending" from popup open until its result arrives; a marker
8573
8578
  // that outlives a lost result (a mobile opener-tab discard clears the message
8574
8579
  // listener but not sessionStorage) is what lets the next load self-heal.
8575
8580
  const PENDING_KEY = 'sv_signin_pending';
8576
8581
  const PENDING_TTL_MS = 10 * 60 * 1000;
8577
- // One-shot: the identifier the recovery bounce is re-minting for. Written only
8578
- // by the recovery bounce; the return leg consumes it to verify the redeemed
8579
- // result is for that same account (see consumeHandoffFragment).
8580
- const RECOVERY_HINT_KEY = 'sv_recovery_hint';
8581
- /**
8582
- * Normalize an identifier for equality, mirroring the server: trim, and
8583
- * lowercase emails (a value containing '@'). Phones compare trimmed-exact.
8584
- */
8585
- function normalizeIdentity(value) {
8586
- const trimmed = value.trim();
8587
- return trimmed.includes('@') ? trimmed.toLowerCase() : trimmed;
8588
- }
8589
8582
  /**
8590
8583
  * Read and parse the pending marker — JSON `{ at, hint }`, where `hint` is the
8591
8584
  * email or phone the sign-in was started with (null when the flow collects the
@@ -8981,14 +8974,16 @@ class IdentityModule {
8981
8974
  * Decode an identity token's claims WITHOUT verifying its signature.
8982
8975
  *
8983
8976
  * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
8984
- * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
8985
- * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
8986
- * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
8987
- * result MUST NOT be trusted for any authorization decision.
8977
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (accepting
8978
+ * only the algorithms the Identity server signs with, so an unsigned or
8979
+ * algorithm-confused token cannot masquerade as valid). It does NOT verify the
8980
+ * signature, so its result MUST NOT be trusted for any authorization decision.
8988
8981
  *
8989
8982
  * To trust a token (e.g. before keying records by `claims.svid`), verify the
8990
- * Ed25519 signature server-side against the Identity JWKS endpoint
8991
- * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
8983
+ * signature server-side against the Identity JWKS endpoint
8984
+ * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`), which
8985
+ * publishes the EdDSA and RS256 keys and selects the verifying key by `kid`.
8986
+ * See docs/SDK.md.
8992
8987
  */
8993
8988
  decodeToken(token) {
8994
8989
  if (!token || typeof token !== 'string') {
@@ -9003,10 +8998,12 @@ class IdentityModule {
9003
8998
  if (typeof header !== 'object' || header === null) {
9004
8999
  throw new ValidationError('Invalid token header');
9005
9000
  }
9006
- // Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
9007
- // tokens are Ed25519-signed; anything else is an unsigned or algorithm-
9008
- // confused token that could never pass server-side JWKS verification.
9009
- if (header.alg !== 'EdDSA') {
9001
+ // Accept exactly the algorithms the Identity server signs with; reject
9002
+ // everything else — `none` (unsigned), a symmetric or algorithm-confused
9003
+ // token, or an absent alg — none of which could pass the server-side JWKS
9004
+ // verification the host performs before trusting the token.
9005
+ const alg = header.alg;
9006
+ if (typeof alg !== 'string' || !ACCEPTED_TOKEN_ALGS.includes(alg)) {
9010
9007
  throw new ValidationError('Unsupported token algorithm');
9011
9008
  }
9012
9009
  const payload = JSON.parse(base64urlToString(payloadB64));
@@ -9087,11 +9084,9 @@ class IdentityModule {
9087
9084
  // (and a StrictMode double-invocation finds an empty hash and no-ops).
9088
9085
  let expectedState = null;
9089
9086
  let codeVerifier = null;
9090
- let expectedRecoveryIdentity = null;
9091
9087
  try {
9092
9088
  expectedState = sessionStorage.getItem('sv_oauth_state');
9093
9089
  codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
9094
- expectedRecoveryIdentity = sessionStorage.getItem(RECOVERY_HINT_KEY);
9095
9090
  this.clearOneShotAuthState();
9096
9091
  }
9097
9092
  catch {
@@ -9112,6 +9107,12 @@ class IdentityModule {
9112
9107
  if (!codeVerifier) {
9113
9108
  throw new ValidationError('Sign-in session was lost — please sign in again.');
9114
9109
  }
9110
+ // WHICH account the code carries is settled where it is minted, never
9111
+ // here: the code is PKCE- and origin-bound to this tab, and a recovery
9112
+ // bounce only ever mints for the account its `login_hint` named (see
9113
+ // startRecoveryBounce). The redeemed result exposes just that account's
9114
+ // PRIMARY identifier — not necessarily the one the caller signed in
9115
+ // with — so re-checking it here could only discard valid sign-ins.
9115
9116
  const raw = await this.api.redeemHandoffCode(code, codeVerifier);
9116
9117
  const result = {
9117
9118
  token: raw.token,
@@ -9121,18 +9122,6 @@ class IdentityModule {
9121
9122
  sessionId: raw.session_id ?? undefined,
9122
9123
  refreshToken: raw.refresh_token ?? undefined,
9123
9124
  };
9124
- // A recovery bounce carries the identifier the interrupted sign-in was
9125
- // addressing, but /sso treats a hint matching no hub session like no hint
9126
- // at all (anti-oracle) — so the bounce can come back holding a DIFFERENT
9127
- // single-eligible account. The client is the one place that knows which
9128
- // account the person was signing in to: a mismatched result is discarded,
9129
- // never handed to the host (a wrong-account handoff). Silent — no
9130
- // onError — falling through to interactive sign-in, matching the recovery
9131
- // flow's non-oracle posture.
9132
- if (expectedRecoveryIdentity &&
9133
- normalizeIdentity(expectedRecoveryIdentity) !== normalizeIdentity(result.identity)) {
9134
- return null;
9135
- }
9136
9125
  options.onSuccess?.(result);
9137
9126
  return result;
9138
9127
  }
@@ -9153,22 +9142,12 @@ class IdentityModule {
9153
9142
  */
9154
9143
  async startRecoveryBounce(loginHint) {
9155
9144
  const sso = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/sso`);
9156
- // With several hub sessions, login_hint tells /sso which account the
9157
- // interrupted sign-in was addressing, so recovery never re-mints another.
9158
- // Also stash it one-shot: a hint matching no hub session deliberately
9159
- // behaves server-side like no hint at all (anti-oracle), so the return leg
9160
- // must verify the redeemed identity is the one this sign-in was for.
9161
- try {
9162
- if (loginHint) {
9163
- sessionStorage.setItem(RECOVERY_HINT_KEY, loginHint);
9164
- }
9165
- else {
9166
- sessionStorage.removeItem(RECOVERY_HINT_KEY);
9167
- }
9168
- }
9169
- catch {
9170
- // No storage → prepareHandoffNavigation bails below; nothing to verify.
9171
- }
9145
+ // With several hub sessions, login_hint names the account the interrupted
9146
+ // sign-in was addressing, and it is the whole wrong-account defence: /sso
9147
+ // mints silently ONLY for a hint that matched exactly one hub session's
9148
+ // verified identifiers — every unsatisfiable hint (a stranger's address, an
9149
+ // ambiguous match, an account not eligible here) comes back with no result
9150
+ // at all rather than a different account's.
9172
9151
  if (loginHint) {
9173
9152
  sso.searchParams.set('login_hint', loginHint);
9174
9153
  }
@@ -9176,16 +9155,6 @@ class IdentityModule {
9176
9155
  if (nav) {
9177
9156
  window.location.assign(nav);
9178
9157
  }
9179
- else {
9180
- // The bounce never left (no storage or WebCrypto) — retire the stash so
9181
- // it cannot linger into an unrelated later return leg.
9182
- try {
9183
- sessionStorage.removeItem(RECOVERY_HINT_KEY);
9184
- }
9185
- catch {
9186
- // Storage disabled: nothing was persisted, nothing to clear.
9187
- }
9188
- }
9189
9158
  }
9190
9159
  /**
9191
9160
  * Explicit `flow: 'redirect'` — navigate this tab to the interactive sign-in
@@ -9285,12 +9254,11 @@ class IdentityModule {
9285
9254
  window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
9286
9255
  }
9287
9256
  }
9288
- /** Drop the one-shot PKCE state/verifier (+ recovery hint) a bounce staged. */
9257
+ /** Drop the one-shot PKCE state/verifier a bounce staged. */
9289
9258
  clearOneShotAuthState() {
9290
9259
  try {
9291
9260
  sessionStorage.removeItem('sv_oauth_state');
9292
9261
  sessionStorage.removeItem('sv_pkce_verifier');
9293
- sessionStorage.removeItem(RECOVERY_HINT_KEY);
9294
9262
  }
9295
9263
  catch {
9296
9264
  // Storage disabled: nothing was persisted, nothing to clear.
@@ -14793,7 +14761,7 @@ class SparkVault {
14793
14761
  }
14794
14762
  /** Get the SDK version */
14795
14763
  static get version() {
14796
- return '9.0.0';
14764
+ return '9.1.0';
14797
14765
  }
14798
14766
  }
14799
14767
  if (typeof window !== 'undefined') {