@north-light/identity 0.3.749 → 0.3.751

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
@@ -59,10 +59,12 @@ export declare class JwksCache {
59
59
  forKid(kid: string | undefined): Promise<JSONWebKeySet>;
60
60
  }
61
61
  /** One link of a call token's actor chain. `grant` and `rev` appear only on an `app:` link. */
62
+ /** `owner` marks an app link with no grant whose app owns the namespace of the token's `sub`. */
62
63
  export interface CallLink {
63
64
  sub: string;
64
65
  grant?: string;
65
66
  rev?: number;
67
+ owner?: true;
66
68
  }
67
69
  /** The verified payload of a call token. Fields beyond `sub`/`aud`/`client_id` are present on some uses only. */
68
70
  export interface CallTokenClaims extends JWTPayload {
@@ -85,7 +87,7 @@ export interface CallTokenClaims extends JWTPayload {
85
87
  }
86
88
  /** A verified call token. The verifier authorizes nothing: the caller decides authority from `chain`. */
87
89
  export interface CallToken {
88
- /** `user:<id>`. */
90
+ /** Any principal `parsePrincipal` accepts. */
89
91
  sub: string;
90
92
  aud: string;
91
93
  /** The actor chain, index 0 = the presenter. */
@@ -97,7 +99,7 @@ export interface CallToken {
97
99
  /**
98
100
  * Verifies a call token of any use (peer, app access, outbound provider, run notice) and returns its actor chain,
99
101
  * presenter first. Checks in order: header `typ` `at+jwt`, `alg` ES256 or RS256, non-empty `kid`; signature; `iss`;
100
- * `aud` a string equal to `audience`; `exp` and `iat` numbers; `sub` = `user:<id>`; `client_id` non-empty; `scope`
102
+ * `aud` a string equal to `audience`; `exp` and `iat` numbers; `sub` a principal `parsePrincipal` accepts; `client_id` non-empty; `scope`
101
103
  * a string when present; then the chain. A token with no `act` is refused: the legacy machine and app shapes are not
102
104
  * accepted. Any `machine_id` must equal the first link, any top-level `grant` an app link's, and, on a token without
103
105
  * `scope`, any `grantee` and `rev` the app link's (or, with no app link, `grantee` = `sub` and no `rev`). It authorizes
package/dist/index.js CHANGED
@@ -245,9 +245,7 @@ function isDeveloperCredentialEnvelope(p) {
245
245
  function chainOf(payload) {
246
246
  const p = payload;
247
247
  const bad = () => { throw new Error('Invalid call token claims'); };
248
- const appLink = (sub, grant, rev) => {
249
- if (grant === undefined)
250
- return { sub };
248
+ const grantLink = (sub, grant, rev) => {
251
249
  if (typeof grant !== 'string' || grant === '')
252
250
  return bad();
253
251
  if (rev === undefined)
@@ -256,6 +254,7 @@ function chainOf(payload) {
256
254
  return bad();
257
255
  return { sub, grant, rev };
258
256
  };
257
+ const tokenSub = typeof p.sub === 'string' ? parsePrincipal(p.sub) : null;
259
258
  if (p.act === undefined)
260
259
  return bad();
261
260
  const chain = [];
@@ -273,19 +272,39 @@ function chainOf(payload) {
273
272
  chain.push({ sub: link.sub });
274
273
  break;
275
274
  }
276
- if (!(validatePrincipal(link.sub, 'runtime') || validatePrincipal(link.sub, 'app') || validatePrincipal(link.sub, 'user')))
275
+ if (typeof link.sub !== 'string')
277
276
  return bad();
278
- if (link.sub.startsWith('app:'))
279
- chain.push(appLink(link.sub, link.grant, link.rev));
280
- else if (link.grant !== undefined || link.rev !== undefined)
281
- return bad();
282
- else
277
+ if (link.sub.startsWith('runtime:')) {
278
+ if (!validatePrincipal(link.sub, 'runtime') || link.grant !== undefined || link.rev !== undefined)
279
+ return bad();
283
280
  chain.push({ sub: link.sub });
281
+ }
282
+ else {
283
+ const parsed = parsePrincipal(link.sub);
284
+ // A link names a namespace root, never a path principal.
285
+ if (parsed === null || parsed.path.length > 0)
286
+ return bad();
287
+ if (parsed.kind === 'app' && link.grant === undefined) {
288
+ if (link.rev !== undefined)
289
+ return bad();
290
+ // Marked `owner` when the app owns the namespace of the token's `sub`; otherwise the existing outbound shape (an app link without a grant).
291
+ chain.push(tokenSub !== null && tokenSub.namespace === link.sub ? { sub: link.sub, owner: true } : { sub: link.sub });
292
+ }
293
+ else if (parsed.kind === 'app')
294
+ chain.push(grantLink(link.sub, link.grant, link.rev));
295
+ else if (link.grant === undefined && link.rev === undefined)
296
+ chain.push({ sub: link.sub });
297
+ // A person's grant-bearing link is accepted only on an exchanged token: the person acts for a different subject.
298
+ else if (p.sub !== link.sub)
299
+ chain.push(grantLink(link.sub, link.grant, link.rev));
300
+ else
301
+ return bad();
302
+ }
284
303
  node = link.act;
285
304
  }
286
305
  if (p.machine_id !== undefined && p.machine_id !== chain[0].sub)
287
306
  return bad();
288
- if (p.grant !== undefined && !chain.some((l) => l.sub.startsWith('app:') && l.grant === p.grant))
307
+ if (p.grant !== undefined && !chain.some((l) => l.grant === p.grant))
289
308
  return bad();
290
309
  // A token's top-level claims (kept for providers pinned to an older `@north-light/plugin`, which read them instead of
291
310
  // `act`) must say what its chain says, or the old and new verifiers authorize different identities from one signed token.
@@ -311,7 +330,7 @@ function chainOf(payload) {
311
330
  /**
312
331
  * Verifies a call token of any use (peer, app access, outbound provider, run notice) and returns its actor chain,
313
332
  * presenter first. Checks in order: header `typ` `at+jwt`, `alg` ES256 or RS256, non-empty `kid`; signature; `iss`;
314
- * `aud` a string equal to `audience`; `exp` and `iat` numbers; `sub` = `user:<id>`; `client_id` non-empty; `scope`
333
+ * `aud` a string equal to `audience`; `exp` and `iat` numbers; `sub` a principal `parsePrincipal` accepts; `client_id` non-empty; `scope`
315
334
  * a string when present; then the chain. A token with no `act` is refused: the legacy machine and app shapes are not
316
335
  * accepted. Any `machine_id` must equal the first link, any top-level `grant` an app link's, and, on a token without
317
336
  * `scope`, any `grantee` and `rev` the app link's (or, with no app link, `grantee` = `sub` and no `rev`). It authorizes
@@ -329,7 +348,7 @@ export async function verifyCallToken(options) {
329
348
  issuer: options.issuer, audience: options.audience, algorithms: ['ES256', 'RS256'], typ: 'at+jwt', requiredClaims: ['exp'],
330
349
  });
331
350
  if (payload.aud !== options.audience || typeof payload.exp !== 'number' || typeof payload.iat !== 'number' ||
332
- !validatePrincipal(payload.sub, 'user') || !nonEmptyString(payload.client_id) ||
351
+ typeof payload.sub !== 'string' || parsePrincipal(payload.sub) === null || !nonEmptyString(payload.client_id) ||
333
352
  (payload.scope !== undefined && typeof payload.scope !== 'string')) {
334
353
  throw new Error('Invalid call token claims');
335
354
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.749",
3
+ "version": "0.3.751",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",