@sparkvault/sdk-js 9.0.1 → 9.1.1

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.cjs CHANGED
@@ -8573,6 +8573,11 @@ function attachClickHandler(selector, onClick) {
8573
8573
  * sv.products.identity.attach('.login-btn');
8574
8574
  */
8575
8575
  const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
8576
+ // The exact algorithms the Identity server signs identity tokens with: EdDSA by
8577
+ // default, RS256 when a client opts in via `id_token_signed_response_alg`. The
8578
+ // unverified client-side decode gates on this set so an unsigned (`none`) or
8579
+ // algorithm-confused token cannot masquerade as valid.
8580
+ const ACCEPTED_TOKEN_ALGS = ['EdDSA', 'RS256'];
8576
8581
  // A sign-in is "pending" from popup open until its result arrives; a marker
8577
8582
  // that outlives a lost result (a mobile opener-tab discard clears the message
8578
8583
  // listener but not sessionStorage) is what lets the next load self-heal.
@@ -8973,14 +8978,16 @@ class IdentityModule {
8973
8978
  * Decode an identity token's claims WITHOUT verifying its signature.
8974
8979
  *
8975
8980
  * This is an UNVERIFIED, client-side decode: it parses the JWT payload and
8976
- * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
8977
- * `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
8978
- * cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
8979
- * result MUST NOT be trusted for any authorization decision.
8981
+ * sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (accepting
8982
+ * only the algorithms the Identity server signs with, so an unsigned or
8983
+ * algorithm-confused token cannot masquerade as valid). It does NOT verify the
8984
+ * signature, so its result MUST NOT be trusted for any authorization decision.
8980
8985
  *
8981
8986
  * To trust a token (e.g. before keying records by `claims.svid`), verify the
8982
- * Ed25519 signature server-side against the Identity JWKS endpoint
8983
- * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
8987
+ * signature server-side against the Identity JWKS endpoint
8988
+ * (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`), which
8989
+ * publishes the EdDSA and RS256 keys and selects the verifying key by `kid`.
8990
+ * See docs/SDK.md.
8984
8991
  */
8985
8992
  decodeToken(token) {
8986
8993
  if (!token || typeof token !== 'string') {
@@ -8995,10 +9002,12 @@ class IdentityModule {
8995
9002
  if (typeof header !== 'object' || header === null) {
8996
9003
  throw new ValidationError('Invalid token header');
8997
9004
  }
8998
- // Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
8999
- // tokens are Ed25519-signed; anything else is an unsigned or algorithm-
9000
- // confused token that could never pass server-side JWKS verification.
9001
- if (header.alg !== 'EdDSA') {
9005
+ // Accept exactly the algorithms the Identity server signs with; reject
9006
+ // everything else — `none` (unsigned), a symmetric or algorithm-confused
9007
+ // token, or an absent alg — none of which could pass the server-side JWKS
9008
+ // verification the host performs before trusting the token.
9009
+ const alg = header.alg;
9010
+ if (typeof alg !== 'string' || !ACCEPTED_TOKEN_ALGS.includes(alg)) {
9002
9011
  throw new ValidationError('Unsupported token algorithm');
9003
9012
  }
9004
9013
  const payload = JSON.parse(base64urlToString(payloadB64));
@@ -14756,7 +14765,7 @@ class SparkVault {
14756
14765
  }
14757
14766
  /** Get the SDK version */
14758
14767
  static get version() {
14759
- return '9.0.1';
14768
+ return '9.1.1';
14760
14769
  }
14761
14770
  }
14762
14771
  if (typeof window !== 'undefined') {