@sparkvault/sdk-js 6.0.0 → 7.0.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 +15 -7
- package/dist/products/identity/index.d.ts +15 -7
- package/dist/sparkvault.cjs.js +34 -9
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +34 -9
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.esm.js
CHANGED
|
@@ -7930,13 +7930,19 @@ class IdentityModule {
|
|
|
7930
7930
|
return cleanup;
|
|
7931
7931
|
}
|
|
7932
7932
|
/**
|
|
7933
|
-
*
|
|
7934
|
-
* Validates the token structure, expiry, and issuer.
|
|
7933
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
7935
7934
|
*
|
|
7936
|
-
*
|
|
7937
|
-
*
|
|
7935
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
7936
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
7937
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
7938
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
7939
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
7940
|
+
*
|
|
7941
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
7942
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
7943
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
7938
7944
|
*/
|
|
7939
|
-
|
|
7945
|
+
decodeToken(token) {
|
|
7940
7946
|
if (!token || typeof token !== 'string') {
|
|
7941
7947
|
throw new ValidationError('Token is required');
|
|
7942
7948
|
}
|
|
@@ -7944,7 +7950,17 @@ class IdentityModule {
|
|
|
7944
7950
|
if (parts.length !== 3) {
|
|
7945
7951
|
throw new ValidationError('Invalid token format');
|
|
7946
7952
|
}
|
|
7947
|
-
const [, payloadB64] = parts;
|
|
7953
|
+
const [headerB64, payloadB64] = parts;
|
|
7954
|
+
const header = JSON.parse(base64urlToString(headerB64));
|
|
7955
|
+
if (typeof header !== 'object' || header === null) {
|
|
7956
|
+
throw new ValidationError('Invalid token header');
|
|
7957
|
+
}
|
|
7958
|
+
// Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
|
|
7959
|
+
// tokens are Ed25519-signed; anything else is an unsigned or algorithm-
|
|
7960
|
+
// confused token that could never pass server-side JWKS verification.
|
|
7961
|
+
if (header.alg !== 'EdDSA') {
|
|
7962
|
+
throw new ValidationError('Unsupported token algorithm');
|
|
7963
|
+
}
|
|
7948
7964
|
const payload = JSON.parse(base64urlToString(payloadB64));
|
|
7949
7965
|
if (!isTokenClaims(payload)) {
|
|
7950
7966
|
throw new ValidationError('Invalid token payload structure');
|
|
@@ -7957,13 +7973,18 @@ class IdentityModule {
|
|
|
7957
7973
|
if (payload.iss !== expectedIssuer) {
|
|
7958
7974
|
throw new ValidationError('Invalid token issuer');
|
|
7959
7975
|
}
|
|
7976
|
+
if (payload.aud !== this.config.accountId) {
|
|
7977
|
+
throw new ValidationError('Invalid token audience');
|
|
7978
|
+
}
|
|
7960
7979
|
return payload;
|
|
7961
7980
|
}
|
|
7962
7981
|
/**
|
|
7963
7982
|
* Complete full-page redirect results produced by social-login flows.
|
|
7964
7983
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
7965
|
-
* not hit server logs. Consume it once,
|
|
7966
|
-
*
|
|
7984
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
7985
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
7986
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
7987
|
+
* via the Identity JWKS before trusting any claim.
|
|
7967
7988
|
*/
|
|
7968
7989
|
async consumeRedirectResult() {
|
|
7969
7990
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
@@ -7990,7 +8011,11 @@ class IdentityModule {
|
|
|
7990
8011
|
if (expectedState && params.get('state') !== expectedState) {
|
|
7991
8012
|
throw new ValidationError('Invalid OAuth state');
|
|
7992
8013
|
}
|
|
7993
|
-
|
|
8014
|
+
// Unverified client-side decode — surfaces the claims for the result
|
|
8015
|
+
// shape and rejects an obviously-bad token (expiry/issuer/audience/alg).
|
|
8016
|
+
// The host MUST still verify result.token server-side via the Identity
|
|
8017
|
+
// JWKS before trusting any claim for an authorization decision.
|
|
8018
|
+
const claims = this.decodeToken(token);
|
|
7994
8019
|
return {
|
|
7995
8020
|
token,
|
|
7996
8021
|
identity: claims.identity,
|