@venizia/ignis 0.4.8 → 0.5.0-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.
Files changed (114) hide show
  1. package/dist/esm/base/applications/base.js +5 -2
  2. package/dist/esm/base/applications/base.js.map +1 -1
  3. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
  4. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
  5. package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
  6. package/dist/esm/components/api-reference/common/keys.js +4 -1
  7. package/dist/esm/components/api-reference/common/keys.js.map +1 -1
  8. package/dist/esm/components/api-reference/common/types.d.ts +1 -1
  9. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  10. package/dist/esm/components/api-reference/component.js.map +1 -1
  11. package/dist/esm/components/auth/authenticate/component.js +10 -16
  12. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  13. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
  14. package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
  15. package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
  16. package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
  17. package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
  18. package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
  19. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +1 -1
  20. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  21. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
  22. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
  23. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
  24. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
  25. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
  26. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
  27. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
  28. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
  29. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
  30. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
  31. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
  32. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
  33. package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
  34. package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
  35. package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
  36. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
  37. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
  38. package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
  39. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
  40. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
  41. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
  42. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
  43. package/dist/esm/components/auth/authorize/component.js.map +1 -1
  44. package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
  45. package/dist/esm/components/controller/grpc/common/types.js +4 -1
  46. package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
  47. package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
  48. package/dist/esm/components/health-check/common/keys.d.ts +4 -2
  49. package/dist/esm/components/health-check/common/keys.js +7 -2
  50. package/dist/esm/components/health-check/common/keys.js.map +1 -1
  51. package/dist/esm/components/health-check/common/types.d.ts +1 -1
  52. package/dist/esm/components/health-check/common/types.js.map +1 -1
  53. package/dist/esm/components/health-check/component.js +1 -3
  54. package/dist/esm/components/health-check/component.js.map +1 -1
  55. package/dist/esm/components/mail/common/constants.d.ts +8 -0
  56. package/dist/esm/components/mail/common/constants.js +6 -0
  57. package/dist/esm/components/mail/common/constants.js.map +1 -1
  58. package/dist/esm/components/mail/common/errors.d.ts +9 -0
  59. package/dist/esm/components/mail/common/errors.js +6 -0
  60. package/dist/esm/components/mail/common/errors.js.map +1 -1
  61. package/dist/esm/components/mail/common/keys.d.ts +14 -11
  62. package/dist/esm/components/mail/common/keys.js +34 -11
  63. package/dist/esm/components/mail/common/keys.js.map +1 -1
  64. package/dist/esm/components/mail/common/types/message.d.ts +3 -0
  65. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  66. package/dist/esm/components/mail/common/types/queue.d.ts +2 -0
  67. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  68. package/dist/esm/components/mail/common/types/template.d.ts +4 -1
  69. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  70. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +2 -0
  71. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +17 -10
  72. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  73. package/dist/esm/components/mail/services/mail.service.js +3 -2
  74. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  75. package/dist/esm/components/mail/services/template.service.d.ts +3 -3
  76. package/dist/esm/components/mail/services/template.service.js +29 -36
  77. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  78. package/dist/esm/components/mail/utilities/index.d.ts +1 -0
  79. package/dist/esm/components/mail/utilities/index.js +1 -0
  80. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  81. package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
  82. package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
  83. package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
  84. package/dist/esm/components/request-tracker/component.d.ts +2 -1
  85. package/dist/esm/components/request-tracker/component.js +5 -5
  86. package/dist/esm/components/request-tracker/component.js.map +1 -1
  87. package/dist/esm/components/server-info/common/keys.d.ts +2 -1
  88. package/dist/esm/components/server-info/common/keys.js +4 -1
  89. package/dist/esm/components/server-info/common/keys.js.map +1 -1
  90. package/dist/esm/components/server-info/common/types.d.ts +1 -1
  91. package/dist/esm/components/server-info/common/types.js.map +1 -1
  92. package/dist/esm/components/server-info/component.js +1 -3
  93. package/dist/esm/components/server-info/component.js.map +1 -1
  94. package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
  95. package/dist/esm/components/socket-io/common/keys.js +19 -6
  96. package/dist/esm/components/socket-io/common/keys.js.map +1 -1
  97. package/dist/esm/components/socket-io/component.js +1 -1
  98. package/dist/esm/components/socket-io/component.js.map +1 -1
  99. package/dist/esm/components/static-asset/common/keys.d.ts +8 -4
  100. package/dist/esm/components/static-asset/common/keys.js +10 -3
  101. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  102. package/dist/esm/components/static-asset/component.js +1 -0
  103. package/dist/esm/components/static-asset/component.js.map +1 -1
  104. package/dist/esm/components/static-asset/utilities/ingest.utility.d.ts +3 -3
  105. package/dist/esm/components/static-asset/utilities/ingest.utility.js +14 -18
  106. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -1
  107. package/dist/esm/components/websocket/common/keys.d.ts +12 -10
  108. package/dist/esm/components/websocket/common/keys.js +31 -10
  109. package/dist/esm/components/websocket/common/keys.js.map +1 -1
  110. package/dist/esm/components/websocket/component.js.map +1 -1
  111. package/dist/presets/app/preset.json +4 -4
  112. package/dist/presets/lib/preset.json +3 -3
  113. package/dist/presets/shared/preset.json +1 -1
  114. package/package.json +8 -8
@@ -1,120 +1,27 @@
1
1
  import { HTTP } from '@venizia/ignis-helpers/common';
2
- import { getError } from '@venizia/ignis-helpers/core';
3
- /** One host name: labels of letters, digits and hyphens joined by single dots - no empty label, no wildcard. */
4
- const HOST_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*$/;
5
- /** An IPv4 address, in any spelling a caller might write; the URL parser decides whether it is the address it looks like. */
6
- const IPV4_PATTERN = /^\d{1,3}(?:\.\d{1,3}){3}$/;
7
- /**
8
- * An entry of `jwks.hosts.http`: a host (a name, an IPv4 address, or an IPv6 address in brackets) and an optional
9
- * `:port`. Nothing else: no scheme, path, userinfo or wildcard.
10
- */
11
- const ENTRY_PATTERN = /^(?<host>\[[0-9a-f:.]+\]|[a-z0-9][a-z0-9.-]*)(?::(?<port>[0-9]{1,5}))?$/;
12
- /** The port of an `http:` URL that names none. */
13
- const DEFAULT_HTTP_PORT = '80';
14
- /** The longest label and the longest name DNS has (RFC 1035): a longer entry is not a host name. */
15
- const MAX_LABEL_LENGTH = 63;
16
- const MAX_NAME_LENGTH = 253;
17
- /** The addresses that mean "any local address", not a host: as the URL parser writes them. */
18
- const UNSPECIFIED_HOSTS = new Set(['0.0.0.0', '[::]']);
19
- /** `127.0.0.0/8`, as the URL parser writes an IPv4 host. */
20
- const LOOPBACK_IPV4_PATTERN = /^127(?:\.\d{1,3}){3}$/;
21
- const LOOPBACK_HOSTS = new Set(['localhost', '[::1]']);
2
+ import { getError, UrlPolicy } from '@venizia/ignis-helpers/core';
22
3
  /**
23
4
  * Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and
24
5
  * whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or
25
- * is listed in `jwks.hosts.http`. The one policy serves the JWKS verifier and the service-assertion
6
+ * its origin is listed in `jwks.trusted`. The one policy serves the JWKS verifier and the service-assertion
26
7
  * callers: both fetch a key set to decide who may call.
27
8
  *
28
- * The opt-in is an EXACT entry, never a pattern or a range: a host name, an IPv4 address, or an IPv6 address in
29
- * brackets, each optionally with a port (`identity-service`, `10.0.0.5:8080`, `[fd00::1]:8443`). An entry without a
30
- * port covers every port of that host; an entry with one covers that port only. An entry and a URL are both read by
31
- * the URL parser, so the two sides are compared in the form the parser gives them: `http://2130706433` is
32
- * `127.0.0.1`, and `http://[::ffff:10.0.0.5]` is `[::ffff:a00:5]`, which is not `10.0.0.5`.
9
+ * The opt-in is an EXACT origin, never a pattern or a range, in the form the URL parser writes it
10
+ * (`http://identity-service`, `http://10.0.0.5:8080`, `http://[fd00::1]:8443`). The shape check is the url guard's own
11
+ * (`UrlPolicy.resolveTrustedOrigins`), so a JWKS entry and a `policy.hosts.trusted` entry follow one rule.
33
12
  */
34
13
  export class JWKSUrlPolicy {
35
- /**
36
- * Refuses an entry of `jwks.hosts.http` that is not exactly a host with an optional port, and answers the entries
37
- * in the form a URL is matched in: the host as the URL parser writes it (lower case), then `:port` when there is one.
38
- * An entry is valid only when `new URL('http://' + entry)` gives the same host back, and the same port.
39
- */
40
- static resolveHttpHosts(opts) {
41
- const { scope, hosts } = opts;
42
- if (hosts === undefined) {
43
- return new Set();
44
- }
45
- if (!Array.isArray(hosts)) {
46
- throw getError({
47
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
48
- message: `[${scope}] jwks.hosts.http must be a list of hosts`,
49
- });
50
- }
51
- const resolved = new Set();
52
- for (const entry of hosts) {
53
- const canonical = typeof entry === 'string' ? JWKSUrlPolicy.canonicalEntry({ entry }) : undefined;
54
- if (canonical === undefined) {
55
- throw getError({
56
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
57
- message: `[${scope}] jwks.hosts.http holds ${JSON.stringify(entry)} | list exact hosts only: a name, an IPv4 address or an IPv6 address in brackets, with an optional :port, for example 'identity-service', '10.0.0.5:8080' or '[fd00::1]:8443' - no scheme, path, credentials, wildcard or range`,
58
- });
59
- }
60
- resolved.add(canonical);
61
- }
62
- return resolved;
63
- }
64
- /** The canonical form of one entry, or `undefined` when it is not exactly a host with an optional port. */
65
- static canonicalEntry(opts) {
66
- // Not trimmed: an entry with a space, a tab or a newline around it is a typo, and is refused rather than corrected.
67
- const matched = ENTRY_PATTERN.exec(opts.entry.toLowerCase());
68
- const { host, port } = matched?.groups ?? {};
69
- if (host === undefined) {
70
- return undefined;
71
- }
72
- // A name has labels of its own shape; an IPv4 or an IPv6 address is judged by the parser alone, below.
73
- const isAddress = host.startsWith('[') || IPV4_PATTERN.test(host);
74
- if (!isAddress &&
75
- !(HOST_NAME_PATTERN.test(host) && JWKSUrlPolicy.isWithinLimits({ name: host }))) {
76
- return undefined;
77
- }
78
- const parsed = JWKSUrlPolicy.parseHttp({
79
- authority: port === undefined ? host : `${host}:${port}`,
80
- });
81
- // The host must be what the parser makes of it: `2130706433`, `0x7f000001`, `1.2.3`, `010.0.0.5` and
82
- // `[::ffff:10.0.0.5]` are spellings the parser rewrites, so none of them is the host it looks like.
83
- if (parsed === undefined || parsed.hostname !== host || UNSPECIFIED_HOSTS.has(host)) {
84
- return undefined;
85
- }
86
- if (port === undefined) {
87
- return host;
88
- }
89
- // The parser drops the default port, so `:80` reads back as no port; a port is valid only as the parser keeps it.
90
- const kept = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;
91
- if (kept !== port || Number(port) < 1) {
92
- return undefined;
93
- }
94
- return `${host}:${port}`;
95
- }
96
- /** Whether a name is within the DNS limits: 253 characters, and 63 for each label. */
97
- static isWithinLimits(opts) {
98
- return (opts.name.length <= MAX_NAME_LENGTH &&
99
- opts.name.split('.').every((label) => label.length <= MAX_LABEL_LENGTH));
100
- }
101
- /** `http://<authority>` through the URL parser, or `undefined` when it refuses it. */
102
- static parseHttp(opts) {
103
- try {
104
- return new URL(`http://${opts.authority}`);
105
- // eslint-disable-next-line venizia/no-silent-catch -- an authority the parser refuses is not a host: the caller refuses the entry
106
- }
107
- catch {
108
- return undefined;
109
- }
14
+ /** Refuses a `jwks.trusted` list that is not exactly a list of origins, and answers the origins as a set. */
15
+ static resolveTrustedOrigins(opts) {
16
+ return UrlPolicy.resolveTrustedOrigins({ ...opts, label: 'jwks.trusted' });
110
17
  }
111
18
  /** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */
112
19
  static isLoopback(hostname) {
113
- return LOOPBACK_HOSTS.has(hostname) || LOOPBACK_IPV4_PATTERN.test(hostname);
20
+ return UrlPolicy.isLoopbackHost({ hostname });
114
21
  }
115
22
  /**
116
- * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or a host listed in
117
- * `jwks.hosts.http`. Only the host name goes into the message: a URL may carry credentials.
23
+ * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or an origin listed in
24
+ * `jwks.trusted`. Only the host name goes into the message: a URL may carry credentials.
118
25
  */
119
26
  static assertUrl(opts) {
120
27
  const { scope, label, url } = opts;
@@ -129,6 +36,8 @@ export class JWKSUrlPolicy {
129
36
  message: `[${scope}] ${label} is not a valid URL`,
130
37
  });
131
38
  }
39
+ // Before the https early return: a bad `jwks.trusted` refuses the boot whatever the URL is.
40
+ const trusted = JWKSUrlPolicy.resolveTrustedOrigins({ scope, trusted: opts.trusted });
132
41
  if (parsed.protocol === 'https:') {
133
42
  return parsed;
134
43
  }
@@ -138,24 +47,19 @@ export class JWKSUrlPolicy {
138
47
  message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,
139
48
  });
140
49
  }
141
- const allowed = JWKSUrlPolicy.resolveHttpHosts({ scope, hosts: opts.hosts });
142
- // Nothing listens on port 0: a URL that names it is a mistake, and no entry without a port should cover it.
50
+ // Nothing listens on port 0: a URL that names it is a mistake, and no origin should cover it.
143
51
  if (parsed.port === '0') {
144
52
  throw getError({
145
53
  statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
146
54
  message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,
147
55
  });
148
56
  }
149
- // An entry without a port covers every port; one with a port covers that port only (an `http:` URL with none is on 80).
150
- const port = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;
151
- if (JWKSUrlPolicy.isLoopback(parsed.hostname) ||
152
- allowed.has(parsed.hostname) ||
153
- allowed.has(`${parsed.hostname}:${port}`)) {
57
+ if (JWKSUrlPolicy.isLoopback(parsed.hostname) || trusted.has(parsed.origin)) {
154
58
  return parsed;
155
59
  }
156
60
  throw getError({
157
61
  statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
158
- message: `[${scope}] ${label} uses http: and the host '${parsed.hostname}' is not allowed | use https, or list the host in jwks.hosts.http`,
62
+ message: `[${scope}] ${label} uses http: and the origin '${parsed.origin}' is not trusted | use https, or list the origin in jwks.trusted`,
159
63
  });
160
64
  }
161
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jwks-url-policy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/services/jwks-url-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,gHAAgH;AAChH,MAAM,iBAAiB,GAAG,yEAAyE,CAAC;AAEpG,6HAA6H;AAC7H,MAAM,YAAY,GAAG,2BAA2B,CAAC;AAEjD;;;GAGG;AACH,MAAM,aAAa,GAAG,yEAAyE,CAAC;AAEhG,kDAAkD;AAClD,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,oGAAoG;AACpG,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,8FAA8F;AAC9F,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E,4DAA4D;AAC5D,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IACxB;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAwC;QAC9D,MAAM,EAAE,KAAK,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IAAI,KAAK,KAAK,KAAK,6BAA6B,MAAM,CAAC,QAAQ,EAAE;aAC3E,CAAC,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAE7E,4GAA4G;QAC5G,IAAI,MAAM,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;YACxB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,+BAA+B,MAAM,CAAC,QAAQ,GAAG;aAC9E,CAAC,CAAC;QACL,CAAC;QAED,wHAAwH;QACxH,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;QAElE,IACE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC;YACzC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC,EACzC,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,6BAA6B,MAAM,CAAC,QAAQ,mEAAmE;SAC5I,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** One host name: labels of letters, digits and hyphens joined by single dots - no empty label, no wildcard. */\nconst HOST_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*$/;\n\n/** An IPv4 address, in any spelling a caller might write; the URL parser decides whether it is the address it looks like. */\nconst IPV4_PATTERN = /^\\d{1,3}(?:\\.\\d{1,3}){3}$/;\n\n/**\n * An entry of `jwks.hosts.http`: a host (a name, an IPv4 address, or an IPv6 address in brackets) and an optional\n * `:port`. Nothing else: no scheme, path, userinfo or wildcard.\n */\nconst ENTRY_PATTERN = /^(?<host>\\[[0-9a-f:.]+\\]|[a-z0-9][a-z0-9.-]*)(?::(?<port>[0-9]{1,5}))?$/;\n\n/** The port of an `http:` URL that names none. */\nconst DEFAULT_HTTP_PORT = '80';\n\n/** The longest label and the longest name DNS has (RFC 1035): a longer entry is not a host name. */\nconst MAX_LABEL_LENGTH = 63;\nconst MAX_NAME_LENGTH = 253;\n\n/** The addresses that mean \"any local address\", not a host: as the URL parser writes them. */\nconst UNSPECIFIED_HOSTS: ReadonlySet<string> = new Set(['0.0.0.0', '[::]']);\n\n/** `127.0.0.0/8`, as the URL parser writes an IPv4 host. */\nconst LOOPBACK_IPV4_PATTERN = /^127(?:\\.\\d{1,3}){3}$/;\n\nconst LOOPBACK_HOSTS: ReadonlySet<string> = new Set(['localhost', '[::1]']);\n\n/**\n * Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and\n * whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or\n * is listed in `jwks.hosts.http`. The one policy serves the JWKS verifier and the service-assertion\n * callers: both fetch a key set to decide who may call.\n *\n * The opt-in is an EXACT entry, never a pattern or a range: a host name, an IPv4 address, or an IPv6 address in\n * brackets, each optionally with a port (`identity-service`, `10.0.0.5:8080`, `[fd00::1]:8443`). An entry without a\n * port covers every port of that host; an entry with one covers that port only. An entry and a URL are both read by\n * the URL parser, so the two sides are compared in the form the parser gives them: `http://2130706433` is\n * `127.0.0.1`, and `http://[::ffff:10.0.0.5]` is `[::ffff:a00:5]`, which is not `10.0.0.5`.\n */\nexport class JWKSUrlPolicy {\n /**\n * Refuses an entry of `jwks.hosts.http` that is not exactly a host with an optional port, and answers the entries\n * in the form a URL is matched in: the host as the URL parser writes it (lower case), then `:port` when there is one.\n * An entry is valid only when `new URL('http://' + entry)` gives the same host back, and the same port.\n */\n static resolveHttpHosts(opts: { scope: string; hosts?: unknown }): ReadonlySet<string> {\n const { scope, hosts } = opts;\n\n if (hosts === undefined) {\n return new Set();\n }\n\n if (!Array.isArray(hosts)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] jwks.hosts.http must be a list of hosts`,\n });\n }\n\n const resolved = new Set<string>();\n\n for (const entry of hosts) {\n const canonical =\n typeof entry === 'string' ? JWKSUrlPolicy.canonicalEntry({ entry }) : undefined;\n\n if (canonical === undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] jwks.hosts.http holds ${JSON.stringify(entry)} | list exact hosts only: a name, an IPv4 address or an IPv6 address in brackets, with an optional :port, for example 'identity-service', '10.0.0.5:8080' or '[fd00::1]:8443' - no scheme, path, credentials, wildcard or range`,\n });\n }\n\n resolved.add(canonical);\n }\n\n return resolved;\n }\n\n /** The canonical form of one entry, or `undefined` when it is not exactly a host with an optional port. */\n private static canonicalEntry(opts: { entry: string }): string | undefined {\n // Not trimmed: an entry with a space, a tab or a newline around it is a typo, and is refused rather than corrected.\n const matched = ENTRY_PATTERN.exec(opts.entry.toLowerCase());\n const { host, port } = matched?.groups ?? {};\n\n if (host === undefined) {\n return undefined;\n }\n\n // A name has labels of its own shape; an IPv4 or an IPv6 address is judged by the parser alone, below.\n const isAddress = host.startsWith('[') || IPV4_PATTERN.test(host);\n\n if (\n !isAddress &&\n !(HOST_NAME_PATTERN.test(host) && JWKSUrlPolicy.isWithinLimits({ name: host }))\n ) {\n return undefined;\n }\n\n const parsed = JWKSUrlPolicy.parseHttp({\n authority: port === undefined ? host : `${host}:${port}`,\n });\n\n // The host must be what the parser makes of it: `2130706433`, `0x7f000001`, `1.2.3`, `010.0.0.5` and\n // `[::ffff:10.0.0.5]` are spellings the parser rewrites, so none of them is the host it looks like.\n if (parsed === undefined || parsed.hostname !== host || UNSPECIFIED_HOSTS.has(host)) {\n return undefined;\n }\n\n if (port === undefined) {\n return host;\n }\n\n // The parser drops the default port, so `:80` reads back as no port; a port is valid only as the parser keeps it.\n const kept = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;\n\n if (kept !== port || Number(port) < 1) {\n return undefined;\n }\n\n return `${host}:${port}`;\n }\n\n /** Whether a name is within the DNS limits: 253 characters, and 63 for each label. */\n private static isWithinLimits(opts: { name: string }): boolean {\n return (\n opts.name.length <= MAX_NAME_LENGTH &&\n opts.name.split('.').every((label) => label.length <= MAX_LABEL_LENGTH)\n );\n }\n\n /** `http://<authority>` through the URL parser, or `undefined` when it refuses it. */\n private static parseHttp(opts: { authority: string }): URL | undefined {\n try {\n return new URL(`http://${opts.authority}`);\n // eslint-disable-next-line venizia/no-silent-catch -- an authority the parser refuses is not a host: the caller refuses the entry\n } catch {\n return undefined;\n }\n }\n\n /** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */\n static isLoopback(hostname: string): boolean {\n return LOOPBACK_HOSTS.has(hostname) || LOOPBACK_IPV4_PATTERN.test(hostname);\n }\n\n /**\n * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or a host listed in\n * `jwks.hosts.http`. Only the host name goes into the message: a URL may carry credentials.\n */\n static assertUrl(opts: { scope: string; label: string; url: string; hosts?: unknown }): URL {\n const { scope, label, url } = opts;\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n // eslint-disable-next-line venizia/no-silent-catch -- the refusal below names the key and withholds the URL, which may carry credentials\n } catch {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} is not a valid URL`,\n });\n }\n\n if (parsed.protocol === 'https:') {\n return parsed;\n }\n\n if (parsed.protocol !== 'http:') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,\n });\n }\n\n const allowed = JWKSUrlPolicy.resolveHttpHosts({ scope, hosts: opts.hosts });\n\n // Nothing listens on port 0: a URL that names it is a mistake, and no entry without a port should cover it.\n if (parsed.port === '0') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,\n });\n }\n\n // An entry without a port covers every port; one with a port covers that port only (an `http:` URL with none is on 80).\n const port = parsed.port === '' ? DEFAULT_HTTP_PORT : parsed.port;\n\n if (\n JWKSUrlPolicy.isLoopback(parsed.hostname) ||\n allowed.has(parsed.hostname) ||\n allowed.has(`${parsed.hostname}:${port}`)\n ) {\n return parsed;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses http: and the host '${parsed.hostname}' is not allowed | use https, or list the host in jwks.hosts.http`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"jwks-url-policy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/services/jwks-url-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IACxB,6GAA6G;IAC7G,MAAM,CAAC,qBAAqB,CAAC,IAA0C;QACrE,OAAO,SAAS,CAAC,qBAAqB,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,gGAAgG;IAChG,MAAM,CAAC,UAAU,CAAC,QAAgB;QAChC,OAAO,SAAS,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH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AAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5E,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,KAAK,KAAK,KAAK,+BAA+B,MAAM,CAAC,MAAM,kEAAkE;SAC3I,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, UrlPolicy } from '@venizia/ignis-helpers/core';\n\n/**\n * Where a JWKS may be fetched from. A key set read over plain `http:` can be replaced on the way, and\n * whoever replaces it signs tokens that verify, so a JWKS URL is `https:` unless its host is loopback or\n * its origin is listed in `jwks.trusted`. The one policy serves the JWKS verifier and the service-assertion\n * callers: both fetch a key set to decide who may call.\n *\n * The opt-in is an EXACT origin, never a pattern or a range, in the form the URL parser writes it\n * (`http://identity-service`, `http://10.0.0.5:8080`, `http://[fd00::1]:8443`). The shape check is the url guard's own\n * (`UrlPolicy.resolveTrustedOrigins`), so a JWKS entry and a `policy.hosts.trusted` entry follow one rule.\n */\nexport class JWKSUrlPolicy {\n /** Refuses a `jwks.trusted` list that is not exactly a list of origins, and answers the origins as a set. */\n static resolveTrustedOrigins(opts: { scope: string; trusted?: unknown }): ReadonlySet<string> {\n return UrlPolicy.resolveTrustedOrigins({ ...opts, label: 'jwks.trusted' });\n }\n\n /** Whether the URL parser's hostname is a loopback one: `localhost`, `127.0.0.0/8` or `::1`. */\n static isLoopback(hostname: string): boolean {\n return UrlPolicy.isLoopbackHost({ hostname });\n }\n\n /**\n * Parses a JWKS URL and refuses it unless it is `https:`, or `http:` to a loopback host or an origin listed in\n * `jwks.trusted`. Only the host name goes into the message: a URL may carry credentials.\n */\n static assertUrl(opts: { scope: string; label: string; url: string; trusted?: unknown }): URL {\n const { scope, label, url } = opts;\n\n let parsed: URL;\n\n try {\n parsed = new URL(url);\n // eslint-disable-next-line venizia/no-silent-catch -- the refusal below names the key and withholds the URL, which may carry credentials\n } catch {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} is not a valid URL`,\n });\n }\n\n // Before the https early return: a bad `jwks.trusted` refuses the boot whatever the URL is.\n const trusted = JWKSUrlPolicy.resolveTrustedOrigins({ scope, trusted: opts.trusted });\n\n if (parsed.protocol === 'https:') {\n return parsed;\n }\n\n if (parsed.protocol !== 'http:') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} must use https | scheme: ${parsed.protocol}`,\n });\n }\n\n // Nothing listens on port 0: a URL that names it is a mistake, and no origin should cover it.\n if (parsed.port === '0') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses port 0 | the host is '${parsed.hostname}'`,\n });\n }\n\n if (JWKSUrlPolicy.isLoopback(parsed.hostname) || trusted.has(parsed.origin)) {\n return parsed;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${label} uses http: and the origin '${parsed.origin}' is not trusted | use https, or list the origin in jwks.trusted`,\n });\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { BaseService } from '@venizia/ignis-kernel';
2
2
  import type { IServiceAuthOptions } from '@venizia/ignis-kernel';
3
+ import { type IFetcherHooks } from '@venizia/ignis-helpers/core';
3
4
  import type { JWK } from 'jose';
4
5
  /**
5
6
  * Mints the outgoing assertion, and publishes the public half for callees to verify against.
@@ -16,6 +17,16 @@ export declare class ServiceAssertionSignerService extends BaseService {
16
17
  isEnabled(): boolean;
17
18
  /** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */
18
19
  getKeyId(): string;
20
+ /**
21
+ * The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the
22
+ * `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.
23
+ * `Authorization` is left alone, so the end user's token still travels on the same request.
24
+ *
25
+ * `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`
26
+ */
27
+ createRequestHook(opts: {
28
+ audience: string;
29
+ }): NonNullable<IFetcherHooks['onRequest']>;
19
30
  /**
20
31
  * One assertion, bound to this exact call.
21
32
  *
@@ -40,6 +40,24 @@ let ServiceAssertionSignerService = ServiceAssertionSignerService_1 = class Serv
40
40
  const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;
41
41
  return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\//, '')}`;
42
42
  }
43
+ /**
44
+ * The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the
45
+ * `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.
46
+ * `Authorization` is left alone, so the end user's token still travels on the same request.
47
+ *
48
+ * `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`
49
+ */
50
+ createRequestHook(opts) {
51
+ const { audience } = opts;
52
+ return async (request) => {
53
+ const assertion = await this.sign({
54
+ method: request.method,
55
+ path: new URL(request.url).pathname,
56
+ audience,
57
+ });
58
+ request.headers.set(ServiceAssertion.HEADER, assertion);
59
+ };
60
+ }
43
61
  /**
44
62
  * One assertion, bound to this exact call.
45
63
  *
@@ -1 +1 @@
1
- {"version":3,"file":"signer.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/signer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EAAE,QAA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AI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,+BAA6B,CAAC,IAAI,eAAe,cAAc,CAAC,GAAG,oCAAoC,MAAM,EAAE;aAC7H,CAAC,CAAC;QACL,CAAC;QAED,IAAI,MAAM,KAAK,cAAc,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,aAAa;QACnB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,CAAC;YACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,IAAI,+BAA6B,CAAC,IAAI,iFAAiF;SACjI,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAvIY,6BAA6B;IASrC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GAThD,6BAA6B,CAuIzC","sourcesContent":["import { inject } from '@/base/metadata';\nimport { AuthenticateBindingKeys, BaseService, ServiceAssertion } from '@venizia/ignis-kernel';\nimport type { IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError, RequestIdGenerator } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JWKSKeyDrivers, JWKSKeyFormats } from '@venizia/ignis-kernel';\nimport { JoseLoader } from '../jose-loader';\n\n/**\n * Mints the outgoing assertion, and publishes the public half for callees to verify against.\n *\n * Only a service that CALLS OUT needs this. `isEnabled()` is false when the application configured\n * no keys, and the component then mounts no certs route.\n */\nexport class ServiceAssertionSignerService extends BaseService {\n private readonly requestIdGenerator = new RequestIdGenerator({\n scope: ServiceAssertionSignerService.name,\n });\n\n private privateKey?: CryptoKey;\n private jwks?: { keys: JWK[] };\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionSignerService.name });\n }\n\n isEnabled(): boolean {\n return Boolean(this.options.keys);\n }\n\n /** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */\n getKeyId(): string {\n const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n\n return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\\//, '')}`;\n }\n\n /**\n * One assertion, bound to this exact call.\n *\n * `path` must be the percent-ENCODED pathname - `new URL(target).pathname`. The verifier compares\n * against the same shape, and a decoded path here would fail every route carrying a space or a\n * non-ASCII slug.\n */\n async sign(opts: { method: string; path: string; audience: string }): Promise<string> {\n const { method, path, audience } = opts;\n\n this.assertEnabled();\n\n const { SignJWT } = await JoseLoader.load();\n const now = Math.floor(Date.now() / 1000);\n const lifetime =\n this.options.signLifetimeSeconds ?? ServiceAssertion.DEFAULT_SIGN_LIFETIME_SECONDS;\n\n const assertion = new SignJWT({ htm: method.toUpperCase(), htu: path })\n .setProtectedHeader({\n alg: ServiceAssertion.ALGORITHM,\n kid: this.getKeyId(),\n typ: ServiceAssertion.TYP,\n })\n .setIssuer(this.options.name)\n .setSubject(this.options.name)\n .setAudience(audience)\n .setJti(this.requestIdGenerator.nextId())\n .setIssuedAt(now)\n .setExpirationTime(now + lifetime);\n\n const privateKey = await this.resolvePrivateKey();\n\n return assertion.sign(privateKey);\n }\n\n /**\n * The document `/svc-certs` serves, built from the PUBLIC key only.\n *\n * `importSPKI` refuses a private PEM outright, which is what makes the private half unreachable\n * from here by construction rather than by care. The JWK format is deliberately NOT accepted for\n * this path: `importJWK` imports whatever it is handed, and a private JWK marked `\"ext\": true`\n * round-trips its `d` straight into this document. See `JWKSIssuerTokenService.assertPublicJWK`.\n */\n async getPublicJWKS(): Promise<{ keys: JWK[] }> {\n if (this.jwks) {\n return this.jwks;\n }\n\n this.assertEnabled();\n\n const { exportJWK, importSPKI } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.public });\n const publicKey = await importSPKI(raw, ServiceAssertion.ALGORITHM);\n const jwk = await exportJWK(publicKey);\n\n if (jwk.d !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] The public key material carries a private exponent | this key would be published at the certs endpoint`,\n });\n }\n\n this.jwks = {\n keys: [{ ...jwk, kid: this.getKeyId(), alg: ServiceAssertion.ALGORITHM, use: 'sig' }],\n };\n\n return this.jwks;\n }\n\n private async resolvePrivateKey(): Promise<CryptoKey> {\n if (this.privateKey) {\n return this.privateKey;\n }\n\n const { importPKCS8 } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.private });\n const result = await importPKCS8(raw, ServiceAssertion.ALGORITHM);\n this.privateKey = result;\n\n return this.privateKey;\n }\n\n private async readKey(opts: { source: string }): Promise<string> {\n const { format, driver } = this.options.keys!;\n\n if (format !== JWKSKeyFormats.PEM) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] Only the '${JWKSKeyFormats.PEM}' key format is supported | got: ${format}`,\n });\n }\n\n if (driver === JWKSKeyDrivers.FILE) {\n return readFile(opts.source, 'utf-8');\n }\n\n return opts.source;\n }\n\n private assertEnabled(): void {\n if (this.options.keys) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] This service has no signing keys | it can verify assertions but not mint them`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"signer.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/signer.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAi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AAC,IAAI,iFAAiF;SACjI,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5JY,6BAA6B;IASrC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GAThD,6BAA6B,CA4JzC","sourcesContent":["import { inject } from '@/base/metadata';\nimport { AuthenticateBindingKeys, BaseService, ServiceAssertion } from '@venizia/ignis-kernel';\nimport type { IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError, RequestIdGenerator, type IFetcherHooks } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { CryptoKey, JWK } from 'jose';\nimport { readFile } from 'node:fs/promises';\nimport { JWKSKeyDrivers, JWKSKeyFormats } from '@venizia/ignis-kernel';\nimport { JoseLoader } from '../jose-loader';\n\n/**\n * Mints the outgoing assertion, and publishes the public half for callees to verify against.\n *\n * Only a service that CALLS OUT needs this. `isEnabled()` is false when the application configured\n * no keys, and the component then mounts no certs route.\n */\nexport class ServiceAssertionSignerService extends BaseService {\n private readonly requestIdGenerator = new RequestIdGenerator({\n scope: ServiceAssertionSignerService.name,\n });\n\n private privateKey?: CryptoKey;\n private jwks?: { keys: JWK[] };\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionSignerService.name });\n }\n\n isEnabled(): boolean {\n return Boolean(this.options.keys);\n }\n\n /** `<name>_<rest path without its slash>`, so a rotated mount changes the kid rather than colliding. */\n getKeyId(): string {\n const restPath = this.options.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n\n return this.options.keys?.kid ?? `${this.options.name}_${restPath.replace(/^\\//, '')}`;\n }\n\n /**\n * The `onRequest` hook of a fetcher that calls `audience`: before EVERY send - each retry attempt included, so the\n * `jti` is fresh - it signs the method and the percent-encoded path of the request and sets the assertion header.\n * `Authorization` is left alone, so the end user's token still travels on the same request.\n *\n * `new NativeFetcher({ name, hooks: { onRequest: signer.createRequestHook({ audience: 'pricing' }) } })`\n */\n createRequestHook(opts: { audience: string }): NonNullable<IFetcherHooks['onRequest']> {\n const { audience } = opts;\n\n return async (request) => {\n const assertion = await this.sign({\n method: request.method,\n path: new URL(request.url).pathname,\n audience,\n });\n\n request.headers.set(ServiceAssertion.HEADER, assertion);\n };\n }\n\n /**\n * One assertion, bound to this exact call.\n *\n * `path` must be the percent-ENCODED pathname - `new URL(target).pathname`. The verifier compares\n * against the same shape, and a decoded path here would fail every route carrying a space or a\n * non-ASCII slug.\n */\n async sign(opts: { method: string; path: string; audience: string }): Promise<string> {\n const { method, path, audience } = opts;\n\n this.assertEnabled();\n\n const { SignJWT } = await JoseLoader.load();\n const now = Math.floor(Date.now() / 1000);\n const lifetime =\n this.options.signLifetimeSeconds ?? ServiceAssertion.DEFAULT_SIGN_LIFETIME_SECONDS;\n\n const assertion = new SignJWT({ htm: method.toUpperCase(), htu: path })\n .setProtectedHeader({\n alg: ServiceAssertion.ALGORITHM,\n kid: this.getKeyId(),\n typ: ServiceAssertion.TYP,\n })\n .setIssuer(this.options.name)\n .setSubject(this.options.name)\n .setAudience(audience)\n .setJti(this.requestIdGenerator.nextId())\n .setIssuedAt(now)\n .setExpirationTime(now + lifetime);\n\n const privateKey = await this.resolvePrivateKey();\n\n return assertion.sign(privateKey);\n }\n\n /**\n * The document `/svc-certs` serves, built from the PUBLIC key only.\n *\n * `importSPKI` refuses a private PEM outright, which is what makes the private half unreachable\n * from here by construction rather than by care. The JWK format is deliberately NOT accepted for\n * this path: `importJWK` imports whatever it is handed, and a private JWK marked `\"ext\": true`\n * round-trips its `d` straight into this document. See `JWKSIssuerTokenService.assertPublicJWK`.\n */\n async getPublicJWKS(): Promise<{ keys: JWK[] }> {\n if (this.jwks) {\n return this.jwks;\n }\n\n this.assertEnabled();\n\n const { exportJWK, importSPKI } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.public });\n const publicKey = await importSPKI(raw, ServiceAssertion.ALGORITHM);\n const jwk = await exportJWK(publicKey);\n\n if (jwk.d !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] The public key material carries a private exponent | this key would be published at the certs endpoint`,\n });\n }\n\n this.jwks = {\n keys: [{ ...jwk, kid: this.getKeyId(), alg: ServiceAssertion.ALGORITHM, use: 'sig' }],\n };\n\n return this.jwks;\n }\n\n private async resolvePrivateKey(): Promise<CryptoKey> {\n if (this.privateKey) {\n return this.privateKey;\n }\n\n const { importPKCS8 } = await JoseLoader.load();\n const raw = await this.readKey({ source: this.options.keys!.private });\n const result = await importPKCS8(raw, ServiceAssertion.ALGORITHM);\n this.privateKey = result;\n\n return this.privateKey;\n }\n\n private async readKey(opts: { source: string }): Promise<string> {\n const { format, driver } = this.options.keys!;\n\n if (format !== JWKSKeyFormats.PEM) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] Only the '${JWKSKeyFormats.PEM}' key format is supported | got: ${format}`,\n });\n }\n\n if (driver === JWKSKeyDrivers.FILE) {\n return readFile(opts.source, 'utf-8');\n }\n\n return opts.source;\n }\n\n private assertEnabled(): void {\n if (this.options.keys) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${ServiceAssertionSignerService.name}] This service has no signing keys | it can verify assertions but not mint them`,\n });\n }\n}\n"]}
@@ -96,7 +96,7 @@ let ServiceAssertionVerifierService = ServiceAssertionVerifierService_1 = class
96
96
  scope: ServiceAssertionVerifierService_1.name,
97
97
  label: 'the caller jwksUrl',
98
98
  url: jwksUrl,
99
- hosts: this.options.jwks?.hosts?.http,
99
+ trusted: this.options.jwks?.trusted,
100
100
  }), {
101
101
  cacheMaxAge: this.options.jwks?.cacheMaxAgeMs ?? ServiceAssertion.DEFAULT_JWKS_CACHE_MAX_AGE_MS,
102
102
  cooldownDuration: this.options.jwks?.cooldownMs ?? ServiceAssertion.DEFAULT_JWKS_COOLDOWN_MS,
@@ -1 +1 @@
1
- {"version":3,"file":"verifier.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/verifier.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD;;;;;;;;GAQG;AACH,IAAa,+BAA+B,uCAA5C,MAAa,+BAAgC,SAAQ,WAAW;IAO9D,YAEE,OAA6C;QAE7C,KAAK,CAAC,EAAE,KAAK,EAAE,iCAA+B,CAAC,IAAI,EAAE,CAAC,CAAC;QAFtC,YAAO,GAAP,OAAO,CAAqB;QAR/C,2FAA2F;QAC1E,YAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QAE5D,oEAAoE;QACnD,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAO3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,IAAqD;QAChE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAErC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,SAAS,CA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O,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,0FAA0F;YAC1F,kEAAkE;YAClE,MAAM,MAAM,GAAI,KAA6B,EAAE,KAAK,IAAI,KAAK,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,iCAAiC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YAE7F,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IAEO,oBAAoB,CAAC,IAI5B;QACC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAEvC,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC;QAEjD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC;aACnC,IAAI,CAAC,oDAAoD,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAE9E,MAAM,QAAQ,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,wBAAwB,EAAE,CAAC,CAAC;IAC3E,CAAC;CACF,CAAA;AAzLY,+BAA+B;IAQvC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GARhD,+BAA+B,CAyL3C","sourcesContent":["import { inject } from '@/base/metadata';\nimport {\n AuthenticateBindingKeys,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { IServiceAssertionClaims, IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { createRemoteJWKSet } from 'jose';\nimport { JoseLoader } from '../jose-loader';\nimport { JWKSUrlPolicy } from '../jwks-url-policy';\n\ntype TRemoteKeySet = ReturnType<typeof createRemoteJWKSet>;\n\n/**\n * Verifies an incoming service assertion against the CALLER's own JWKS.\n *\n * What the assertion covers, and nothing else: the HTTP method and the percent-encoded path. It does\n * NOT cover the query string, any header, or the body. Tenant selectors in particular are usually a\n * header or a query parameter, so an assertion alone does not authenticate which tenant a call acts\n * on - the caller allowlist and the application's own scoping have to do that. Stated because the\n * gap is invisible from the call site.\n */\nexport class ServiceAssertionVerifierService extends BaseService {\n /** One remote key set per caller, kept because `createRemoteJWKSet` owns its own cache. */\n private readonly keySets = new Map<string, TRemoteKeySet>();\n\n /** Per-caller accepted age, resolved once alongside its key set. */\n private readonly acceptMaxAges = new Map<string, number>();\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionVerifierService.name });\n }\n\n /**\n * @param path The percent-ENCODED pathname, from `new URL(context.req.url).pathname`. Never\n * `context.req.path` - Hono decodes that one, and the caller signed the encoded form.\n */\n async verify(opts: { token: string; method: string; path: string }): Promise<{ issuer: string }> {\n const { token, method, path } = opts;\n\n const jose = await JoseLoader.load();\n const issuer = this.readIssuer({ token, jose });\n const keySet = this.resolveKeySet({ issuer, jose });\n const payload = await this.runVerify({ token, issuer, keySet, jose });\n\n this.assertRequestBinding({ payload, method, path });\n\n return { issuer };\n }\n\n /**\n * Reads `iss` WITHOUT verifying, only to choose which key set checks the signature. The same value\n * is then enforced as the expected issuer, so a forged `iss` buys nothing beyond selecting the key\n * set that will reject it.\n */\n private readIssuer(opts: { token: string; jose: typeof import('jose') }): string {\n let issuer: unknown;\n\n try {\n ({ iss: issuer } = opts.jose.decodeJwt(opts.token));\n } catch (error) {\n this.logger.for(this.readIssuer.name).warn('Undecodable assertion | error: %s', error);\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID });\n }\n\n // Typed, not merely present: a numeric `iss` would index the caller map by coercion.\n if (typeof issuer !== 'string' || issuer.length === 0) {\n this.logger\n .for(this.readIssuer.name)\n .warn('Undecodable assertion | iss is missing or not a string');\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID });\n }\n\n return issuer;\n }\n\n private resolveKeySet(opts: { issuer: string; jose: typeof import('jose') }): TRemoteKeySet {\n const { issuer, jose } = opts;\n\n const cached = this.keySets.get(issuer);\n\n if (cached) {\n return cached;\n }\n\n const callers = this.options.callers ?? {};\n\n // `Object.hasOwn`, never a truthiness check on the index: the map arrives as a plain object, so\n // `iss: 'constructor'` would otherwise return `Function` - truthy - walk past this guard, and\n // reach `new URL(<function>)` as an uncaught TypeError.\n if (!Object.hasOwn(callers, issuer)) {\n this.logger\n .for(this.resolveKeySet.name)\n .warn('Caller not on the allowlist | iss: %s', issuer);\n throw getError({ error: AuthenticationErrors.CALLER_NOT_ALLOWED });\n }\n\n const entry = callers[issuer];\n const jwksUrl = typeof entry === 'string' ? entry : entry.jwksUrl;\n\n this.acceptMaxAges.set(\n issuer,\n ServiceAssertion.resolveAcceptMaxAge({\n callerOverride: typeof entry === 'string' ? undefined : entry.acceptMaxAgeSeconds,\n serviceDefault: this.options.acceptMaxAgeSeconds,\n }),\n );\n\n const keySet = jose.createRemoteJWKSet(\n JWKSUrlPolicy.assertUrl({\n scope: ServiceAssertionVerifierService.name,\n label: 'the caller jwksUrl',\n url: jwksUrl,\n hosts: this.options.jwks?.hosts?.http,\n }),\n {\n cacheMaxAge:\n this.options.jwks?.cacheMaxAgeMs ?? ServiceAssertion.DEFAULT_JWKS_CACHE_MAX_AGE_MS,\n cooldownDuration:\n this.options.jwks?.cooldownMs ?? ServiceAssertion.DEFAULT_JWKS_COOLDOWN_MS,\n },\n );\n\n this.keySets.set(issuer, keySet);\n\n return keySet;\n }\n\n private async runVerify(opts: {\n token: string;\n issuer: string;\n keySet: TRemoteKeySet;\n jose: typeof import('jose');\n }): Promise<IServiceAssertionClaims> {\n const { token, issuer, keySet, jose } = opts;\n\n // Resolved when the key set was, so a per-caller override is already folded in.\n const maxTokenAge =\n this.acceptMaxAges.get(issuer) ??\n ServiceAssertion.resolveAcceptMaxAge({\n serviceDefault: this.options.acceptMaxAgeSeconds,\n });\n\n const clockTolerance =\n this.options.clockToleranceSeconds ?? ServiceAssertion.DEFAULT_CLOCK_TOLERANCE_SECONDS;\n\n try {\n const { payload } = await jose.jwtVerify<IServiceAssertionClaims>(token, keySet, {\n algorithms: [ServiceAssertion.ALGORITHM],\n typ: ServiceAssertion.TYP,\n issuer,\n audience: this.options.name,\n // NOT redundant with `exp`, though it looks it. An honest caller stamps `exp = iat +\n // lifetime`, so the two are numerically tied and jose reaches `exp` first - measured.\n // `maxTokenAge` is the only bound that still holds when the CALLER is the attacker and picks\n // its own `exp`, which is precisely the case it exists for. Do not delete it as dead config.\n //\n // And it is the CALLEE's number, never one the caller may request: a caller that could ask\n // for a longer window would be choosing its own replay window, which is the whole thing this\n // is here to deny.\n //\n // TWO NUMBERS, and they answer different questions. Measured at the defaults, 60 + 5:\n // - 65s is the ACCEPTANCE window on this machine's clock. Age 64 passes, 65 does not.\n // - 70s is the REPLAY window in wall-clock time, when the caller's clock runs the full\n // tolerance fast: we accept an `iat` up to 5s in our future, then keep accepting for\n // another 64. Measured: still accepted 69s after minting.\n // The second is the one a threat model asks for. Widening `clockToleranceSeconds` widens it\n // second for second, so it is a security knob, not an operational one.\n maxTokenAge,\n clockTolerance,\n requiredClaims: ['htm', 'htu', 'jti'],\n });\n\n return payload;\n } catch (error) {\n // One code out, the reason on `cause`: a wrong audience, clock skew and a rotated key are\n // otherwise the same string to whoever is reading the log at 2am.\n const reason = (error as { cause?: unknown })?.cause ?? error;\n this.logger.for(this.runVerify.name).warn('Rejected | iss: %s | reason: %s', issuer, reason);\n\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID, cause: error });\n }\n }\n\n private assertRequestBinding(opts: {\n payload: IServiceAssertionClaims;\n method: string;\n path: string;\n }): void {\n const { payload, method, path } = opts;\n\n const signed = `${payload.htm} ${payload.htu}`;\n const actual = `${method.toUpperCase()} ${path}`;\n\n if (signed === actual) {\n return;\n }\n\n this.logger\n .for(this.assertRequestBinding.name)\n .warn('Request binding mismatch | signed: %s | actual: %s', signed, actual);\n\n throw getError({ error: AuthenticationErrors.REQUEST_BINDING_MISMATCH });\n }\n}\n"]}
1
+ {"version":3,"file":"verifier.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/service/verifier.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD;;;;;;;;GAQG;AACH,IAAa,+BAA+B,uCAA5C,MAAa,+BAAgC,SAAQ,WAAW;IAO9D,YAEE,OAA6C;QAE7C,KAAK,CAAC,EAAE,KAAK,EAAE,iCAA+B,CAAC,IAAI,EAAE,CAAC,CAAC;QAFtC,YAAO,GAAP,OAAO,CAAqB;QAR/C,2FAA2F;QAC1E,YAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;QAE5D,oEAAoE;QACnD,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAO3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,IAAqD;QAChE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAErC,MAAM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,CAAC,CAAC;IAC3E,CAAC;CACF,CAAA;AAzLY,+BAA+B;IAQvC,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;;GARhD,+BAA+B,CAyL3C","sourcesContent":["import { inject } from '@/base/metadata';\nimport {\n AuthenticateBindingKeys,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { IServiceAssertionClaims, IServiceAuthOptions } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { createRemoteJWKSet } from 'jose';\nimport { JoseLoader } from '../jose-loader';\nimport { JWKSUrlPolicy } from '../jwks-url-policy';\n\ntype TRemoteKeySet = ReturnType<typeof createRemoteJWKSet>;\n\n/**\n * Verifies an incoming service assertion against the CALLER's own JWKS.\n *\n * What the assertion covers, and nothing else: the HTTP method and the percent-encoded path. It does\n * NOT cover the query string, any header, or the body. Tenant selectors in particular are usually a\n * header or a query parameter, so an assertion alone does not authenticate which tenant a call acts\n * on - the caller allowlist and the application's own scoping have to do that. Stated because the\n * gap is invisible from the call site.\n */\nexport class ServiceAssertionVerifierService extends BaseService {\n /** One remote key set per caller, kept because `createRemoteJWKSet` owns its own cache. */\n private readonly keySets = new Map<string, TRemoteKeySet>();\n\n /** Per-caller accepted age, resolved once alongside its key set. */\n private readonly acceptMaxAges = new Map<string, number>();\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions,\n ) {\n super({ scope: ServiceAssertionVerifierService.name });\n }\n\n /**\n * @param path The percent-ENCODED pathname, from `new URL(context.req.url).pathname`. Never\n * `context.req.path` - Hono decodes that one, and the caller signed the encoded form.\n */\n async verify(opts: { token: string; method: string; path: string }): Promise<{ issuer: string }> {\n const { token, method, path } = opts;\n\n const jose = await JoseLoader.load();\n const issuer = this.readIssuer({ token, jose });\n const keySet = this.resolveKeySet({ issuer, jose });\n const payload = await this.runVerify({ token, issuer, keySet, jose });\n\n this.assertRequestBinding({ payload, method, path });\n\n return { issuer };\n }\n\n /**\n * Reads `iss` WITHOUT verifying, only to choose which key set checks the signature. The same value\n * is then enforced as the expected issuer, so a forged `iss` buys nothing beyond selecting the key\n * set that will reject it.\n */\n private readIssuer(opts: { token: string; jose: typeof import('jose') }): string {\n let issuer: unknown;\n\n try {\n ({ iss: issuer } = opts.jose.decodeJwt(opts.token));\n } catch (error) {\n this.logger.for(this.readIssuer.name).warn('Undecodable assertion | error: %s', error);\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID });\n }\n\n // Typed, not merely present: a numeric `iss` would index the caller map by coercion.\n if (typeof issuer !== 'string' || issuer.length === 0) {\n this.logger\n .for(this.readIssuer.name)\n .warn('Undecodable assertion | iss is missing or not a string');\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID });\n }\n\n return issuer;\n }\n\n private resolveKeySet(opts: { issuer: string; jose: typeof import('jose') }): TRemoteKeySet {\n const { issuer, jose } = opts;\n\n const cached = this.keySets.get(issuer);\n\n if (cached) {\n return cached;\n }\n\n const callers = this.options.callers ?? {};\n\n // `Object.hasOwn`, never a truthiness check on the index: the map arrives as a plain object, so\n // `iss: 'constructor'` would otherwise return `Function` - truthy - walk past this guard, and\n // reach `new URL(<function>)` as an uncaught TypeError.\n if (!Object.hasOwn(callers, issuer)) {\n this.logger\n .for(this.resolveKeySet.name)\n .warn('Caller not on the allowlist | iss: %s', issuer);\n throw getError({ error: AuthenticationErrors.CALLER_NOT_ALLOWED });\n }\n\n const entry = callers[issuer];\n const jwksUrl = typeof entry === 'string' ? entry : entry.jwksUrl;\n\n this.acceptMaxAges.set(\n issuer,\n ServiceAssertion.resolveAcceptMaxAge({\n callerOverride: typeof entry === 'string' ? undefined : entry.acceptMaxAgeSeconds,\n serviceDefault: this.options.acceptMaxAgeSeconds,\n }),\n );\n\n const keySet = jose.createRemoteJWKSet(\n JWKSUrlPolicy.assertUrl({\n scope: ServiceAssertionVerifierService.name,\n label: 'the caller jwksUrl',\n url: jwksUrl,\n trusted: this.options.jwks?.trusted,\n }),\n {\n cacheMaxAge:\n this.options.jwks?.cacheMaxAgeMs ?? ServiceAssertion.DEFAULT_JWKS_CACHE_MAX_AGE_MS,\n cooldownDuration:\n this.options.jwks?.cooldownMs ?? ServiceAssertion.DEFAULT_JWKS_COOLDOWN_MS,\n },\n );\n\n this.keySets.set(issuer, keySet);\n\n return keySet;\n }\n\n private async runVerify(opts: {\n token: string;\n issuer: string;\n keySet: TRemoteKeySet;\n jose: typeof import('jose');\n }): Promise<IServiceAssertionClaims> {\n const { token, issuer, keySet, jose } = opts;\n\n // Resolved when the key set was, so a per-caller override is already folded in.\n const maxTokenAge =\n this.acceptMaxAges.get(issuer) ??\n ServiceAssertion.resolveAcceptMaxAge({\n serviceDefault: this.options.acceptMaxAgeSeconds,\n });\n\n const clockTolerance =\n this.options.clockToleranceSeconds ?? ServiceAssertion.DEFAULT_CLOCK_TOLERANCE_SECONDS;\n\n try {\n const { payload } = await jose.jwtVerify<IServiceAssertionClaims>(token, keySet, {\n algorithms: [ServiceAssertion.ALGORITHM],\n typ: ServiceAssertion.TYP,\n issuer,\n audience: this.options.name,\n // NOT redundant with `exp`, though it looks it. An honest caller stamps `exp = iat +\n // lifetime`, so the two are numerically tied and jose reaches `exp` first - measured.\n // `maxTokenAge` is the only bound that still holds when the CALLER is the attacker and picks\n // its own `exp`, which is precisely the case it exists for. Do not delete it as dead config.\n //\n // And it is the CALLEE's number, never one the caller may request: a caller that could ask\n // for a longer window would be choosing its own replay window, which is the whole thing this\n // is here to deny.\n //\n // TWO NUMBERS, and they answer different questions. Measured at the defaults, 60 + 5:\n // - 65s is the ACCEPTANCE window on this machine's clock. Age 64 passes, 65 does not.\n // - 70s is the REPLAY window in wall-clock time, when the caller's clock runs the full\n // tolerance fast: we accept an `iat` up to 5s in our future, then keep accepting for\n // another 64. Measured: still accepted 69s after minting.\n // The second is the one a threat model asks for. Widening `clockToleranceSeconds` widens it\n // second for second, so it is a security knob, not an operational one.\n maxTokenAge,\n clockTolerance,\n requiredClaims: ['htm', 'htu', 'jti'],\n });\n\n return payload;\n } catch (error) {\n // One code out, the reason on `cause`: a wrong audience, clock skew and a rotated key are\n // otherwise the same string to whoever is reading the log at 2am.\n const reason = (error as { cause?: unknown })?.cause ?? error;\n this.logger.for(this.runVerify.name).warn('Rejected | iss: %s | reason: %s', issuer, reason);\n\n throw getError({ error: AuthenticationErrors.ASSERTION_INVALID, cause: error });\n }\n }\n\n private assertRequestBinding(opts: {\n payload: IServiceAssertionClaims;\n method: string;\n path: string;\n }): void {\n const { payload, method, path } = opts;\n\n const signed = `${payload.htm} ${payload.htu}`;\n const actual = `${method.toUpperCase()} ${path}`;\n\n if (signed === actual) {\n return;\n }\n\n this.logger\n .for(this.assertRequestBinding.name)\n .warn('Request binding mismatch | signed: %s | actual: %s', signed, actual);\n\n throw getError({ error: AuthenticationErrors.REQUEST_BINDING_MISMATCH });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"basic.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/basic.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,GAGf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,iFAAiF;AACjF,IAAa,2BAA2B,mCAAxC,MAAa,2BACX,SAAQ,UAAU;IAKlB,YAOE,OAAqC;QAErC,KAAK,CAAC,EAAE,KAAK,EAAE,6BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC;QAF3C,YAAO,GAAP,OAAO,CAAsB;QATvC,SAAI,GAAG,cAAc,CAAC,cAAc,CAAC;IAYrC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA4B;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAE7D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,CAAC;CACF,CAAA;AAvBY,2BAA2B;IAOnC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,iBAAiB,CAAC,IAAI;SAC5B,CAAC;KACH,CAAC,CAAA;qCACe,iBAAiB;GAbzB,2BAA2B,CAuBvC","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n} from '@venizia/ignis-kernel';\nimport { BasicTokenService } from '../services';\n\n/** HTTP Basic Authentication strategy using Authorization header credentials. */\nexport class BasicAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_BASIC;\n\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: BasicTokenService.name,\n }),\n })\n private service: BasicTokenService<E>,\n ) {\n super({ scope: BasicAuthenticationStrategy.name });\n }\n\n async authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const credentials = this.service.extractCredentials(context);\n\n return this.service.verify({ credentials, context });\n }\n}\n"]}
1
+ {"version":3,"file":"basic.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/basic.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,GAGf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,iFAAiF;AACjF,IAAa,2BAA2B,mCAAxC,MAAa,2BACX,SAAQ,UAAU;IAKlB,YAOE,OAAqC;QAErC,KAAK,CAAC,EAAE,KAAK,EAAE,6BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC;QAF3C,YAAO,GAAP,OAAO,CAAsB;QATvC,SAAI,GAAG,cAAc,CAAC,cAAc,CAAC;IAYrC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA4B;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAE7D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,CAAC;CACF,CAAA;AAvBY,2BAA2B;IAOnC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAoB;YACxC,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,iBAAiB,CAAC,IAAI;SAC5B,CAAC;KACH,CAAC,CAAA;qCACe,iBAAiB;GAbzB,2BAA2B,CAuBvC","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n} from '@venizia/ignis-kernel';\nimport { BasicTokenService } from '../services';\n\n/** HTTP Basic Authentication strategy using Authorization header credentials. */\nexport class BasicAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_BASIC;\n\n constructor(\n @inject({\n key: BindingKeys.build<BasicTokenService>({\n namespace: BindingNamespaces.SERVICE,\n key: BasicTokenService.name,\n }),\n })\n private service: BasicTokenService<E>,\n ) {\n super({ scope: BasicAuthenticationStrategy.name });\n }\n\n async authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const credentials = this.service.extractCredentials(context);\n\n return this.service.verify({ credentials, context });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"issuer.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/strategies/jwks/issuer.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,+IAA+I;AAC/I,IAAa,gCAAgC,wCAA7C,MAAa,gCACX,SAAQ,UAAU;IAMlB,YAOE,OAA0C;QAE1C,KAAK,CAAC,EAAE,KAAK,EAAE,kCAAgC,CAAC,IAAI,EAAE,CAAC,CAAC;QAFhD,YAAO,GAAP,OAAO,CAA2B;QAV5C,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,IAAI,CAAC;IAY9B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,gCAAgC;IAQxC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,sBAAsB,CAAC,IAAI;SACjC,CAAC;KACH,CAAC,CAAA;qCACe,sBAAsB;GAd9B,gCAAgC,CAwB5C","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWKSIssuerTokenService } from '../../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWKSIssuerTokenService`, for an application that issues its own tokens. */\nexport class JWKSIssuerAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWKS;\n\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSIssuerTokenService.name,\n }),\n })\n private service: JWKSIssuerTokenService<E>,\n ) {\n super({ scope: JWKSIssuerAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
1
+ {"version":3,"file":"issuer.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/strategies/jwks/issuer.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,+IAA+I;AAC/I,IAAa,gCAAgC,wCAA7C,MAAa,gCACX,SAAQ,UAAU;IAMlB,YAOE,OAA0C;QAE1C,KAAK,CAAC,EAAE,KAAK,EAAE,kCAAgC,CAAC,IAAI,EAAE,CAAC,CAAC;QAFhD,YAAO,GAAP,OAAO,CAA2B;QAV5C,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,IAAI,CAAC;IAY9B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,gCAAgC;IAQxC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAyB;YAC7C,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,sBAAsB,CAAC,IAAI;SACjC,CAAC;KACH,CAAC,CAAA;qCACe,sBAAsB;GAd9B,gCAAgC,CAwB5C","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWKSIssuerTokenService } from '../../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWKSIssuerTokenService`, for an application that issues its own tokens. */\nexport class JWKSIssuerAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWKS;\n\n constructor(\n @inject({\n key: BindingKeys.build<JWKSIssuerTokenService>({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSIssuerTokenService.name,\n }),\n })\n private service: JWKSIssuerTokenService<E>,\n ) {\n super({ scope: JWKSIssuerAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/strategies/jwks/verifier.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,gJAAgJ;AAChJ,IAAa,kCAAkC,0CAA/C,MAAa,kCACX,SAAQ,UAAU;IAMlB,YAOE,OAA4C;QAE5C,KAAK,CAAC,EAAE,KAAK,EAAE,oCAAkC,CAAC,IAAI,EAAE,CAAC,CAAC;QAFlD,YAAO,GAAP,OAAO,CAA6B;QAV9C,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,IAAI,CAAC;IAY9B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,kCAAkC;IAQ1C,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,wBAAwB,CAAC,IAAI;SACnC,CAAC;KACH,CAAC,CAAA;qCACe,wBAAwB;GAdhC,kCAAkC,CAwB9C","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWKSVerifierTokenService } from '../../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWKSVerifierTokenService`, for an application that trusts a remote JWKS. */\nexport class JWKSVerifierAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWKS;\n\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSVerifierTokenService.name,\n }),\n })\n private service: JWKSVerifierTokenService<E>,\n ) {\n super({ scope: JWKSVerifierAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
1
+ {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/strategies/jwks/verifier.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,gJAAgJ;AAChJ,IAAa,kCAAkC,0CAA/C,MAAa,kCACX,SAAQ,UAAU;IAMlB,YAOE,OAA4C;QAE5C,KAAK,CAAC,EAAE,KAAK,EAAE,oCAAkC,CAAC,IAAI,EAAE,CAAC,CAAC;QAFlD,YAAO,GAAP,OAAO,CAA6B;QAV9C,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,IAAI,CAAC;IAY9B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,kCAAkC;IAQ1C,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAA2B;YAC/C,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,wBAAwB,CAAC,IAAI;SACnC,CAAC;KACH,CAAC,CAAA;qCACe,wBAAwB;GAdhC,kCAAkC,CAwB9C","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWKSVerifierTokenService } from '../../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWKSVerifierTokenService`, for an application that trusts a remote JWKS. */\nexport class JWKSVerifierAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWKS;\n\n constructor(\n @inject({\n key: BindingKeys.build<JWKSVerifierTokenService>({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSVerifierTokenService.name,\n }),\n })\n private service: JWKSVerifierTokenService<E>,\n ) {\n super({ scope: JWKSVerifierAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"jws.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/jws.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,iHAAiH;AACjH,IAAa,yBAAyB,iCAAtC,MAAa,yBACX,SAAQ,UAAU;IAMlB,YAOE,OAAmC;QAEnC,KAAK,CAAC,EAAE,KAAK,EAAE,2BAAyB,CAAC,IAAI,EAAE,CAAC,CAAC;QAFzC,YAAO,GAAP,OAAO,CAAoB;QAVrC,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,GAAG,CAAC;IAY7B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,yBAAyB;IAQjC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,eAAe,CAAC,IAAI;SAC1B,CAAC;KACH,CAAC,CAAA;qCACe,eAAe;GAdvB,yBAAyB,CAwBrC","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWSTokenService } from '../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWSTokenService` (JWS, HS256 by default). */\nexport class JWSAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWS;\n\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: JWSTokenService.name,\n }),\n })\n private service: JWSTokenService<E>,\n ) {\n super({ scope: JWSAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
1
+ {"version":3,"file":"jws.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/jws.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,cAAc,EAGd,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,iHAAiH;AACjH,IAAa,yBAAyB,iCAAtC,MAAa,yBACX,SAAQ,UAAU;IAMlB,YAOE,OAAmC;QAEnC,KAAK,CAAC,EAAE,KAAK,EAAE,2BAAyB,CAAC,IAAI,EAAE,CAAC,CAAC;QAFzC,YAAO,GAAP,OAAO,CAAoB;QAVrC,SAAI,GAAG,cAAc,CAAC,YAAY,CAAC;QACnC,aAAQ,GAAG,aAAa,CAAC,GAAG,CAAC;IAY7B,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxBY,yBAAyB;IAQjC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAkB;YACtC,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,eAAe,CAAC,IAAI;SAC1B,CAAC;KACH,CAAC,CAAA;qCACe,eAAe;GAdvB,yBAAyB,CAwBrC","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { BaseHelper } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n type IAuthUser,\n type IAuthenticationStrategy,\n JOSEStandards,\n} from '@venizia/ignis-kernel';\nimport { JWSTokenService } from '../services';\n\n/** JWT authentication strategy that verifies the bearer token with `JWSTokenService` (JWS, HS256 by default). */\nexport class JWSAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_JWT;\n standard = JOSEStandards.JWS;\n\n constructor(\n @inject({\n key: BindingKeys.build<JWSTokenService>({\n namespace: BindingNamespaces.SERVICE,\n key: JWSTokenService.name,\n }),\n })\n private service: JWSTokenService<E>,\n ) {\n super({ scope: JWSAuthenticationStrategy.name });\n }\n\n authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = this.service.extractCredentials(context);\n\n return this.service.verify(token);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"service.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/service.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,GACP,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF;;;;;;GAMG;AACH,IAAa,6BAA6B,qCAA1C,MAAa,6BACX,SAAQ,UAAU;IAKlB,YAOE,QAA0D,EAE1D,OAAgD;QAEhD,KAAK,CAAC,EA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AAA;AAjDY,6BAA6B;IAOrC,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,+BAA+B,CAAC,IAAI;SAC1C,CAAC;KACH,CAAC,CAAA;IAED,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,eAAe,EAAE,CAAC,CAAA;qCAD9B,+BAA+B;GAbjD,6BAA6B,CAiDzC","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport type { Env } from 'hono';\nimport {\n AuthenticateBindingKeys,\n Authentication,\n AuthenticationErrors,\n BindingNamespaces,\n ServiceAssertion,\n inject,\n} from '@venizia/ignis-kernel';\nimport type {\n IAuthUser,\n IAuthenticationStrategy,\n IServiceAuthOptions,\n TContext,\n} from '@venizia/ignis-kernel';\nimport { ServiceAssertionVerifierService } from '../services/service/verifier.service';\n\n/**\n * Proves the CALLING SERVICE, from a per-request Ed25519 assertion verified against that caller's\n * own JWKS. No identity round trip and no shared password.\n *\n * It proves which service called, never which user. `resolvePrincipal` is where the application\n * turns a caller name into one of its own principals.\n */\nexport class ServiceAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_SERVICE;\n\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: ServiceAssertionVerifierService.name,\n }),\n })\n private readonly verifier: ServiceAssertionVerifierService,\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions<E>,\n ) {\n super({ scope: ServiceAuthenticationStrategy.name });\n }\n\n async authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = context.req.header(ServiceAssertion.HEADER);\n\n if (!token) {\n throw getError({ error: AuthenticationErrors.ASSERTION_MISSING });\n }\n\n // The raw url, NOT `context.req.path`: Hono hands that back percent-DECODED, so a route carrying\n // a space or a non-ASCII slug would never match the encoded path the caller signed.\n const { issuer } = await this.verifier.verify({\n token,\n method: context.req.method,\n path: new URL(context.req.url).pathname,\n });\n\n const principal = await this.options.resolvePrincipal({ issuer, context });\n\n // Validated rather than trusted. The provider also refuses an answer without a `userId`, but a principal an\n // application resolves wrongly is reported here, at the cause, with the issuer and the strategy named.\n if (!principal?.userId) {\n this.logger\n .for(this.authenticate.name)\n .warn('resolvePrincipal returned no usable principal | iss: %s', issuer);\n throw getError({ error: AuthenticationErrors.PRINCIPAL_UNRESOLVED });\n }\n\n // Which service called is audit-relevant even when the principal is shared across callers.\n return { ...principal, callerService: issuer };\n }\n}\n"]}
1
+ {"version":3,"file":"service.strategy.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/strategies/service.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,GACP,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF;;;;;;GAMG;AACH,IAAa,6BAA6B,qCAA1C,MAAa,6BACX,SAAQ,UAAU;IAKlB,YAOE,QAA0D,EAE1D,OAAgD;QAEhD,KAAK,CAAC,EAAE,KAAK,EAAE,+BAA6B,CAAC,IAAI,EAAE,CAAC,CAAC;QAJpC,aAAQ,GAAR,QAAQ,CAAiC;QAEzC,YAAO,GAAP,OAAO,CAAwB;QAXlD,SAAI,GAAG,cAAc,CAAC,gBAAgB,CAAC;IAcvC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA4B;QAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,GAA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AAE,CAAC,CAAA;qCAD9B,+BAA+B;GAbjD,6BAA6B,CAiDzC","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport type { Env } from 'hono';\nimport {\n AuthenticateBindingKeys,\n Authentication,\n AuthenticationErrors,\n BindingNamespaces,\n ServiceAssertion,\n inject,\n} from '@venizia/ignis-kernel';\nimport type {\n IAuthUser,\n IAuthenticationStrategy,\n IServiceAuthOptions,\n TContext,\n} from '@venizia/ignis-kernel';\nimport { ServiceAssertionVerifierService } from '../services/service/verifier.service';\n\n/**\n * Proves the CALLING SERVICE, from a per-request Ed25519 assertion verified against that caller's\n * own JWKS. No identity round trip and no shared password.\n *\n * It proves which service called, never which user. `resolvePrincipal` is where the application\n * turns a caller name into one of its own principals.\n */\nexport class ServiceAuthenticationStrategy<E extends Env = Env>\n extends BaseHelper\n implements IAuthenticationStrategy<E>\n{\n name = Authentication.STRATEGY_SERVICE;\n\n constructor(\n @inject({\n key: BindingKeys.build<ServiceAssertionVerifierService>({\n namespace: BindingNamespaces.SERVICE,\n key: ServiceAssertionVerifierService.name,\n }),\n })\n private readonly verifier: ServiceAssertionVerifierService,\n @inject({ key: AuthenticateBindingKeys.SERVICE_OPTIONS })\n private readonly options: IServiceAuthOptions<E>,\n ) {\n super({ scope: ServiceAuthenticationStrategy.name });\n }\n\n async authenticate(context: TContext<E, string>): Promise<IAuthUser> {\n const token = context.req.header(ServiceAssertion.HEADER);\n\n if (!token) {\n throw getError({ error: AuthenticationErrors.ASSERTION_MISSING });\n }\n\n // The raw url, NOT `context.req.path`: Hono hands that back percent-DECODED, so a route carrying\n // a space or a non-ASCII slug would never match the encoded path the caller signed.\n const { issuer } = await this.verifier.verify({\n token,\n method: context.req.method,\n path: new URL(context.req.url).pathname,\n });\n\n const principal = await this.options.resolvePrincipal({ issuer, context });\n\n // Validated rather than trusted. The provider also refuses an answer without a `userId`, but a principal an\n // application resolves wrongly is reported here, at the cause, with the issuer and the strategy named.\n if (!principal?.userId) {\n this.logger\n .for(this.authenticate.name)\n .warn('resolvePrincipal returned no usable principal | iss: %s', issuer);\n throw getError({ error: AuthenticationErrors.PRINCIPAL_UNRESOLVED });\n }\n\n // Which service called is audit-relevant even when the principal is shared across callers.\n return { ...principal, callerService: issuer };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAE/B,6IAA6I;AAC7I,IAAa,kBAAkB,0BAA/B,MAAa,kBAAmB,SAAQ,aAAa;IACnD,YAC8D,WAA4B;QAExF,KAAK,CAAC;YACJ,KAAK,EAAE,oBAAkB,CAAC,IAAI;YAC9B,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;SACtD,CAAC,CAAC;QALyD,gBAAW,GAAX,WAAW,CAAiB;IAM1F,CAAC;IAEQ,OAAO;QACd,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAoB;YACtD,GAAG,EAAE,oBAAoB,CAAC,OAAO;YACjC,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,QAAQ,CAAC;gBACb,OAAO,EACL,iIAAiI;aACpI,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAEvC,0FAA0F;QAC1F,4FAA4F;QAC5F,6BAA6B,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAEpE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEO,oBAAoB,CAAC,IAAoC;QAC/D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC;YAC3C,OAAO;QACT,CAAC;QAED,IAAI,CAAC,WAAW;aACb,IAAI,CAAW,EAAE,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC;aAChE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAzCY,kBAAkB;IAE1B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,kBAAkB,CAyC9B","sourcesContent":["import type { BaseApplication } from '@/base/applications/base';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { CoreBindings } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n AuthorizationEnforcerRegistry,\n AuthorizeBindingKeys,\n type IAuthorizeOptions,\n} from '@venizia/ignis-kernel';\n\n/** Registers authorization from the options bound under `AuthorizeBindingKeys.OPTIONS`. Throws at binding time when no options are bound. */\nexport class AuthorizeComponent extends BaseComponent {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: AuthorizeComponent.name,\n initDefault: { enable: true, container: application },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const options = this.application.get<IAuthorizeOptions>({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (!options) {\n throw getError({\n message:\n '[AuthorizeComponent] No authorize options found. Bind options to AuthorizeBindingKeys.OPTIONS before registering the component.',\n });\n }\n\n this.bindAlwaysAllowRoles({ options });\n\n // The registry otherwise finds options only through a registered enforcer's container, so\n // `defaultDecision` would be unreadable in the one case it decides: no enforcer registered.\n AuthorizationEnforcerRegistry.getInstance().setOptions({ options });\n\n this.logger.for(this.binding.name).info('Authorization configured');\n }\n\n private bindAlwaysAllowRoles(opts: { options: IAuthorizeOptions }): void {\n if (!opts.options.alwaysAllowRoles?.length) {\n return;\n }\n\n this.application\n .bind<string[]>({ key: AuthorizeBindingKeys.ALWAYS_ALLOW_ROLES })\n .toValue(opts.options.alwaysAllowRoles);\n }\n}\n"]}
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAE/B,6IAA6I;AAC7I,IAAa,kBAAkB,0BAA/B,MAAa,kBAAmB,SAAQ,aAAa;IACnD,YAC8D,WAA4B;QAExF,KAAK,CAAC;YACJ,KAAK,EAAE,oBAAkB,CAAC,IAAI;YAC9B,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;SACtD,CAAC,CAAC;QALyD,gBAAW,GAAX,WAAW,CAAiB;IAM1F,CAAC;IAEQ,OAAO;QACd,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;YACnC,GAAG,EAAE,oBAAoB,CAAC,OAAO;YACjC,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,QAAQ,CAAC;gBACb,OAAO,EACL,iIAAiI;aACpI,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAEvC,0FAA0F;QAC1F,4FAA4F;QAC5F,6BAA6B,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAEpE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACtE,CAAC;IAEO,oBAAoB,CAAC,IAAoC;QAC/D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC;YAC3C,OAAO;QACT,CAAC;QAED,IAAI,CAAC,WAAW;aACb,IAAI,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC;aACtD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAzCY,kBAAkB;IAE1B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,kBAAkB,CAyC9B","sourcesContent":["import type { BaseApplication } from '@/base/applications/base';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { CoreBindings } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n AuthorizationEnforcerRegistry,\n AuthorizeBindingKeys,\n type IAuthorizeOptions,\n} from '@venizia/ignis-kernel';\n\n/** Registers authorization from the options bound under `AuthorizeBindingKeys.OPTIONS`. Throws at binding time when no options are bound. */\nexport class AuthorizeComponent extends BaseComponent {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: AuthorizeComponent.name,\n initDefault: { enable: true, container: application },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const options = this.application.get({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (!options) {\n throw getError({\n message:\n '[AuthorizeComponent] No authorize options found. Bind options to AuthorizeBindingKeys.OPTIONS before registering the component.',\n });\n }\n\n this.bindAlwaysAllowRoles({ options });\n\n // The registry otherwise finds options only through a registered enforcer's container, so\n // `defaultDecision` would be unreadable in the one case it decides: no enforcer registered.\n AuthorizationEnforcerRegistry.getInstance().setOptions({ options });\n\n this.logger.for(this.binding.name).info('Authorization configured');\n }\n\n private bindAlwaysAllowRoles(opts: { options: IAuthorizeOptions }): void {\n if (!opts.options.alwaysAllowRoles?.length) {\n return;\n }\n\n this.application\n .bind({ key: AuthorizeBindingKeys.ALWAYS_ALLOW_ROLES })\n .toValue(opts.options.alwaysAllowRoles);\n }\n}\n"]}
@@ -8,6 +8,6 @@ export interface IGrpcComponentConfig {
8
8
  }
9
9
  /** Container keys of the gRPC component. */
10
10
  export declare class GrpcBindingKeys {
11
- static readonly GRPC_COMPONENT_OPTIONS = "@app/grpc/options";
11
+ static readonly GRPC_COMPONENT_OPTIONS: import("@venizia/ignis-inversion").TBindingKey<IGrpcComponentConfig>;
12
12
  }
13
13
  //# sourceMappingURL=types.d.ts.map
@@ -1,5 +1,8 @@
1
+ import { BindingKeys } from '@venizia/ignis-inversion';
1
2
  /** Container keys of the gRPC component. */
2
3
  export class GrpcBindingKeys {
3
- static { this.GRPC_COMPONENT_OPTIONS = '@app/grpc/options'; }
4
+ static { this.GRPC_COMPONENT_OPTIONS = BindingKeys.build({
5
+ key: '@app/grpc/options',
6
+ }); }
4
7
  }
5
8
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/components/controller/grpc/common/types.ts"],"names":[],"mappings":"AAYA,4CAA4C;AAC5C,MAAM,OAAO,eAAe;aACV,2BAAsB,GAAG,mBAAmB,CAAC","sourcesContent":["import type { IConnectRpcModule } from '@/base/controllers/grpc/common/types';\n\n// Re-exported so an application can name the type without reaching into the base barrel.\nexport type { IConnectRpcModule };\n\n/** Options of `GrpcComponent`, bound at `GrpcBindingKeys.GRPC_COMPONENT_OPTIONS`. */\nexport interface IGrpcComponentConfig {\n interceptors?: unknown[];\n /** The ConnectRPC peer, for a compiled binary that has no `node_modules` to resolve it from. */\n module?: IConnectRpcModule;\n}\n\n/** Container keys of the gRPC component. */\nexport class GrpcBindingKeys {\n static readonly GRPC_COMPONENT_OPTIONS = '@app/grpc/options';\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/components/controller/grpc/common/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAYvD,4CAA4C;AAC5C,MAAM,OAAO,eAAe;aACV,2BAAsB,GAAG,WAAW,CAAC,KAAK,CAAuB;QAC/E,GAAG,EAAE,mBAAmB;KACzB,CAAC,CAAC","sourcesContent":["import type { IConnectRpcModule } from '@/base/controllers/grpc/common/types';\nimport { BindingKeys } from '@venizia/ignis-inversion';\n\n// Re-exported so an application can name the type without reaching into the base barrel.\nexport type { IConnectRpcModule };\n\n/** Options of `GrpcComponent`, bound at `GrpcBindingKeys.GRPC_COMPONENT_OPTIONS`. */\nexport interface IGrpcComponentConfig {\n interceptors?: unknown[];\n /** The ConnectRPC peer, for a compiled binary that has no `node_modules` to resolve it from. */\n module?: IConnectRpcModule;\n}\n\n/** Container keys of the gRPC component. */\nexport class GrpcBindingKeys {\n static readonly GRPC_COMPONENT_OPTIONS = BindingKeys.build<IGrpcComponentConfig>({\n key: '@app/grpc/options',\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"grpc.component.js","sourceRo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,CAAC,UAAU;gBACjC,OAAO,EAAE,UAAU;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { BaseApplication } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { ControllerTransports } from '@venizia/ignis-kernel';\nimport type { AbstractGrpcController } from '@/base/controllers/grpc';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { Binding, BindingValueTypes, MetadataRegistry } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { IGrpcComponentConfig } from './common/types';\nimport { GrpcBindingKeys } from './common/types';\n\nconst DEFAULT_OPTIONS: IGrpcComponentConfig = {};\n\n/** Mounts every controller declared with the gRPC transport onto the root router at its metadata `path`, and hands each the `IGrpcComponentConfig` interceptors and ConnectRPC module. A gRPC controller without a service definition is skipped with a warning. */\nexport class GrpcComponent extends BaseComponent {\n constructor(private application: BaseApplication) {\n super({\n scope: GrpcComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [GrpcBindingKeys.GRPC_COMPONENT_OPTIONS]: Binding.bind<IGrpcComponentConfig>({\n key: GrpcBindingKeys.GRPC_COMPONENT_OPTIONS,\n }).toValue(DEFAULT_OPTIONS),\n },\n });\n }\n\n override async binding(): Promise<void> {\n const logger = this.logger.for(this.binding.name);\n const router = this.application.getRootRouter();\n\n const options = this.application.get<IGrpcComponentConfig>({\n key: GrpcBindingKeys.GRPC_COMPONENT_OPTIONS,\n isOptional: true,\n });\n\n // Batch drained before re-scanning - see `RestApplication.registerDynamicBindings` for why.\n const configured = new Set<string>();\n\n let bindings = this.application.findByTag({\n tag: BindingNamespaces.CONTROLLER,\n exclude: configured,\n });\n\n while (bindings.length > 0) {\n for (const binding of bindings) {\n if (configured.has(binding.key)) {\n continue;\n }\n\n const target = binding.getBindingMeta({ type: BindingValueTypes.CLASS });\n\n if (!target) {\n configured.add(binding.key);\n continue;\n }\n\n const metadata = MetadataRegistry.getInstance().getControllerMetadata({ target });\n\n // Skip non-gRPC controllers — they are configured by RestComponent\n if (metadata?.transport !== ControllerTransports.GRPC) {\n configured.add(binding.key);\n continue;\n }\n\n if (!metadata?.path || ObjectUtility.isEmpty({ value: metadata.path })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[registerControllers] key: '${binding.key}' | Invalid controller metadata, 'path' is required for gRPC controller metadata`,\n });\n }\n\n const instance = this.application.get<AbstractGrpcController>({\n key: binding.key,\n isOptional: false,\n });\n\n if (!instance) {\n logger.debug('No binding instance | key: %s', binding.key);\n configured.add(binding.key);\n continue;\n }\n\n if (!instance.service) {\n logger.warn('gRPC controller has no service definition, skipping | key: %s', binding.key);\n configured.add(binding.key);\n continue;\n }\n\n instance.basePath = this.application.getProjectConfigs().path.base;\n instance.connectRpcModule = options?.module;\n instance.interceptors = options?.interceptors;\n await instance.configure();\n\n router.route(metadata.path, instance.getRouter());\n configured.add(binding.key);\n\n logger.info('Configured gRPC controller | key: %s | path: %s', binding.key, metadata.path);\n }\n\n // Re-fetch excluding already configured — picks up dynamically added controllers\n bindings = this.application.findByTag({\n tag: BindingNamespaces.CONTROLLER,\n exclude: configured,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"grpc.component.js","sourceRoot":"","sources":["../../../../../src/components/controller/grpc/grpc.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;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Q,CAAC,OAAO,EAAE,CAAC;oBACtB,MAAM,CAAC,IAAI,CAAC,+DAA+D,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;oBAC1F,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;oBAC5B,SAAS;gBACX,CAAC;gBAED,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;gBACnE,QAAQ,CAAC,gBAAgB,GAAG,OAAO,EAAE,MAAM,CAAC;gBAC5C,QAAQ,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;gBAC9C,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAE3B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;gBAClD,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAE5B,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7F,CAAC;YAED,iFAAiF;YACjF,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;gBACpC,GAAG,EAAE,iBAAiB,CAAC,UAAU;gBACjC,OAAO,EAAE,UAAU;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { BaseApplication } from '@/base/applications';\nimport { BaseComponent } from '@venizia/ignis-kernel';\nimport { ControllerTransports } from '@venizia/ignis-kernel';\nimport type { AbstractGrpcController } from '@/base/controllers/grpc';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { Binding, BindingValueTypes, MetadataRegistry } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { IGrpcComponentConfig } from './common/types';\nimport { GrpcBindingKeys } from './common/types';\n\nconst DEFAULT_OPTIONS: IGrpcComponentConfig = {};\n\n/** Mounts every controller declared with the gRPC transport onto the root router at its metadata `path`, and hands each the `IGrpcComponentConfig` interceptors and ConnectRPC module. A gRPC controller without a service definition is skipped with a warning. */\nexport class GrpcComponent extends BaseComponent {\n constructor(private application: BaseApplication) {\n super({\n scope: GrpcComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [GrpcBindingKeys.GRPC_COMPONENT_OPTIONS]: Binding.bind({\n key: GrpcBindingKeys.GRPC_COMPONENT_OPTIONS,\n }).toValue(DEFAULT_OPTIONS),\n },\n });\n }\n\n override async binding(): Promise<void> {\n const logger = this.logger.for(this.binding.name);\n const router = this.application.getRootRouter();\n\n const options = this.application.get({\n key: GrpcBindingKeys.GRPC_COMPONENT_OPTIONS,\n isOptional: true,\n });\n\n // Batch drained before re-scanning - see `RestApplication.registerDynamicBindings` for why.\n const configured = new Set<string>();\n\n let bindings = this.application.findByTag({\n tag: BindingNamespaces.CONTROLLER,\n exclude: configured,\n });\n\n while (bindings.length > 0) {\n for (const binding of bindings) {\n if (configured.has(binding.key)) {\n continue;\n }\n\n const target = binding.getBindingMeta({ type: BindingValueTypes.CLASS });\n\n if (!target) {\n configured.add(binding.key);\n continue;\n }\n\n const metadata = MetadataRegistry.getInstance().getControllerMetadata({ target });\n\n // Skip non-gRPC controllers — they are configured by RestComponent\n if (metadata?.transport !== ControllerTransports.GRPC) {\n configured.add(binding.key);\n continue;\n }\n\n if (!metadata?.path || ObjectUtility.isEmpty({ value: metadata.path })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[registerControllers] key: '${binding.key}' | Invalid controller metadata, 'path' is required for gRPC controller metadata`,\n });\n }\n\n const instance = this.application.get<AbstractGrpcController>({\n key: binding.key,\n isOptional: false,\n });\n\n if (!instance) {\n logger.debug('No binding instance | key: %s', binding.key);\n configured.add(binding.key);\n continue;\n }\n\n if (!instance.service) {\n logger.warn('gRPC controller has no service definition, skipping | key: %s', binding.key);\n configured.add(binding.key);\n continue;\n }\n\n instance.basePath = this.application.getProjectConfigs().path.base;\n instance.connectRpcModule = options?.module;\n instance.interceptors = options?.interceptors;\n await instance.configure();\n\n router.route(metadata.path, instance.getRouter());\n configured.add(binding.key);\n\n logger.info('Configured gRPC controller | key: %s | path: %s', binding.key, metadata.path);\n }\n\n // Re-fetch excluding already configured — picks up dynamically added controllers\n bindings = this.application.findByTag({\n tag: BindingNamespaces.CONTROLLER,\n exclude: configured,\n });\n }\n }\n}\n"]}
@@ -1,7 +1,9 @@
1
+ import type { IApplicationInfo } from '@venizia/ignis-kernel';
2
+ import type { IHealthCheckOptions } from './types.js';
1
3
  /** Container keys of the health check component. */
2
4
  export declare class HealthCheckBindingKeys {
3
- static readonly HEALTH_CHECK_OPTIONS = "@app/health-check/options";
5
+ static readonly HEALTH_CHECK_OPTIONS: import("@venizia/ignis-inversion").TBindingKey<IHealthCheckOptions>;
4
6
  /** The component resolves `getAppInfo()` once (it is async) and binds the result for the controller. */
5
- static readonly APPLICATION_INFO = "@app/health-check/application-info";
7
+ static readonly APPLICATION_INFO: import("@venizia/ignis-inversion").TBindingKey<IApplicationInfo>;
6
8
  }
7
9
  //# sourceMappingURL=keys.d.ts.map