@opencloudcms/oauth2 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +397 -2
  3. package/dist/audit/audit.service.d.ts +18 -0
  4. package/dist/audit/audit.service.js +61 -0
  5. package/dist/audit/audit.service.js.map +1 -0
  6. package/dist/bff/auth.controller.d.ts +41 -0
  7. package/dist/bff/auth.controller.js +269 -0
  8. package/dist/bff/auth.controller.js.map +1 -0
  9. package/dist/bff/cookies.d.ts +11 -0
  10. package/dist/bff/cookies.js +43 -0
  11. package/dist/bff/cookies.js.map +1 -0
  12. package/dist/bff/oidc-client.d.ts +73 -0
  13. package/dist/bff/oidc-client.js +158 -0
  14. package/dist/bff/oidc-client.js.map +1 -0
  15. package/dist/bff/session-refresher.d.ts +27 -0
  16. package/dist/bff/session-refresher.js +95 -0
  17. package/dist/bff/session-refresher.js.map +1 -0
  18. package/dist/bff/session.store.d.ts +88 -0
  19. package/dist/bff/session.store.js +167 -0
  20. package/dist/bff/session.store.js.map +1 -0
  21. package/dist/clients/clients.d.ts +37 -0
  22. package/dist/clients/clients.js +107 -0
  23. package/dist/clients/clients.js.map +1 -0
  24. package/dist/config/schema.d.ts +91 -0
  25. package/dist/config/schema.js +129 -0
  26. package/dist/config/schema.js.map +1 -0
  27. package/dist/constants.d.ts +45 -0
  28. package/dist/constants.js +42 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/cors/cors-origins.controller.d.ts +19 -0
  31. package/dist/cors/cors-origins.controller.js +122 -0
  32. package/dist/cors/cors-origins.controller.js.map +1 -0
  33. package/dist/cors/cors-origins.service.d.ts +73 -0
  34. package/dist/cors/cors-origins.service.js +287 -0
  35. package/dist/cors/cors-origins.service.js.map +1 -0
  36. package/dist/cors/customer-cors.middleware.d.ts +22 -0
  37. package/dist/cors/customer-cors.middleware.js +84 -0
  38. package/dist/cors/customer-cors.middleware.js.map +1 -0
  39. package/dist/customers/account.controller.d.ts +91 -0
  40. package/dist/customers/account.controller.js +443 -0
  41. package/dist/customers/account.controller.js.map +1 -0
  42. package/dist/customers/auth-hooks.d.ts +47 -0
  43. package/dist/customers/auth-hooks.js +79 -0
  44. package/dist/customers/auth-hooks.js.map +1 -0
  45. package/dist/customers/customer-auth.controller.d.ts +54 -0
  46. package/dist/customers/customer-auth.controller.js +287 -0
  47. package/dist/customers/customer-auth.controller.js.map +1 -0
  48. package/dist/customers/customer-sessions.revoker.d.ts +21 -0
  49. package/dist/customers/customer-sessions.revoker.js +47 -0
  50. package/dist/customers/customer-sessions.revoker.js.map +1 -0
  51. package/dist/customers/customer.service.d.ts +53 -0
  52. package/dist/customers/customer.service.js +229 -0
  53. package/dist/customers/customer.service.js.map +1 -0
  54. package/dist/customers/customers-admin.controller.d.ts +21 -0
  55. package/dist/customers/customers-admin.controller.js +134 -0
  56. package/dist/customers/customers-admin.controller.js.map +1 -0
  57. package/dist/customers/identifier.d.ts +6 -0
  58. package/dist/customers/identifier.js +27 -0
  59. package/dist/customers/identifier.js.map +1 -0
  60. package/dist/customers/sign-in-settings.controller.d.ts +27 -0
  61. package/dist/customers/sign-in-settings.controller.js +112 -0
  62. package/dist/customers/sign-in-settings.controller.js.map +1 -0
  63. package/dist/customers/sign-in-settings.service.d.ts +35 -0
  64. package/dist/customers/sign-in-settings.service.js +130 -0
  65. package/dist/customers/sign-in-settings.service.js.map +1 -0
  66. package/dist/db/migrations/index.d.ts +2 -0
  67. package/dist/db/migrations/index.js +14 -0
  68. package/dist/db/migrations/index.js.map +1 -0
  69. package/dist/db/migrations/oauth2_0001_init.d.ts +2 -0
  70. package/dist/db/migrations/oauth2_0001_init.js +127 -0
  71. package/dist/db/migrations/oauth2_0001_init.js.map +1 -0
  72. package/dist/db/migrations/oauth2_0002_user_locale.d.ts +3 -0
  73. package/dist/db/migrations/oauth2_0002_user_locale.js +13 -0
  74. package/dist/db/migrations/oauth2_0002_user_locale.js.map +1 -0
  75. package/dist/db/migrations/oauth2_0003_groups.d.ts +6 -0
  76. package/dist/db/migrations/oauth2_0003_groups.js +46 -0
  77. package/dist/db/migrations/oauth2_0003_groups.js.map +1 -0
  78. package/dist/db/migrations/oauth2_0004_customers.d.ts +3 -0
  79. package/dist/db/migrations/oauth2_0004_customers.js +108 -0
  80. package/dist/db/migrations/oauth2_0004_customers.js.map +1 -0
  81. package/dist/db/types.d.ts +176 -0
  82. package/dist/db/types.js +3 -0
  83. package/dist/db/types.js.map +1 -0
  84. package/dist/errors.d.ts +28 -0
  85. package/dist/errors.js +115 -0
  86. package/dist/errors.js.map +1 -0
  87. package/dist/groups/groups.controller.d.ts +28 -0
  88. package/dist/groups/groups.controller.js +126 -0
  89. package/dist/groups/groups.controller.js.map +1 -0
  90. package/dist/groups/groups.service.d.ts +38 -0
  91. package/dist/groups/groups.service.js +134 -0
  92. package/dist/groups/groups.service.js.map +1 -0
  93. package/dist/guard/auth.guard.d.ts +29 -0
  94. package/dist/guard/auth.guard.js +119 -0
  95. package/dist/guard/auth.guard.js.map +1 -0
  96. package/dist/guard/current-user.decorator.d.ts +33 -0
  97. package/dist/guard/current-user.decorator.js +16 -0
  98. package/dist/guard/current-user.decorator.js.map +1 -0
  99. package/dist/guard/customer-auth.decorator.d.ts +26 -0
  100. package/dist/guard/customer-auth.decorator.js +16 -0
  101. package/dist/guard/customer-auth.decorator.js.map +1 -0
  102. package/dist/guard/customer-authenticator.d.ts +58 -0
  103. package/dist/guard/customer-authenticator.js +215 -0
  104. package/dist/guard/customer-authenticator.js.map +1 -0
  105. package/dist/guard/public.decorator.d.ts +2 -0
  106. package/dist/guard/public.decorator.js +8 -0
  107. package/dist/guard/public.decorator.js.map +1 -0
  108. package/dist/guard/session-auth.service.d.ts +28 -0
  109. package/dist/guard/session-auth.service.js +125 -0
  110. package/dist/guard/session-auth.service.js.map +1 -0
  111. package/dist/idp/identity-linker.d.ts +19 -0
  112. package/dist/idp/identity-linker.js +93 -0
  113. package/dist/idp/identity-linker.js.map +1 -0
  114. package/dist/idp/identity-provider.d.ts +54 -0
  115. package/dist/idp/identity-provider.js +36 -0
  116. package/dist/idp/identity-provider.js.map +1 -0
  117. package/dist/idp/idp.controller.d.ts +36 -0
  118. package/dist/idp/idp.controller.js +232 -0
  119. package/dist/idp/idp.controller.js.map +1 -0
  120. package/dist/idp/oidc.identity-provider.d.ts +42 -0
  121. package/dist/idp/oidc.identity-provider.js +96 -0
  122. package/dist/idp/oidc.identity-provider.js.map +1 -0
  123. package/dist/index.d.ts +50 -0
  124. package/dist/index.js +98 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/interaction/customer-interaction.controller.d.ts +64 -0
  127. package/dist/interaction/customer-interaction.controller.js +336 -0
  128. package/dist/interaction/customer-interaction.controller.js.map +1 -0
  129. package/dist/interaction/interaction.controller.d.ts +36 -0
  130. package/dist/interaction/interaction.controller.js +175 -0
  131. package/dist/interaction/interaction.controller.js.map +1 -0
  132. package/dist/interaction/interaction.service.d.ts +40 -0
  133. package/dist/interaction/interaction.service.js +102 -0
  134. package/dist/interaction/interaction.service.js.map +1 -0
  135. package/dist/maintenance/cleanup.service.d.ts +22 -0
  136. package/dist/maintenance/cleanup.service.js +77 -0
  137. package/dist/maintenance/cleanup.service.js.map +1 -0
  138. package/dist/oauth2.module.d.ts +37 -0
  139. package/dist/oauth2.module.js +214 -0
  140. package/dist/oauth2.module.js.map +1 -0
  141. package/dist/otp/otp-guard.d.ts +7 -0
  142. package/dist/otp/otp-guard.js +27 -0
  143. package/dist/otp/otp-guard.js.map +1 -0
  144. package/dist/otp/otp.service.d.ts +57 -0
  145. package/dist/otp/otp.service.js +202 -0
  146. package/dist/otp/otp.service.js.map +1 -0
  147. package/dist/otp/otp.types.d.ts +36 -0
  148. package/dist/otp/otp.types.js +34 -0
  149. package/dist/otp/otp.types.js.map +1 -0
  150. package/dist/otp/storefront-boot-check.d.ts +13 -0
  151. package/dist/otp/storefront-boot-check.js +53 -0
  152. package/dist/otp/storefront-boot-check.js.map +1 -0
  153. package/dist/permissions.d.ts +12 -0
  154. package/dist/permissions.js +24 -0
  155. package/dist/permissions.js.map +1 -0
  156. package/dist/provider/kysely.adapter.d.ts +27 -0
  157. package/dist/provider/kysely.adapter.js +79 -0
  158. package/dist/provider/kysely.adapter.js.map +1 -0
  159. package/dist/provider/provider.factory.d.ts +101 -0
  160. package/dist/provider/provider.factory.js +377 -0
  161. package/dist/provider/provider.factory.js.map +1 -0
  162. package/dist/provider/provider.service.d.ts +60 -0
  163. package/dist/provider/provider.service.js +200 -0
  164. package/dist/provider/provider.service.js.map +1 -0
  165. package/dist/provider/signing-keys.d.ts +19 -0
  166. package/dist/provider/signing-keys.js +41 -0
  167. package/dist/provider/signing-keys.js.map +1 -0
  168. package/dist/register-migrations.d.ts +1 -0
  169. package/dist/register-migrations.js +7 -0
  170. package/dist/register-migrations.js.map +1 -0
  171. package/dist/security/crypto.d.ts +6 -0
  172. package/dist/security/crypto.js +29 -0
  173. package/dist/security/crypto.js.map +1 -0
  174. package/dist/security/email.d.ts +1 -0
  175. package/dist/security/email.js +7 -0
  176. package/dist/security/email.js.map +1 -0
  177. package/dist/security/origin.d.ts +1 -0
  178. package/dist/security/origin.js +15 -0
  179. package/dist/security/origin.js.map +1 -0
  180. package/dist/security/password.d.ts +12 -0
  181. package/dist/security/password.js +92 -0
  182. package/dist/security/password.js.map +1 -0
  183. package/dist/security/rate-limiter.d.ts +25 -0
  184. package/dist/security/rate-limiter.js +52 -0
  185. package/dist/security/rate-limiter.js.map +1 -0
  186. package/dist/security/return-to.d.ts +6 -0
  187. package/dist/security/return-to.js +33 -0
  188. package/dist/security/return-to.js.map +1 -0
  189. package/dist/security/validate.d.ts +3 -0
  190. package/dist/security/validate.js +14 -0
  191. package/dist/security/validate.js.map +1 -0
  192. package/dist/settings/settings.provider.d.ts +11 -0
  193. package/dist/settings/settings.provider.js +20 -0
  194. package/dist/settings/settings.provider.js.map +1 -0
  195. package/dist/setup/bootstrap.service.d.ts +24 -0
  196. package/dist/setup/bootstrap.service.js +117 -0
  197. package/dist/setup/bootstrap.service.js.map +1 -0
  198. package/dist/setup/setup-state.d.ts +8 -0
  199. package/dist/setup/setup-state.js +42 -0
  200. package/dist/setup/setup-state.js.map +1 -0
  201. package/dist/setup/setup.controller.d.ts +23 -0
  202. package/dist/setup/setup.controller.js +96 -0
  203. package/dist/setup/setup.controller.js.map +1 -0
  204. package/dist/users/password.controller.d.ts +19 -0
  205. package/dist/users/password.controller.js +87 -0
  206. package/dist/users/password.controller.js.map +1 -0
  207. package/dist/users/user.service.d.ts +114 -0
  208. package/dist/users/user.service.js +336 -0
  209. package/dist/users/user.service.js.map +1 -0
  210. package/dist/users/users.controller.d.ts +43 -0
  211. package/dist/users/users.controller.js +188 -0
  212. package/dist/users/users.controller.js.map +1 -0
  213. package/package.json +75 -3
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ProviderService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const kysely_1 = require("kysely");
19
+ const clients_1 = require("../clients/clients");
20
+ const constants_1 = require("../constants");
21
+ const auth_hooks_1 = require("../customers/auth-hooks");
22
+ const customer_service_1 = require("../customers/customer.service");
23
+ const crypto_1 = require("../security/crypto");
24
+ const bootstrap_service_1 = require("../setup/bootstrap.service");
25
+ const user_service_1 = require("../users/user.service");
26
+ const kysely_adapter_1 = require("./kysely.adapter");
27
+ const provider_factory_1 = require("./provider.factory");
28
+ const signing_keys_1 = require("./signing-keys");
29
+ let ProviderService = class ProviderService {
30
+ db;
31
+ cfg;
32
+ settings;
33
+ adapterHost;
34
+ moduleRef;
35
+ logger = new common_1.Logger('OAuth2');
36
+ adapter;
37
+ instance;
38
+ constructor(db, cfg, settings, adapterHost, moduleRef) {
39
+ this.db = db;
40
+ this.cfg = cfg;
41
+ this.settings = settings;
42
+ this.adapterHost = adapterHost;
43
+ this.moduleRef = moduleRef;
44
+ this.adapter = (0, kysely_adapter_1.createKyselyAdapter)(db);
45
+ }
46
+ get provider() {
47
+ if (!this.instance)
48
+ throw new Error('oidc-provider is not initialised yet');
49
+ return this.instance;
50
+ }
51
+ async onModuleInit() {
52
+ await this.moduleRef.get(constants_1.CORE_READY, { strict: false }).wait();
53
+ const jwks = await (0, signing_keys_1.ensureSigningKey)(this.db, (0, crypto_1.deriveKey)(this.cfg.secret, 'key'));
54
+ await (0, provider_factory_1.upsertAdminClient)(this.db, this.cfg);
55
+ // The web client row is only written while the storefront is on (findAdapterClient ignores it otherwise).
56
+ const webRedirectUris = this.cfg.storefront.enabled ? await this.webRedirectUrisFromCors() : [];
57
+ if (this.cfg.storefront.enabled)
58
+ await this.syncWebClient(webRedirectUris);
59
+ const users = this.moduleRef.get(user_service_1.UserService, { strict: false });
60
+ const customers = this.moduleRef.get(customer_service_1.CustomerService, { strict: false });
61
+ this.instance = await (0, provider_factory_1.createProvider)({
62
+ cfg: this.cfg,
63
+ adapter: (0, provider_factory_1.withClientFinder)(this.adapter, (id) => this.findAdapterClient(id)),
64
+ jwks,
65
+ clients: (0, clients_1.buildClients)(this.cfg, webRedirectUris),
66
+ ttls: await provider_factory_1.TtlSnapshot.create(() => this.settings.getTtls()),
67
+ findUser: (id) => users.findById(id),
68
+ findCustomer: (id) => customers.findById(id),
69
+ customerTtls: () => this.cfg.storefront.ttl,
70
+ onCodeExchanged: (e) => this.afterCodeExchange(e),
71
+ });
72
+ await this.moduleRef.get(bootstrap_service_1.BootstrapService, { strict: false }).run();
73
+ const http = this.adapterHost?.httpAdapter;
74
+ if (!http) {
75
+ this.logger.warn('No HTTP adapter; oidc-provider is not mounted at /oauth2');
76
+ return;
77
+ }
78
+ http.getInstance().use('/oauth2', ...(0, provider_factory_1.providerMountHandlers)(this.cfg.publicUrl, this.instance.callback()));
79
+ }
80
+ /**
81
+ * `afterSignIn` for customer sign-ins of the public clients (mobile, web): fired once, when the client exchanges
82
+ * its authorization code (never on refresh). The site's BFF (`opencloudcms-storefront`) fires its own in its
83
+ * callback, so it is skipped here; admin-realm codes are not customer sign-ins.
84
+ */
85
+ async afterCodeExchange(e) {
86
+ if ((0, clients_1.realmOf)(e.clientId) !== 'customer' || e.clientId === constants_1.STOREFRONT_CLIENT_ID)
87
+ return;
88
+ try {
89
+ const customer = await this.moduleRef.get(customer_service_1.CustomerService, { strict: false }).findById(e.accountId);
90
+ if (!customer || customer.status !== 'active')
91
+ return;
92
+ await this.moduleRef.get(auth_hooks_1.AuthHookRunner, { strict: false }).after('afterSignIn', customer, {
93
+ db: this.db,
94
+ ip: e.ip,
95
+ userAgent: e.userAgent,
96
+ method: e.amr?.includes('pwd') ? 'password' : 'otp',
97
+ clientId: e.clientId,
98
+ });
99
+ }
100
+ catch (err) {
101
+ this.logger.warn(`afterSignIn after code exchange failed: ${err?.name ?? 'Error'}`);
102
+ }
103
+ }
104
+ /** Destroys one Grant and every code/token issued under it (a public client's logout). */
105
+ async revokeGrant(grantId) {
106
+ await new this.adapter('Grant').revokeByGrantId(grantId);
107
+ await new this.adapter('Grant').destroy(grantId);
108
+ }
109
+ /**
110
+ * Stores the `opencloudcms-storefront-web` client's metadata (public, PKCE, refresh tokens) with these redirect
111
+ * URIs (also its post-logout URIs) in auth_oauth_clients. The client is not a static provider client: the
112
+ * provider reads this row through the adapter on every request (findAdapterClient), so the change applies on
113
+ * every instance without restart. An empty list makes the client unknown. `trx`: write inside the caller's
114
+ * transaction (CorsOriginsService serializes its writes with this).
115
+ */
116
+ async syncWebClient(redirectUris, trx) {
117
+ const uris = [...new Set(redirectUris)];
118
+ const json = JSON.stringify((0, clients_1.clientMetadata)((0, clients_1.webClientSpec)(this.cfg, uris)));
119
+ await (trx ?? this.db)
120
+ .insertInto('auth_oauth_clients')
121
+ .values({ client_id: constants_1.STOREFRONT_WEB_CLIENT_ID, metadata: json, created_at: new Date(), updated_at: new Date() })
122
+ .onConflict((oc) => oc.column('client_id').doUpdateSet({ metadata: json, updated_at: new Date() }))
123
+ .execute();
124
+ }
125
+ /**
126
+ * The provider's `Client` adapter lookup: only the web client, only with the storefront enabled and at least
127
+ * one redirect URI. Every other client is static (or does not exist). Only the stored `redirect_uris` are read;
128
+ * the metadata is rebuilt from the fixed web spec, so a hand-edited row cannot change the client's auth method,
129
+ * scopes or grant types.
130
+ */
131
+ async findAdapterClient(id) {
132
+ if (!this.cfg.storefront.enabled || id !== constants_1.STOREFRONT_WEB_CLIENT_ID)
133
+ return undefined;
134
+ const row = await this.db
135
+ .selectFrom('auth_oauth_clients')
136
+ .select('metadata')
137
+ .where('client_id', '=', constants_1.STOREFRONT_WEB_CLIENT_ID)
138
+ .executeTakeFirst();
139
+ const stored = (typeof row?.metadata === 'string' ? JSON.parse(row.metadata) : row?.metadata);
140
+ const uris = Array.isArray(stored?.redirect_uris)
141
+ ? [...new Set(stored.redirect_uris.filter((u) => typeof u === 'string'))]
142
+ : [];
143
+ if (uris.length === 0)
144
+ return undefined;
145
+ return (0, clients_1.clientMetadata)((0, clients_1.webClientSpec)(this.cfg, uris));
146
+ }
147
+ /** Redirect URIs of the admin-managed origins allowed for the customer API (goal 14). */
148
+ async webRedirectUrisFromCors() {
149
+ const rows = await this.db
150
+ .selectFrom('auth_cors_origins')
151
+ .select('redirect_uris')
152
+ .where('allow_customer', '=', true)
153
+ .orderBy('origin')
154
+ .execute();
155
+ return rows.flatMap((r) => r.redirect_uris ?? []);
156
+ }
157
+ /**
158
+ * Destroys every Grant of `userId` except `opts.exceptGrantId` (the current BFF session's, on an own
159
+ * password change), all codes/tokens issued under them, and the user's provider Sessions. Uses
160
+ * OAUTH2_DB directly (never a caller's transaction) so it also works before the Provider exists.
161
+ */
162
+ async revokeAllGrants(userId, opts = {}) {
163
+ let q = this.db
164
+ .selectFrom('auth_oidc_payloads')
165
+ .select('id')
166
+ .where('kind', '=', 'Grant')
167
+ .where((0, kysely_1.sql) `payload->>'accountId'`, '=', userId);
168
+ if (opts.exceptGrantId)
169
+ q = q.where('id', '<>', opts.exceptGrantId);
170
+ for (const { id } of await q.execute()) {
171
+ await new this.adapter('Grant').revokeByGrantId(id);
172
+ await new this.adapter('Grant').destroy(id);
173
+ }
174
+ await this.destroyProviderSessions(userId);
175
+ }
176
+ /**
177
+ * C1: the provider `_session` must not outlive the BFF session (logout, idle/absolute expiry, user no
178
+ * longer active). The BFF always sends prompt=login, so provider Sessions only matter during an
179
+ * interaction; destroying all of the user's is safe.
180
+ */
181
+ async destroyProviderSessions(userId) {
182
+ await this.db
183
+ .deleteFrom('auth_oidc_payloads')
184
+ .where('kind', '=', 'Session')
185
+ .where((0, kysely_1.sql) `payload->>'accountId'`, '=', userId)
186
+ .execute();
187
+ }
188
+ };
189
+ exports.ProviderService = ProviderService;
190
+ exports.ProviderService = ProviderService = __decorate([
191
+ (0, common_1.Injectable)(),
192
+ __param(0, (0, common_1.Inject)(constants_1.OAUTH2_DB)),
193
+ __param(1, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
194
+ __param(2, (0, common_1.Inject)(constants_1.AUTH_SETTINGS)),
195
+ __param(3, (0, common_1.Inject)(core_1.HttpAdapterHost)),
196
+ __param(4, (0, common_1.Inject)(core_1.ModuleRef)),
197
+ __metadata("design:paramtypes", [Function, Object, Object, core_1.HttpAdapterHost,
198
+ core_1.ModuleRef])
199
+ ], ProviderService);
200
+ //# sourceMappingURL=provider.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.service.js","sourceRoot":"","sources":["../../src/provider/provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+E;AAC/E,uCAA0D;AAC1D,mCAA4D;AAC5D,gDAA0F;AAE1F,4CAEsB;AACtB,wDAAyD;AACzD,oEAAgE;AAEhE,+CAA+C;AAE/C,kEAA8D;AAC9D,wDAAuE;AACvE,qDAAqG;AACrG,yDAQ4B;AAC5B,iDAAkD;AAG3C,IAAM,eAAe,GAArB,MAAM,eAAe;IAMY;IACI;IACA;IACE;IAEN;IAVrB,MAAM,GAAG,IAAI,eAAM,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,CAAqB;IACrC,QAAQ,CAAgB;IAEhC,YACsC,EAAsB,EAClB,GAAiB,EACjB,QAA8B,EAC5B,WAA4B,EAElC,SAAoB;QALpB,OAAE,GAAF,EAAE,CAAoB;QAClB,QAAG,GAAH,GAAG,CAAc;QACjB,aAAQ,GAAR,QAAQ,CAAsB;QAC5B,gBAAW,GAAX,WAAW,CAAiB;QAElC,cAAS,GAAT,SAAS,CAAW;QAExD,IAAI,CAAC,OAAO,GAAG,IAAA,oCAAmB,EAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,QAAQ;QACV,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAY,sBAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,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AC;IAED;;;;OAIG;IACH,KAAK,CAAC,uBAAuB,CAAC,MAAc;QAC1C,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,oBAAoB,CAAC;aAChC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC;aAC7B,KAAK,CAAC,IAAA,YAAG,EAAQ,uBAAuB,EAAE,GAAG,EAAE,MAAM,CAAC;aACtD,OAAO,EAAE,CAAC;IACf,CAAC;CACF,CAAA;AAjKY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,qBAAS,CAAC,CAAA;IACjB,WAAA,IAAA,eAAM,EAAC,yBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,yBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,sBAAe,CAAC,CAAA;IAEvB,WAAA,IAAA,eAAM,EAAC,gBAAS,CAAC,CAAA;+DAFqC,sBAAe;QAEvB,gBAAS;GAX/C,eAAe,CAiK3B"}
@@ -0,0 +1,19 @@
1
+ import type { Kysely } from 'kysely';
2
+ import type { AuthTables } from '../db/types';
3
+ /** Private EC JWK as stored (sealed) in auth_signing_keys and handed to oidc-provider's `jwks`. */
4
+ export type JWK = {
5
+ kty: string;
6
+ crv?: string;
7
+ x?: string;
8
+ y?: string;
9
+ d?: string;
10
+ kid: string;
11
+ alg: string;
12
+ use?: string;
13
+ [k: string]: unknown;
14
+ };
15
+ /**
16
+ * Spec §6.1 step 2. Returns all non-retired private JWKs (decrypted with `key`); generates, seals and
17
+ * stores one ES256 key when none is active.
18
+ */
19
+ export declare function ensureSigningKey(db: Kysely<AuthTables>, key: Buffer): Promise<JWK[]>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureSigningKey = ensureSigningKey;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const errors_1 = require("../errors");
6
+ const crypto_1 = require("../security/crypto");
7
+ function generateEs256() {
8
+ const { privateKey } = (0, node_crypto_1.generateKeyPairSync)('ec', { namedCurve: 'P-256' });
9
+ const jwk = privateKey.export({ format: 'jwk' });
10
+ return { ...jwk, kty: jwk.kty, kid: (0, node_crypto_1.randomBytes)(16).toString('base64url'), alg: 'ES256', use: 'sig' };
11
+ }
12
+ /**
13
+ * Spec §6.1 step 2. Returns all non-retired private JWKs (decrypted with `key`); generates, seals and
14
+ * stores one ES256 key when none is active.
15
+ */
16
+ async function ensureSigningKey(db, key) {
17
+ const load = async () => db
18
+ .selectFrom('auth_signing_keys')
19
+ .select(['kid', 'jwk_private_enc'])
20
+ .where('retired_at', 'is', null)
21
+ .orderBy('created_at', 'desc')
22
+ .execute();
23
+ let rows = await load();
24
+ if (rows.length === 0) {
25
+ const jwk = generateEs256();
26
+ await db
27
+ .insertInto('auth_signing_keys')
28
+ .values({ kid: jwk.kid, jwk_private_enc: (0, crypto_1.seal)(key, JSON.stringify(jwk)), alg: 'ES256', created_at: new Date() })
29
+ .execute();
30
+ rows = await load();
31
+ }
32
+ try {
33
+ return rows.map((r) => JSON.parse((0, crypto_1.open)(key, r.jwk_private_enc)));
34
+ }
35
+ catch {
36
+ throw new errors_1.ConfigError('The signing keys stored in auth_signing_keys were encrypted with a different OPENCLOUDCMS_SECRET. ' +
37
+ 'Restore the previous OPENCLOUDCMS_SECRET, or delete the rows in auth_signing_keys and auth_sessions ' +
38
+ '(a new key is generated at startup; all users are signed out).');
39
+ }
40
+ }
41
+ //# sourceMappingURL=signing-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing-keys.js","sourceRoot":"","sources":["../../src/provider/signing-keys.ts"],"names":[],"mappings":";;AA6BA,4CA2BC;AAxDD,6CAA+D;AAG/D,sCAAwC;AACxC,+CAAgD;AAehD,SAAS,aAAa;IACpB,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iCAAmB,EAAC,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,EA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AAI,CAAC,KAAK,CAAC,IAAA,aAAI,EAAC,GAAG,EAAE,CAAC,CAAC,eAAe,CAAC,CAAQ,CAAC,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,oBAAW,CACnB,oGAAoG;YAClG,sGAAsG;YACtG,gEAAgE,CACnE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Side-effect only, Nest-free: makes `coreMigrator()` (e.g. in the `opencloudcms` CLI) aware of the oauth2 tables.
4
+ const db_1 = require("@opencloudcms/db");
5
+ const migrations_1 = require("./db/migrations");
6
+ (0, db_1.registerCoreMigrations)(migrations_1.oauth2CoreMigrations);
7
+ //# sourceMappingURL=register-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-migrations.js","sourceRoot":"","sources":["../src/register-migrations.ts"],"names":[],"mappings":";;AAAA,mHAAmH;AACnH,yCAA0D;AAC1D,gDAAuD;AAEvD,IAAA,2BAAsB,EAAC,iCAAoB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export type KeyPurpose = 'token' | 'key' | 'cookie' | 'client-secret' | 'client-secret-storefront' | 'otp';
2
+ export declare function deriveKey(secret: Buffer, purpose: KeyPurpose): Buffer;
3
+ /** base64url of iv(12) | tag(16) | ciphertext. */
4
+ export declare function seal(key: Buffer, plaintext: string): string;
5
+ export declare function open(key: Buffer, sealed: string): string;
6
+ export declare function sha256(s: string): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveKey = deriveKey;
4
+ exports.seal = seal;
5
+ exports.open = open;
6
+ exports.sha256 = sha256;
7
+ const node_crypto_1 = require("node:crypto");
8
+ function deriveKey(secret, purpose) {
9
+ return Buffer.from((0, node_crypto_1.hkdfSync)('sha256', secret, Buffer.alloc(0), `opencloudcms/${purpose}`, 32));
10
+ }
11
+ /** base64url of iv(12) | tag(16) | ciphertext. */
12
+ function seal(key, plaintext) {
13
+ const iv = (0, node_crypto_1.randomBytes)(12);
14
+ const cipher = (0, node_crypto_1.createCipheriv)('aes-256-gcm', key, iv);
15
+ const ct = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
16
+ return Buffer.concat([iv, cipher.getAuthTag(), ct]).toString('base64url');
17
+ }
18
+ function open(key, sealed) {
19
+ const buf = Buffer.from(sealed, 'base64url');
20
+ if (buf.length < 28)
21
+ throw new Error('invalid sealed data');
22
+ const decipher = (0, node_crypto_1.createDecipheriv)('aes-256-gcm', key, buf.subarray(0, 12));
23
+ decipher.setAuthTag(buf.subarray(12, 28));
24
+ return Buffer.concat([decipher.update(buf.subarray(28)), decipher.final()]).toString('utf8');
25
+ }
26
+ function sha256(s) {
27
+ return (0, node_crypto_1.createHash)('sha256').update(s).digest('hex');
28
+ }
29
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/security/crypto.ts"],"names":[],"mappings":";;AAIA,8BAEC;AAGD,oBAKC;AAED,oBAMC;AAED,wBAEC;AA1BD,6CAAkG;AAIlG,SAAgB,SAAS,CAAC,MAAc,EAAE,OAAmB;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAA,sBAAQ,EAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,gBAAgB,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,kDAAkD;AAClD,SAAgB,IAAI,CAAC,GAAW,EAAE,SAAiB;IACjD,MAAM,EAAE,GAAG,IAAA,yBAAW,EAAC,EAAE,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,IAAA,4BAAc,EAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED,SAAgB,IAAI,CAAC,GAAW,EAAE,MAAc;IAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7C,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,IAAA,8BAAgB,EAAC,aAAa,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC/F,CAAC;AAED,SAAgB,MAAM,CAAC,CAAS;IAC9B,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function normalizeEmail(s: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeEmail = normalizeEmail;
4
+ function normalizeEmail(s) {
5
+ return s.trim().toLowerCase();
6
+ }
7
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/security/email.ts"],"names":[],"mappings":";;AAAA,wCAEC;AAFD,SAAgB,cAAc,CAAC,CAAS;IACtC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function assertSameOrigin(originHeader: string | undefined, publicUrl: string): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertSameOrigin = assertSameOrigin;
4
+ const errors_1 = require("../errors");
5
+ function assertSameOrigin(originHeader, publicUrl) {
6
+ try {
7
+ if (originHeader && new URL(originHeader).origin === new URL(publicUrl).origin)
8
+ return;
9
+ }
10
+ catch {
11
+ /* fall through */
12
+ }
13
+ throw new errors_1.AuthError('origin_mismatch', 403, 'Origin not allowed');
14
+ }
15
+ //# sourceMappingURL=origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/security/origin.ts"],"names":[],"mappings":";;AAEA,4CAOC;AATD,sCAAsC;AAEtC,SAAgB,gBAAgB,CAAC,YAAgC,EAAE,SAAiB;IAClF,IAAI,CAAC;QACH,IAAI,YAAY,IAAI,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM;YAAE,OAAO;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;IACD,MAAM,IAAI,kBAAS,CAAC,iBAAiB,EAAE,GAAG,EAAE,oBAAoB,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare class PasswordService {
2
+ private readonly opts;
3
+ private dummyHash?;
4
+ constructor(opts: {
5
+ minLength: number;
6
+ });
7
+ validate(password: string, email: string): void;
8
+ hash(p: string): Promise<string>;
9
+ verify(hash: string, p: string): Promise<boolean>;
10
+ /** Burns comparable time against a cached hash when the account does not exist. */
11
+ verifyDummy(p: string): Promise<false>;
12
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.PasswordService = void 0;
46
+ const common_1 = require("@nestjs/common");
47
+ const argon2 = __importStar(require("argon2"));
48
+ const errors_1 = require("../errors");
49
+ const email_1 = require("./email");
50
+ const MAX_LENGTH = 256;
51
+ let PasswordService = class PasswordService {
52
+ opts;
53
+ dummyHash;
54
+ constructor(opts) {
55
+ this.opts = opts;
56
+ }
57
+ validate(password, email) {
58
+ const len = [...password].length;
59
+ if (len < this.opts.minLength) {
60
+ throw new errors_1.AuthError('weak_password', 422, `Password must be at least ${this.opts.minLength} characters`);
61
+ }
62
+ if (len > MAX_LENGTH) {
63
+ throw new errors_1.AuthError('weak_password', 422, `Password must be at most ${MAX_LENGTH} characters`);
64
+ }
65
+ if (password.toLowerCase() === (0, email_1.normalizeEmail)(email)) {
66
+ throw new errors_1.AuthError('weak_password', 422, 'Password must not equal the email');
67
+ }
68
+ }
69
+ hash(p) {
70
+ return argon2.hash(p, { type: argon2.argon2id });
71
+ }
72
+ async verify(hash, p) {
73
+ try {
74
+ return await argon2.verify(hash, p);
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ }
80
+ /** Burns comparable time against a cached hash when the account does not exist. */
81
+ async verifyDummy(p) {
82
+ this.dummyHash ??= this.hash('opencloudcms-dummy-password');
83
+ await this.verify(await this.dummyHash, p);
84
+ return false;
85
+ }
86
+ };
87
+ exports.PasswordService = PasswordService;
88
+ exports.PasswordService = PasswordService = __decorate([
89
+ (0, common_1.Injectable)(),
90
+ __metadata("design:paramtypes", [Object])
91
+ ], PasswordService);
92
+ //# sourceMappingURL=password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password.js","sourceRoot":"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AAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,mFAAmF;IACnF,KAAK,CAAC,WAAW,CAAC,CAAS;QACzB,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC5D,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AApCY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;;GACA,eAAe,CAoC3B"}
@@ -0,0 +1,25 @@
1
+ export interface RateLimiter {
2
+ hit(key: string, limit: number, windowSec: number): {
3
+ ok: boolean;
4
+ retryAfterSec: number;
5
+ };
6
+ }
7
+ /** Upper bound on tracked keys; beyond it the oldest insertion is dropped (M4: bounded memory). */
8
+ export declare const RATE_LIMITER_MAX_KEYS = 10000;
9
+ export declare class InMemoryRateLimiter implements RateLimiter {
10
+ private readonly windows;
11
+ private readonly maxKeys;
12
+ private lastPrune;
13
+ constructor(opts?: {
14
+ maxKeys?: number;
15
+ });
16
+ /** Number of tracked keys. */
17
+ get size(): number;
18
+ hit(key: string, limit: number, windowSec: number): {
19
+ ok: boolean;
20
+ retryAfterSec: number;
21
+ };
22
+ /** (Re)inserts at the end of the Map's insertion order, evicting the oldest entries when full. */
23
+ private insert;
24
+ private prune;
25
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryRateLimiter = exports.RATE_LIMITER_MAX_KEYS = void 0;
4
+ /** Upper bound on tracked keys; beyond it the oldest insertion is dropped (M4: bounded memory). */
5
+ exports.RATE_LIMITER_MAX_KEYS = 10_000;
6
+ class InMemoryRateLimiter {
7
+ windows = new Map();
8
+ maxKeys;
9
+ lastPrune = 0;
10
+ constructor(opts = {}) {
11
+ this.maxKeys = opts.maxKeys ?? exports.RATE_LIMITER_MAX_KEYS;
12
+ }
13
+ /** Number of tracked keys. */
14
+ get size() {
15
+ return this.windows.size;
16
+ }
17
+ hit(key, limit, windowSec) {
18
+ const now = Date.now();
19
+ this.prune(now);
20
+ let w = this.windows.get(key);
21
+ if (!w || w.resetAt <= now) {
22
+ w = { count: 0, resetAt: now + windowSec * 1000 };
23
+ this.insert(key, w);
24
+ }
25
+ if (w.count >= limit) {
26
+ return { ok: false, retryAfterSec: Math.max(1, Math.ceil((w.resetAt - now) / 1000)) };
27
+ }
28
+ w.count++;
29
+ return { ok: true, retryAfterSec: 0 };
30
+ }
31
+ /** (Re)inserts at the end of the Map's insertion order, evicting the oldest entries when full. */
32
+ insert(key, w) {
33
+ this.windows.delete(key);
34
+ while (this.windows.size >= this.maxKeys) {
35
+ const oldest = this.windows.keys().next().value;
36
+ if (oldest === undefined)
37
+ break;
38
+ this.windows.delete(oldest);
39
+ }
40
+ this.windows.set(key, w);
41
+ }
42
+ prune(now) {
43
+ if (now - this.lastPrune < 60_000)
44
+ return;
45
+ this.lastPrune = now;
46
+ for (const [k, w] of this.windows)
47
+ if (w.resetAt <= now)
48
+ this.windows.delete(k);
49
+ }
50
+ }
51
+ exports.InMemoryRateLimiter = InMemoryRateLimiter;
52
+ //# sourceMappingURL=rate-limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/security/rate-limiter.ts"],"names":[],"mappings":";;;AAIA,mGAAmG;AACtF,QAAA,qBAAqB,GAAG,MAAM,CAAC;AAE5C,MAAa,mBAAmB;IACb,OAAO,GAAG,IAAI,GAAG,EAA8C,CAAC;IAChE,OAAO,CAAS;IACzB,SAAS,GAAG,CAAC,CAAC;IAEtB,YAAY,OAA6B,EAAE;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,6BAAqB,CAAC;IACvD,CAAC;IAED,8BAA8B;IAC9B,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO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AC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,GAAW;QACvB,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,GAAG,MAAM;YAAE,OAAO;QAC1C,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;QACrB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,CAAC,OAAO,IAAI,GAAG;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;CACF;AA7CD,kDA6CC"}
@@ -0,0 +1,6 @@
1
+ export declare function sanitizeReturnTo(v: string | undefined): string;
2
+ /**
3
+ * Where the customer BFF may send the browser after sign-in: a local absolute path on this origin (no scheme,
4
+ * no `//` or `\\` that a browser would read as another host, no control characters); anything else → `/`.
5
+ */
6
+ export declare function sanitizeCustomerReturnTo(v: string | undefined): string;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeReturnTo = sanitizeReturnTo;
4
+ exports.sanitizeCustomerReturnTo = sanitizeCustomerReturnTo;
5
+ const DEFAULT = '/admin';
6
+ function sanitizeReturnTo(v) {
7
+ if (typeof v !== 'string' || !v.startsWith('/admin'))
8
+ return DEFAULT;
9
+ const next = v.charAt('/admin'.length);
10
+ if (next !== '' && next !== '/' && next !== '?' && next !== '#')
11
+ return DEFAULT;
12
+ if (v.includes('\\') || v.includes('//'))
13
+ return DEFAULT;
14
+ // eslint-disable-next-line no-control-regex
15
+ if (/[\u0000-\u001f\u007f]/.test(v))
16
+ return DEFAULT;
17
+ return v;
18
+ }
19
+ /**
20
+ * Where the customer BFF may send the browser after sign-in: a local absolute path on this origin (no scheme,
21
+ * no `//` or `\\` that a browser would read as another host, no control characters); anything else → `/`.
22
+ */
23
+ function sanitizeCustomerReturnTo(v) {
24
+ if (typeof v !== 'string' || !v.startsWith('/'))
25
+ return '/';
26
+ if (v.includes('\\') || v.includes('//'))
27
+ return '/';
28
+ // eslint-disable-next-line no-control-regex
29
+ if (/[\u0000-\u001f\u007f]/.test(v))
30
+ return '/';
31
+ return v;
32
+ }
33
+ //# sourceMappingURL=return-to.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"return-to.js","sourceRoot":"","sources":["../../src/security/return-to.ts"],"names":[],"mappings":";;AAEA,4CAQC;AAMD,4DAMC;AAtBD,MAAM,OAAO,GAAG,QAAQ,CAAC;AAEzB,SAAgB,gBAAgB,CAAC,CAAqB;IACpD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAC;IACrE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,OAAO,CAAC;IAChF,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC;IACzD,4CAA4C;IAC5C,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACpD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,CAAqB;IAC5D,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC5D,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC;IACrD,4CAA4C;IAC5C,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IAChD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ZodType } from 'zod';
2
+ /** Validates a request body with zod; failure -> `422 validation_failed` with a short `path: message` list. */
3
+ export declare function parseBody<T>(schema: ZodType<T, any, any>, body: unknown): T;