@getstrata/core 2.2.55 → 2.2.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 2.2.57
4
+
5
+ Add opt-in CsrfOptions.targetOrigin with strict request Host/URL authority and source-origin validation while retaining signed cookie/token checks and existing defaults. Preserve native Request identity and ignore forwarding claims. Fall back safely to JSON error formatting for malformed native URL metadata.
6
+
7
+ ## 2.2.56
8
+
9
+ - Stop adding schema CREATE to PostgreSQL runtime roles; keep USAGE, existing object/default grants and both catalog/ACL concurrency protocols. Existing grants, PUBLIC privileges, memberships and ownership are not revoked automatically; restricted deployments can use the documented public schema-only migration runner.
10
+ - Require Bun >=1.4.4 and retain the native SQL timer regression matrix. Preserve ORM/transaction behavior while removing two redundant private guards; strengthen error, empty-data and adapter-metadata coverage without changing public or protected APIs.
11
+
3
12
  ## 2.2.55
4
13
 
5
14
  - Align the lockstep version with the starter startup-cleanup correction. Core runtime, ORM, lifecycle policy and public/protected APIs are unchanged.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @getstrata/core
2
2
 
3
- Runtime library for [Strata](https://github.com/EyK-26/strata) apps: HTTP, auth, database, queue, mail, and security. Requires Bun >=1.4.3 (tested on 1.4.3).
3
+ Runtime library for [Strata](https://github.com/EyK-26/strata) apps: HTTP, auth, database, queue, mail, and security. Requires Bun >=1.4.4 (tested on 1.4.4).
4
4
 
5
5
  Generate an app rather than wiring this by hand:
6
6
 
@@ -1,3 +1,8 @@
1
1
  import type { Middleware } from "./middleware";
2
- declare function createCsrfMiddleware(): Middleware;
2
+ interface CsrfOptions {
3
+ /** Explicit public origin for TLS offload; requires matching URL authority and Host on every request. */
4
+ targetOrigin?: string;
5
+ }
6
+ declare function createCsrfMiddleware(options?: CsrfOptions): Middleware;
7
+ export type { CsrfOptions };
3
8
  export { createCsrfMiddleware };
@@ -0,0 +1,6 @@
1
+ /** Explicit target policy only. Forwarding headers never select an origin or approve a host. */
2
+ declare function createCsrfOriginPolicy(value: unknown): {
3
+ acceptsSourceOrigin(source: string | null): boolean;
4
+ assertHost(request: Request): void;
5
+ };
6
+ export { createCsrfOriginPolicy };
@@ -138,12 +138,7 @@ function requestTransactionRollback() {
138
138
  if (!state || index < 0) {
139
139
  return;
140
140
  }
141
- const flags = state.rollback;
142
- const current = flags[index];
143
- if (current === undefined) {
144
- return;
145
- }
146
- flags[index] = true;
141
+ state.rollback[index] = true;
147
142
  }
148
143
  function scopeRequestsRollback() {
149
144
  const state = transactionScopes.getStore();
@@ -195,12 +195,7 @@ function requestTransactionRollback() {
195
195
  if (!state || index < 0) {
196
196
  return;
197
197
  }
198
- const flags = state.rollback;
199
- const current = flags[index];
200
- if (current === undefined) {
201
- return;
202
- }
203
- flags[index] = true;
198
+ state.rollback[index] = true;
204
199
  }
205
200
  function scopeRequestsRollback() {
206
201
  const state = transactionScopes.getStore();
@@ -339,12 +339,7 @@ function requestTransactionRollback() {
339
339
  if (!state || index < 0) {
340
340
  return;
341
341
  }
342
- const flags = state.rollback;
343
- const current = flags[index];
344
- if (current === undefined) {
345
- return;
346
- }
347
- flags[index] = true;
342
+ state.rollback[index] = true;
348
343
  }
349
344
  function scopeRequestsRollback() {
350
345
  const state = transactionScopes.getStore();
@@ -339,12 +339,7 @@ function requestTransactionRollback() {
339
339
  if (!state || index < 0) {
340
340
  return;
341
341
  }
342
- const flags = state.rollback;
343
- const current = flags[index];
344
- if (current === undefined) {
345
- return;
346
- }
347
- flags[index] = true;
342
+ state.rollback[index] = true;
348
343
  }
349
344
  function scopeRequestsRollback() {
350
345
  const state = transactionScopes.getStore();
@@ -138,12 +138,7 @@ function requestTransactionRollback() {
138
138
  if (!state || index < 0) {
139
139
  return;
140
140
  }
141
- const flags = state.rollback;
142
- const current = flags[index];
143
- if (current === undefined) {
144
- return;
145
- }
146
- flags[index] = true;
141
+ state.rollback[index] = true;
147
142
  }
148
143
  function scopeRequestsRollback() {
149
144
  const state = transactionScopes.getStore();
@@ -4,10 +4,15 @@ function requestPrefersJson(request) {
4
4
  if (!request) {
5
5
  return true;
6
6
  }
7
+ let pathname;
8
+ try {
9
+ pathname = new URL(request.url).pathname;
10
+ } catch {
11
+ return true;
12
+ }
7
13
  if (request.headers.get("HX-Request") === "true") {
8
14
  return false;
9
15
  }
10
- const pathname = new URL(request.url).pathname;
11
16
  if (pathname.startsWith("/api/")) {
12
17
  return true;
13
18
  }
@@ -28,9 +28,58 @@ var init_asyncContextStore = () => {};
28
28
 
29
29
  // ../../src/core/http/csrfMiddleware.ts
30
30
  import { currentAuthUser, currentCredentialSource } from "@getstrata/core/auth/authContext";
31
- import { ForbiddenError } from "@getstrata/core/errors/http";
31
+ import { ForbiddenError as ForbiddenError2 } from "@getstrata/core/errors/http";
32
32
  import { envFlagEnabled as envFlagEnabled2, isProductionEnv as isProductionEnv2 } from "@getstrata/core/runtime/appEnv";
33
33
 
34
+ // ../../src/core/http/csrfOriginPolicy.ts
35
+ import { isIP } from "net";
36
+ import { ForbiddenError } from "@getstrata/core/errors/http";
37
+ function parseAuthority(authority, protocol) {
38
+ if (!authority || authority.endsWith(":") || /[\s\\/@?#%,*]/.test(authority))
39
+ return null;
40
+ try {
41
+ const url = new URL(`${protocol}//${authority}`);
42
+ const hostname = url.hostname.replace(/\.$/, "");
43
+ const ip = hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
44
+ if (!isIP(ip) && (hostname.length > 253 || !hostname.split(".").every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label))))
45
+ return null;
46
+ return url.host;
47
+ } catch {
48
+ return null;
49
+ }
50
+ }
51
+ function parseOrigin(value, allowRootPath) {
52
+ if (typeof value !== "string" || value !== value.trim())
53
+ return null;
54
+ const match = /^(https?):\/\/([^/?#]+)(\/?)$/i.exec(value);
55
+ if (!match || !allowRootPath && match[3])
56
+ return null;
57
+ const protocol = `${match[1]?.toLowerCase()}:`;
58
+ const host = parseAuthority(match[2] ?? null, protocol);
59
+ return host ? `${protocol}//${host}` : null;
60
+ }
61
+ function createCsrfOriginPolicy(value) {
62
+ const origin = parseOrigin(value, true);
63
+ if (!origin)
64
+ throw new TypeError("CSRF targetOrigin must be a single HTTP(S) origin without credentials, path, query, fragment or wildcard.");
65
+ const target = new URL(origin);
66
+ return {
67
+ acceptsSourceOrigin(source) {
68
+ return parseOrigin(source, false) === origin;
69
+ },
70
+ assertHost(request) {
71
+ let url;
72
+ try {
73
+ url = new URL(request.url);
74
+ } catch {
75
+ throw new ForbiddenError("Unrecognized request host.");
76
+ }
77
+ if (!/^https?:$/.test(url.protocol) || url.username || url.password || parseAuthority(url.host, target.protocol) !== target.host || parseAuthority(request.headers.get("host"), target.protocol) !== target.host)
78
+ throw new ForbiddenError("Unrecognized request host.");
79
+ }
80
+ };
81
+ }
82
+
34
83
  // ../../src/core/http/csrfToken.ts
35
84
  import { timingSafeEqual } from "crypto";
36
85
 
@@ -272,8 +321,11 @@ function appendSetCookie(response, cookie) {
272
321
  headers
273
322
  });
274
323
  }
275
- function createCsrfMiddleware() {
324
+ function createCsrfMiddleware(options = {}) {
325
+ const targetOrigin = options.targetOrigin;
326
+ const policy = targetOrigin === undefined ? undefined : createCsrfOriginPolicy(targetOrigin);
276
327
  return async (request, next) => {
328
+ policy?.assertHost(request);
277
329
  const credentialSource = currentCredentialSource();
278
330
  const developmentHeaderProof = credentialSource === "guest" && currentAuthUser() !== null && envFlagEnabled2(process.env.AUTH_DEV_HEADERS) && !isProductionEnv2();
279
331
  if (credentialSource === "bearer" || credentialSource === "basic" || developmentHeaderProof) {
@@ -296,19 +348,19 @@ function createCsrfMiddleware() {
296
348
  }
297
349
  const submitted = await readSubmittedCsrfTokenFromBody(request);
298
350
  if (!verifyCsrfToken(request, submitted)) {
299
- throw new ForbiddenError("Invalid or missing CSRF token.");
351
+ throw new ForbiddenError2("Invalid or missing CSRF token.");
300
352
  }
301
353
  const originHeader = request.headers.get("origin");
302
354
  let headerOrigin = null;
303
- if (originHeader) {
355
+ if (!policy && originHeader) {
304
356
  try {
305
357
  headerOrigin = new URL(originHeader).origin;
306
358
  } catch {
307
359
  headerOrigin = null;
308
360
  }
309
361
  }
310
- if (!headerOrigin || headerOrigin !== new URL(request.url).origin) {
311
- throw new ForbiddenError("Cross-site cookie requests are not allowed.");
362
+ if (policy ? !policy.acceptsSourceOrigin(originHeader) : !headerOrigin || headerOrigin !== new URL(request.url).origin) {
363
+ throw new ForbiddenError2("Cross-site cookie requests are not allowed.");
312
364
  }
313
365
  return await next();
314
366
  };
@@ -419,10 +419,15 @@ function requestPrefersJson(request) {
419
419
  if (!request) {
420
420
  return true;
421
421
  }
422
+ let pathname;
423
+ try {
424
+ pathname = new URL(request.url).pathname;
425
+ } catch {
426
+ return true;
427
+ }
422
428
  if (request.headers.get("HX-Request") === "true") {
423
429
  return false;
424
430
  }
425
- const pathname = new URL(request.url).pathname;
426
431
  if (pathname.startsWith("/api/")) {
427
432
  return true;
428
433
  }
@@ -54,10 +54,15 @@ function requestPrefersJson(request) {
54
54
  if (!request) {
55
55
  return true;
56
56
  }
57
+ let pathname;
58
+ try {
59
+ pathname = new URL(request.url).pathname;
60
+ } catch {
61
+ return true;
62
+ }
57
63
  if (request.headers.get("HX-Request") === "true") {
58
64
  return false;
59
65
  }
60
- const pathname = new URL(request.url).pathname;
61
66
  if (pathname.startsWith("/api/")) {
62
67
  return true;
63
68
  }
@@ -38,10 +38,15 @@ function requestPrefersJson(request) {
38
38
  if (!request) {
39
39
  return true;
40
40
  }
41
+ let pathname;
42
+ try {
43
+ pathname = new URL(request.url).pathname;
44
+ } catch {
45
+ return true;
46
+ }
41
47
  if (request.headers.get("HX-Request") === "true") {
42
48
  return false;
43
49
  }
44
- const pathname = new URL(request.url).pathname;
45
50
  if (pathname.startsWith("/api/")) {
46
51
  return true;
47
52
  }
@@ -14,10 +14,15 @@ function requestPrefersJson(request) {
14
14
  if (!request) {
15
15
  return true;
16
16
  }
17
+ let pathname;
18
+ try {
19
+ pathname = new URL(request.url).pathname;
20
+ } catch {
21
+ return true;
22
+ }
17
23
  if (request.headers.get("HX-Request") === "true") {
18
24
  return false;
19
25
  }
20
- const pathname = new URL(request.url).pathname;
21
26
  if (pathname.startsWith("/api/")) {
22
27
  return true;
23
28
  }
@@ -9,10 +9,15 @@ function requestPrefersJson(request) {
9
9
  if (!request) {
10
10
  return true;
11
11
  }
12
+ let pathname;
13
+ try {
14
+ pathname = new URL(request.url).pathname;
15
+ } catch {
16
+ return true;
17
+ }
12
18
  if (request.headers.get("HX-Request") === "true") {
13
19
  return false;
14
20
  }
15
- const pathname = new URL(request.url).pathname;
16
21
  if (pathname.startsWith("/api/")) {
17
22
  return true;
18
23
  }
@@ -61,12 +61,7 @@ function requestTransactionRollback() {
61
61
  if (!state || index < 0) {
62
62
  return;
63
63
  }
64
- const flags = state.rollback;
65
- const current = flags[index];
66
- if (current === undefined) {
67
- return;
68
- }
69
- flags[index] = true;
64
+ state.rollback[index] = true;
70
65
  }
71
66
  function scopeRequestsRollback() {
72
67
  const state = transactionScopes.getStore();
@@ -473,10 +473,15 @@ function requestPrefersJson(request) {
473
473
  if (!request) {
474
474
  return true;
475
475
  }
476
+ let pathname;
477
+ try {
478
+ pathname = new URL(request.url).pathname;
479
+ } catch {
480
+ return true;
481
+ }
476
482
  if (request.headers.get("HX-Request") === "true") {
477
483
  return false;
478
484
  }
479
- const pathname = new URL(request.url).pathname;
480
485
  if (pathname.startsWith("/api/")) {
481
486
  return true;
482
487
  }
@@ -358,10 +358,15 @@ function requestPrefersJson(request) {
358
358
  if (!request) {
359
359
  return true;
360
360
  }
361
+ let pathname;
362
+ try {
363
+ pathname = new URL(request.url).pathname;
364
+ } catch {
365
+ return true;
366
+ }
361
367
  if (request.headers.get("HX-Request") === "true") {
362
368
  return false;
363
369
  }
364
- const pathname = new URL(request.url).pathname;
365
370
  if (pathname.startsWith("/api/")) {
366
371
  return true;
367
372
  }
@@ -7,10 +7,15 @@ function requestPrefersJson(request) {
7
7
  if (!request) {
8
8
  return true;
9
9
  }
10
+ let pathname;
11
+ try {
12
+ pathname = new URL(request.url).pathname;
13
+ } catch {
14
+ return true;
15
+ }
10
16
  if (request.headers.get("HX-Request") === "true") {
11
17
  return false;
12
18
  }
13
- const pathname = new URL(request.url).pathname;
14
19
  if (pathname.startsWith("/api/")) {
15
20
  return true;
16
21
  }
@@ -138,12 +138,7 @@ function requestTransactionRollback() {
138
138
  if (!state || index < 0) {
139
139
  return;
140
140
  }
141
- const flags = state.rollback;
142
- const current = flags[index];
143
- if (current === undefined) {
144
- return;
145
- }
146
- flags[index] = true;
141
+ state.rollback[index] = true;
147
142
  }
148
143
  function scopeRequestsRollback() {
149
144
  const state = transactionScopes.getStore();
@@ -448,12 +448,7 @@ function requestTransactionRollback() {
448
448
  if (!state || index < 0) {
449
449
  return;
450
450
  }
451
- const flags = state.rollback;
452
- const current = flags[index];
453
- if (current === undefined) {
454
- return;
455
- }
456
- flags[index] = true;
451
+ state.rollback[index] = true;
457
452
  }
458
453
  function scopeRequestsRollback() {
459
454
  const state = transactionScopes.getStore();
@@ -138,12 +138,7 @@ function requestTransactionRollback() {
138
138
  if (!state || index < 0) {
139
139
  return;
140
140
  }
141
- const flags = state.rollback;
142
- const current = flags[index];
143
- if (current === undefined) {
144
- return;
145
- }
146
- flags[index] = true;
141
+ state.rollback[index] = true;
147
142
  }
148
143
  function scopeRequestsRollback() {
149
144
  const state = transactionScopes.getStore();
@@ -196,7 +196,7 @@ function postgresAppRolePrivilegeSql(options) {
196
196
  const database = assertSafeSqlIdentifier(options.database, "database name");
197
197
  const role = assertSafeSqlIdentifier(options.role ?? POSTGRES_APP_ROLE, "role name");
198
198
  return `GRANT CONNECT ON DATABASE ${database} TO ${role};
199
- GRANT USAGE, CREATE ON SCHEMA public TO ${role};
199
+ GRANT USAGE ON SCHEMA public TO ${role};
200
200
  GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ${role};
201
201
  GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO ${role};
202
202
  GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO ${role};
@@ -61,12 +61,7 @@ function requestTransactionRollback() {
61
61
  if (!state || index < 0) {
62
62
  return;
63
63
  }
64
- const flags = state.rollback;
65
- const current = flags[index];
66
- if (current === undefined) {
67
- return;
68
- }
69
- flags[index] = true;
64
+ state.rollback[index] = true;
70
65
  }
71
66
  function scopeRequestsRollback() {
72
67
  const state = transactionScopes.getStore();
@@ -87,7 +87,7 @@ export type { ContentSecurityPolicyDirectives, ContentSecurityPolicyOptions, } f
87
87
  export { configureContentSecurityPolicy, generateCspNonce, HTMX_2_0_4_INDICATOR_STYLE_HASH, resetContentSecurityPolicyForTests, resolveContentSecurityPolicy, resolveHtmlContentSecurityPolicy, serverHtmxContentSecurityPolicy, spaContentSecurityPolicy, strictApiContentSecurityPolicy, } from "../core/http/contentSecurityPolicy.ts";
88
88
  export { readBunRequestCookie, readRequestCookie } from "../core/http/cookies.ts";
89
89
  export { type CorsConfig, type CorsOptions, createCorsMiddleware, } from "../core/http/corsMiddleware.ts";
90
- export { createCsrfMiddleware } from "../core/http/csrfMiddleware.ts";
90
+ export { type CsrfOptions, createCsrfMiddleware } from "../core/http/csrfMiddleware.ts";
91
91
  export { createCsrfProtection } from "../core/http/csrfProtection.ts";
92
92
  export { createCsrfTokenCookie, readSubmittedCsrfToken, readSubmittedCsrfTokenFromBody, resolveCsrfToken, resolveCsrfTokenForRequest, verifyCsrfToken, } from "../core/http/csrfToken.ts";
93
93
  export { applyConditionalGet, assertIfMatch, computeEtagFromJson, type EtagVersioned, etagFromResource, etagValuesMatch, ifMatchSatisfied, ifNoneMatchSatisfied, isEtagEnabled, notModifiedResponse, } from "../core/http/etag.ts";
package/dist/index.js CHANGED
@@ -243,12 +243,7 @@ function requestTransactionRollback() {
243
243
  if (!state || index < 0) {
244
244
  return;
245
245
  }
246
- const flags = state.rollback;
247
- const current = flags[index];
248
- if (current === undefined) {
249
- return;
250
- }
251
- flags[index] = true;
246
+ state.rollback[index] = true;
252
247
  }
253
248
  function scopeRequestsRollback() {
254
249
  const state = transactionScopes.getStore();
@@ -8476,11 +8471,8 @@ async function eagerLoadOnModels(models, paths, knownAbsentMorphRoots = new Map)
8476
8471
  }
8477
8472
  await Promise.all([...grouped.entries()].map(async ([head, nested]) => {
8478
8473
  const unloaded = models.filter((model) => model.loaded(head) === undefined && !knownAbsentMorphRoots.get(model)?.has(head));
8479
- if (unloaded.length > 0) {
8480
- const first = unloaded[0];
8481
- if (!first) {
8482
- return;
8483
- }
8474
+ const first = unloaded[0];
8475
+ if (first) {
8484
8476
  const relationQuery = resolveModelRelation(first, head);
8485
8477
  const query = first.getRepository().query();
8486
8478
  relationQuery.applyEagerLoad(query, head);
@@ -12054,10 +12046,15 @@ function requestPrefersJson(request) {
12054
12046
  if (!request) {
12055
12047
  return true;
12056
12048
  }
12049
+ let pathname;
12050
+ try {
12051
+ pathname = new URL(request.url).pathname;
12052
+ } catch {
12053
+ return true;
12054
+ }
12057
12055
  if (request.headers.get("HX-Request") === "true") {
12058
12056
  return false;
12059
12057
  }
12060
- const pathname = new URL(request.url).pathname;
12061
12058
  if (pathname.startsWith("/api/")) {
12062
12059
  return true;
12063
12060
  }
@@ -12648,6 +12645,54 @@ function buildCorsHeaders(request, options) {
12648
12645
  }
12649
12646
  return headers;
12650
12647
  }
12648
+ // ../../src/core/http/csrfOriginPolicy.ts
12649
+ import { isIP } from "net";
12650
+ function parseAuthority(authority, protocol) {
12651
+ if (!authority || authority.endsWith(":") || /[\s\\/@?#%,*]/.test(authority))
12652
+ return null;
12653
+ try {
12654
+ const url = new URL(`${protocol}//${authority}`);
12655
+ const hostname = url.hostname.replace(/\.$/, "");
12656
+ const ip = hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
12657
+ if (!isIP(ip) && (hostname.length > 253 || !hostname.split(".").every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label))))
12658
+ return null;
12659
+ return url.host;
12660
+ } catch {
12661
+ return null;
12662
+ }
12663
+ }
12664
+ function parseOrigin(value, allowRootPath) {
12665
+ if (typeof value !== "string" || value !== value.trim())
12666
+ return null;
12667
+ const match = /^(https?):\/\/([^/?#]+)(\/?)$/i.exec(value);
12668
+ if (!match || !allowRootPath && match[3])
12669
+ return null;
12670
+ const protocol = `${match[1]?.toLowerCase()}:`;
12671
+ const host = parseAuthority(match[2] ?? null, protocol);
12672
+ return host ? `${protocol}//${host}` : null;
12673
+ }
12674
+ function createCsrfOriginPolicy(value) {
12675
+ const origin = parseOrigin(value, true);
12676
+ if (!origin)
12677
+ throw new TypeError("CSRF targetOrigin must be a single HTTP(S) origin without credentials, path, query, fragment or wildcard.");
12678
+ const target = new URL(origin);
12679
+ return {
12680
+ acceptsSourceOrigin(source) {
12681
+ return parseOrigin(source, false) === origin;
12682
+ },
12683
+ assertHost(request) {
12684
+ let url;
12685
+ try {
12686
+ url = new URL(request.url);
12687
+ } catch {
12688
+ throw new ForbiddenError("Unrecognized request host.");
12689
+ }
12690
+ if (!/^https?:$/.test(url.protocol) || url.username || url.password || parseAuthority(url.host, target.protocol) !== target.host || parseAuthority(request.headers.get("host"), target.protocol) !== target.host)
12691
+ throw new ForbiddenError("Unrecognized request host.");
12692
+ }
12693
+ };
12694
+ }
12695
+
12651
12696
  // ../../src/core/http/csrfToken.ts
12652
12697
  import { timingSafeEqual as timingSafeEqual3 } from "crypto";
12653
12698
  var CSRF_COOKIE = appCookieName("csrf");
@@ -12756,8 +12801,11 @@ function appendSetCookie(response, cookie) {
12756
12801
  headers
12757
12802
  });
12758
12803
  }
12759
- function createCsrfMiddleware() {
12804
+ function createCsrfMiddleware(options = {}) {
12805
+ const targetOrigin = options.targetOrigin;
12806
+ const policy = targetOrigin === undefined ? undefined : createCsrfOriginPolicy(targetOrigin);
12760
12807
  return async (request, next) => {
12808
+ policy?.assertHost(request);
12761
12809
  const credentialSource = currentCredentialSource();
12762
12810
  const developmentHeaderProof = credentialSource === "guest" && currentAuthUser() !== null && envFlagEnabled(process.env.AUTH_DEV_HEADERS) && !isProductionEnv();
12763
12811
  if (credentialSource === "bearer" || credentialSource === "basic" || developmentHeaderProof) {
@@ -12784,14 +12832,14 @@ function createCsrfMiddleware() {
12784
12832
  }
12785
12833
  const originHeader = request.headers.get("origin");
12786
12834
  let headerOrigin = null;
12787
- if (originHeader) {
12835
+ if (!policy && originHeader) {
12788
12836
  try {
12789
12837
  headerOrigin = new URL(originHeader).origin;
12790
12838
  } catch {
12791
12839
  headerOrigin = null;
12792
12840
  }
12793
12841
  }
12794
- if (!headerOrigin || headerOrigin !== new URL(request.url).origin) {
12842
+ if (policy ? !policy.acceptsSourceOrigin(originHeader) : !headerOrigin || headerOrigin !== new URL(request.url).origin) {
12795
12843
  throw new ForbiddenError("Cross-site cookie requests are not allowed.");
12796
12844
  }
12797
12845
  return await next();
@@ -16425,7 +16473,7 @@ import { createHash as createHash8 } from "crypto";
16425
16473
  init_databaseTenantContext();
16426
16474
 
16427
16475
  // ../../src/core/tenant/publicTenantHost.ts
16428
- import { BlockList, isIP } from "net";
16476
+ import { BlockList, isIP as isIP2 } from "net";
16429
16477
  function normalizeTenantHostname(authority) {
16430
16478
  if (!authority || authority !== authority.trim() || /[\s\\/@?#%,]/.test(authority)) {
16431
16479
  throw new ForbiddenError("Invalid tenant hostname.");
@@ -16438,7 +16486,7 @@ function normalizeTenantHostname(authority) {
16438
16486
  }
16439
16487
  const hostname = url.hostname.toLowerCase().replace(/\.$/, "");
16440
16488
  const ip = hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
16441
- if (!isIP(ip) && (hostname.length > 253 || !hostname.split(".").every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label)))) {
16489
+ if (!isIP2(ip) && (hostname.length > 253 || !hostname.split(".").every((label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label)))) {
16442
16490
  throw new ForbiddenError("Invalid tenant hostname.");
16443
16491
  }
16444
16492
  return hostname;
@@ -16449,14 +16497,14 @@ function createPublicTenantSelector(options) {
16449
16497
  throw new Error("Public tenancy supports at most 128 trusted proxy addresses.");
16450
16498
  const proxies = new BlockList;
16451
16499
  for (const address of addresses) {
16452
- const version = isIP(address);
16500
+ const version = isIP2(address);
16453
16501
  if (!version)
16454
16502
  throw new Error("Trusted proxy addresses must be literal IP addresses.");
16455
16503
  proxies.addAddress(address, version === 6 ? "ipv6" : "ipv4");
16456
16504
  }
16457
16505
  return async (request) => {
16458
16506
  const peer = currentRequestMeta().peerAddress;
16459
- const version = peer ? isIP(peer) : 0;
16507
+ const version = peer ? isIP2(peer) : 0;
16460
16508
  const trusted = peer && version && proxies.check(peer, version === 6 ? "ipv6" : "ipv4");
16461
16509
  const forwarded = trusted ? request.headers.get("x-forwarded-host") : null;
16462
16510
  const authority = forwarded ?? request.headers.get("host") ?? new URL(request.url).host;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "2.2.55",
3
+ "version": "2.2.57",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -982,7 +982,7 @@
982
982
  }
983
983
  },
984
984
  "engines": {
985
- "bun": ">=1.4.3"
985
+ "bun": ">=1.4.4"
986
986
  },
987
987
  "dependencies": {
988
988
  "@opentelemetry/api": "1.9.1",