@ambasada/sdk 0.7.1 → 0.7.2

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.
Files changed (2) hide show
  1. package/dist/index.js +4 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -679,7 +679,7 @@ var AmbasadaAuth = class {
679
679
  async verifyShellToken(token, options = {}) {
680
680
  const c = this.config();
681
681
  if (!c.issuer) throw new VillageError("CONFIG", "silent sign-in needs AMBASADA_AUTH_ISSUER (injected on ambasada.dev and by `ambasada dev`)");
682
- const issuer = c.issuer.replace(/\/+$/, "");
682
+ const trusted = [c.issuer, c.hubUrl].filter((v) => !!v).map((v) => v.replace(/\/+$/, ""));
683
683
  const audiences = [options.audience ?? c.audiences ?? []].flat().filter(Boolean).map((a) => a.replace(/\/+$/, ""));
684
684
  if (!audiences.length) throw new VillageError("CONFIG", "silent sign-in needs to know this app: set AMBASADA_APP_ORIGIN or PUBLIC_URL, or pass { audience }");
685
685
  const doFetch = c.fetch ?? ((input, init) => fetch(input, init));
@@ -694,6 +694,9 @@ var AmbasadaAuth = class {
694
694
  throw shellRefused("not a JWT");
695
695
  }
696
696
  if (header3.alg !== "RS256") throw shellRefused(`alg ${String(header3.alg)} (only RS256)`);
697
+ const iss = typeof claims.iss === "string" ? claims.iss.replace(/\/+$/, "") : null;
698
+ if (iss && !trusted.includes(iss)) throw shellRefused(`issuer ${claims.iss}`);
699
+ const issuer = iss ?? trusted[0];
697
700
  let keys3 = await jwks(issuer, doFetch);
698
701
  let jwk = keys3.find((k) => k.kid === header3.kid) ?? (!header3.kid && keys3.length === 1 ? keys3[0] : void 0);
699
702
  if (!jwk) {
@@ -708,7 +711,6 @@ var AmbasadaAuth = class {
708
711
  if (typeof claims.exp !== "number" || claims.exp + LEEWAY_S < now) throw shellRefused("expired");
709
712
  if (typeof claims.nbf === "number" && claims.nbf - LEEWAY_S > now) throw shellRefused("not valid yet");
710
713
  if (typeof claims.iat === "number" && claims.iat - LEEWAY_S > now) throw shellRefused("issued in the future");
711
- if (typeof claims.iss === "string" && claims.iss.replace(/\/+$/, "") !== issuer) throw shellRefused(`issuer ${claims.iss}`);
712
714
  const aud = [claims.aud].flat().filter((a) => typeof a === "string").map((a) => a.replace(/\/+$/, ""));
713
715
  if (!aud.some((a) => audiences.includes(a))) throw shellRefused(`it is for ${aud.join(", ") || "no app"}, not this one`);
714
716
  if (typeof claims.sub !== "string" || !claims.sub) throw shellRefused("no subject");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ambasada/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "TypeScript SDK for the Hack A Ton village: Checkout, webhooks, receipts, Pay, needs, LLM, images, tools, files, listings, wallet.",
5
5
  "type": "module",
6
6
  "license": "MIT",