@digilogiclabs/platform-core 1.17.1 → 1.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/auth.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as RateLimitStore, a as RateLimitRule, b as RateLimitOptions } from './env-BJWliXSO.mjs';
2
2
  export { al as AllowlistConfig, A as ApiError, d as ApiErrorCode, f as ApiErrorCodeType, h as ApiPaginatedResponse, Q as ApiSecurityConfig, V as ApiSecurityContext, g as ApiSuccessResponse, aD as AuditRequest, H as AuthCookiesConfig, N as AuthMethod, aL as BetaClientConfig, C as CommonApiErrors, ar as CommonRateLimits, ac as DateRangeInput, a6 as DateRangeSchema, ag as DeploymentStage, aa as EmailInput, $ as EmailSchema, E as EnvValidationConfig, p as EnvValidationResult, ai as FlagDefinition, aj as FlagDefinitions, ah as FlagValue, r as KEYCLOAK_DEFAULT_ROLES, F as KeycloakCallbacksConfig, K as KeycloakConfig, G as KeycloakJwtFields, q as KeycloakTokenSet, ae as LoginInput, a8 as LoginSchema, ay as OpsAuditActor, aA as OpsAuditEvent, aC as OpsAuditLoggerOptions, aB as OpsAuditRecord, az as OpsAuditResource, ab as PaginationInput, a5 as PaginationSchema, a0 as PasswordSchema, a3 as PersonNameSchema, a2 as PhoneSchema, aq as RateLimitCheckResult, P as RateLimitPreset, J as RedirectCallbackConfig, ak as ResolvedFlags, O as RouteAuditConfig, ad as SearchQueryInput, a7 as SearchQuerySchema, U as SecuritySession, af as SignupInput, a9 as SignupSchema, a1 as SlugSchema, aF as StandardAuditActionType, aE as StandardAuditActions, S as StandardRateLimitPresets, T as TokenRefreshResult, _ as WrapperPresets, ao as buildAllowlist, I as buildAuthCookies, Z as buildErrorBody, M as buildKeycloakCallbacks, e as buildPagination, Y as buildRateLimitHeaders, aw as buildRateLimitResponseHeaders, L as buildRedirectCallback, y as buildTokenRefreshParams, n as checkEnvVars, at as checkRateLimit, c as classifyError, aR as clearStoredBetaCode, aJ as createAuditActor, aK as createAuditLogger, aM as createBetaClient, an as createFeatureFlags, as as createMemoryRateLimitStore, a4 as createSafeTextSchema, am as detectStage, aG as extractAuditIp, aI as extractAuditRequestId, aH as extractAuditUserAgent, X as extractClientIp, aN as fetchBetaSettings, l as getBoolEnv, B as getEndSessionEndpoint, o as getEnvSummary, m as getIntEnv, k as getOptionalEnv, au as getRateLimitStatus, j as getRequiredEnv, aQ as getStoredBetaCode, z as getTokenEndpoint, w as hasAllRoles, u as hasAnyRole, t as hasRole, ap as isAllowlisted, i as isApiError, x as isTokenExpired, s as parseKeycloakRoles, D as refreshKeycloakToken, av as resetRateLimitForKey, ax as resolveIdentifier, W as resolveRateLimitIdentifier, aP as storeBetaCode, aO as validateBetaCode, v as validateEnvVars } from './env-BJWliXSO.mjs';
3
- export { c as constantTimeEqual, b as containsHtml, a as containsUrls, e as escapeHtml, g as getCorrelationId, d as sanitizeApiError, s as stripHtml } from './security-BvLXaQkv.mjs';
3
+ export { c as constantTimeEqual, b as containsHtml, a as containsUrls, e as escapeHtml, h as getCorrelationId, g as sanitizeApiError, s as stripHtml, d as stripNullBytes, f as stripNullBytesDeep } from './security-DMUNYqQI.mjs';
4
4
  import 'zod';
5
5
 
6
6
  /**
@@ -341,6 +341,33 @@ interface FederatedLogoutConfig {
341
341
  * If not provided, errors are silently ignored.
342
342
  */
343
343
  onError?: (message: string, error?: unknown) => void;
344
+ /**
345
+ * Number of chunk suffixes to enumerate when clearing session-token cookies.
346
+ *
347
+ * Auth.js splits encrypted JWE session tokens across `.0`, `.1`, `.2` ...
348
+ * suffixed cookies when the value exceeds the ~4 KB per-cookie limit.
349
+ * Keycloak access + id + refresh tokens reliably push past this threshold,
350
+ * so the unsuffixed name alone does NOT clear the session in production —
351
+ * the chunks survive and Auth.js reassembles the session on the next
352
+ * `/api/auth/session` call, causing silent re-auth after logout.
353
+ *
354
+ * Default: `3` (covers `.0`/`.1`/`.2` — 12 KB ceiling, well above any
355
+ * realistic JWE). Raise only if your tokens are unusually large; each
356
+ * additional chunk adds 4 Set-Cookie headers (host + domain scopes for
357
+ * both `authjs` and `next-auth` session-token names), and the total
358
+ * response headers must stay under Cloudflare's ~16 KB HTTP/2 limit.
359
+ */
360
+ chunkCount?: number;
361
+ /**
362
+ * Whether to also clear legacy `next-auth.*` cookie names in addition to
363
+ * the `authjs.*` names. Defaults to `true` for compatibility with apps
364
+ * that migrated from NextAuth v4 → Auth.js v5 (their sessions may still
365
+ * be under the old names). Set to `false` on apps that never ran
366
+ * pre-Auth.js-v5 to slim the Set-Cookie response.
367
+ *
368
+ * Default: `true`
369
+ */
370
+ includeLegacyNextAuthCookies?: boolean;
344
371
  }
345
372
  /**
346
373
  * Build a Next.js route handler for federated logout with Keycloak.
package/dist/auth.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as RateLimitStore, a as RateLimitRule, b as RateLimitOptions } from './env-BJWliXSO.js';
2
2
  export { al as AllowlistConfig, A as ApiError, d as ApiErrorCode, f as ApiErrorCodeType, h as ApiPaginatedResponse, Q as ApiSecurityConfig, V as ApiSecurityContext, g as ApiSuccessResponse, aD as AuditRequest, H as AuthCookiesConfig, N as AuthMethod, aL as BetaClientConfig, C as CommonApiErrors, ar as CommonRateLimits, ac as DateRangeInput, a6 as DateRangeSchema, ag as DeploymentStage, aa as EmailInput, $ as EmailSchema, E as EnvValidationConfig, p as EnvValidationResult, ai as FlagDefinition, aj as FlagDefinitions, ah as FlagValue, r as KEYCLOAK_DEFAULT_ROLES, F as KeycloakCallbacksConfig, K as KeycloakConfig, G as KeycloakJwtFields, q as KeycloakTokenSet, ae as LoginInput, a8 as LoginSchema, ay as OpsAuditActor, aA as OpsAuditEvent, aC as OpsAuditLoggerOptions, aB as OpsAuditRecord, az as OpsAuditResource, ab as PaginationInput, a5 as PaginationSchema, a0 as PasswordSchema, a3 as PersonNameSchema, a2 as PhoneSchema, aq as RateLimitCheckResult, P as RateLimitPreset, J as RedirectCallbackConfig, ak as ResolvedFlags, O as RouteAuditConfig, ad as SearchQueryInput, a7 as SearchQuerySchema, U as SecuritySession, af as SignupInput, a9 as SignupSchema, a1 as SlugSchema, aF as StandardAuditActionType, aE as StandardAuditActions, S as StandardRateLimitPresets, T as TokenRefreshResult, _ as WrapperPresets, ao as buildAllowlist, I as buildAuthCookies, Z as buildErrorBody, M as buildKeycloakCallbacks, e as buildPagination, Y as buildRateLimitHeaders, aw as buildRateLimitResponseHeaders, L as buildRedirectCallback, y as buildTokenRefreshParams, n as checkEnvVars, at as checkRateLimit, c as classifyError, aR as clearStoredBetaCode, aJ as createAuditActor, aK as createAuditLogger, aM as createBetaClient, an as createFeatureFlags, as as createMemoryRateLimitStore, a4 as createSafeTextSchema, am as detectStage, aG as extractAuditIp, aI as extractAuditRequestId, aH as extractAuditUserAgent, X as extractClientIp, aN as fetchBetaSettings, l as getBoolEnv, B as getEndSessionEndpoint, o as getEnvSummary, m as getIntEnv, k as getOptionalEnv, au as getRateLimitStatus, j as getRequiredEnv, aQ as getStoredBetaCode, z as getTokenEndpoint, w as hasAllRoles, u as hasAnyRole, t as hasRole, ap as isAllowlisted, i as isApiError, x as isTokenExpired, s as parseKeycloakRoles, D as refreshKeycloakToken, av as resetRateLimitForKey, ax as resolveIdentifier, W as resolveRateLimitIdentifier, aP as storeBetaCode, aO as validateBetaCode, v as validateEnvVars } from './env-BJWliXSO.js';
3
- export { c as constantTimeEqual, b as containsHtml, a as containsUrls, e as escapeHtml, g as getCorrelationId, d as sanitizeApiError, s as stripHtml } from './security-BvLXaQkv.js';
3
+ export { c as constantTimeEqual, b as containsHtml, a as containsUrls, e as escapeHtml, h as getCorrelationId, g as sanitizeApiError, s as stripHtml, d as stripNullBytes, f as stripNullBytesDeep } from './security-DMUNYqQI.js';
4
4
  import 'zod';
5
5
 
6
6
  /**
@@ -341,6 +341,33 @@ interface FederatedLogoutConfig {
341
341
  * If not provided, errors are silently ignored.
342
342
  */
343
343
  onError?: (message: string, error?: unknown) => void;
344
+ /**
345
+ * Number of chunk suffixes to enumerate when clearing session-token cookies.
346
+ *
347
+ * Auth.js splits encrypted JWE session tokens across `.0`, `.1`, `.2` ...
348
+ * suffixed cookies when the value exceeds the ~4 KB per-cookie limit.
349
+ * Keycloak access + id + refresh tokens reliably push past this threshold,
350
+ * so the unsuffixed name alone does NOT clear the session in production —
351
+ * the chunks survive and Auth.js reassembles the session on the next
352
+ * `/api/auth/session` call, causing silent re-auth after logout.
353
+ *
354
+ * Default: `3` (covers `.0`/`.1`/`.2` — 12 KB ceiling, well above any
355
+ * realistic JWE). Raise only if your tokens are unusually large; each
356
+ * additional chunk adds 4 Set-Cookie headers (host + domain scopes for
357
+ * both `authjs` and `next-auth` session-token names), and the total
358
+ * response headers must stay under Cloudflare's ~16 KB HTTP/2 limit.
359
+ */
360
+ chunkCount?: number;
361
+ /**
362
+ * Whether to also clear legacy `next-auth.*` cookie names in addition to
363
+ * the `authjs.*` names. Defaults to `true` for compatibility with apps
364
+ * that migrated from NextAuth v4 → Auth.js v5 (their sessions may still
365
+ * be under the old names). Set to `false` on apps that never ran
366
+ * pre-Auth.js-v5 to slim the Set-Cookie response.
367
+ *
368
+ * Default: `true`
369
+ */
370
+ includeLegacyNextAuthCookies?: boolean;
344
371
  }
345
372
  /**
346
373
  * Build a Next.js route handler for federated logout with Keycloak.
package/dist/auth.js CHANGED
@@ -103,6 +103,8 @@ __export(auth_exports, {
103
103
  sanitizeApiError: () => sanitizeApiError,
104
104
  storeBetaCode: () => storeBetaCode,
105
105
  stripHtml: () => stripHtml,
106
+ stripNullBytes: () => stripNullBytes,
107
+ stripNullBytesDeep: () => stripNullBytesDeep,
106
108
  validateBetaCode: () => validateBetaCode,
107
109
  validateEnvVars: () => validateEnvVars,
108
110
  verifyCronAuth: () => verifyCronAuth,
@@ -471,6 +473,29 @@ function containsHtml(str) {
471
473
  function stripHtml(str) {
472
474
  return str.replace(/<[^>]*>/g, "");
473
475
  }
476
+ function stripNullBytes(value) {
477
+ if (value === null || value === void 0) return value;
478
+ return value.replace(/\u0000/g, "");
479
+ }
480
+ function stripNullBytesDeep(value, depth = 8) {
481
+ if (depth <= 0) {
482
+ throw new Error("stripNullBytesDeep: max depth exceeded (circular?)");
483
+ }
484
+ if (typeof value === "string") {
485
+ return value.replace(/\u0000/g, "");
486
+ }
487
+ if (Array.isArray(value)) {
488
+ return value.map((v) => stripNullBytesDeep(v, depth - 1));
489
+ }
490
+ if (value !== null && typeof value === "object") {
491
+ const out = {};
492
+ for (const [k, v] of Object.entries(value)) {
493
+ out[k] = stripNullBytesDeep(v, depth - 1);
494
+ }
495
+ return out;
496
+ }
497
+ return value;
498
+ }
474
499
  function constantTimeEqual(a, b) {
475
500
  try {
476
501
  const aBuf = Buffer.from(a, "utf-8");
@@ -1428,9 +1453,15 @@ function isAllowedCallbackUrl(url, baseUrl) {
1428
1453
  return false;
1429
1454
  }
1430
1455
  }
1431
- var AUTH_COOKIE_NAMES = [
1456
+ var SESSION_TOKEN_BASE_NAMES_AUTHJS = [
1432
1457
  "authjs.session-token",
1433
- "__Secure-authjs.session-token",
1458
+ "__Secure-authjs.session-token"
1459
+ ];
1460
+ var SESSION_TOKEN_BASE_NAMES_LEGACY = [
1461
+ "next-auth.session-token",
1462
+ "__Secure-next-auth.session-token"
1463
+ ];
1464
+ var NON_SESSION_COOKIE_NAMES_AUTHJS = [
1434
1465
  "authjs.callback-url",
1435
1466
  "__Secure-authjs.callback-url",
1436
1467
  "authjs.csrf-token",
@@ -1438,21 +1469,42 @@ var AUTH_COOKIE_NAMES = [
1438
1469
  "authjs.pkce.code_verifier",
1439
1470
  "__Secure-authjs.pkce.code_verifier",
1440
1471
  "authjs.state",
1441
- "__Secure-authjs.state",
1442
- // Legacy next-auth names
1443
- "next-auth.session-token",
1444
- "__Secure-next-auth.session-token",
1472
+ "__Secure-authjs.state"
1473
+ ];
1474
+ var NON_SESSION_COOKIE_NAMES_LEGACY = [
1445
1475
  "next-auth.callback-url",
1446
1476
  "__Secure-next-auth.callback-url",
1447
1477
  "next-auth.csrf-token",
1448
1478
  "__Secure-next-auth.csrf-token"
1449
1479
  ];
1450
- var HOST_COOKIES = [
1451
- "__Host-authjs.csrf-token",
1452
- "__Host-next-auth.csrf-token"
1453
- ];
1480
+ var HOST_COOKIES_AUTHJS = ["__Host-authjs.csrf-token"];
1481
+ var HOST_COOKIES_LEGACY = ["__Host-next-auth.csrf-token"];
1482
+ function buildCookieNames(chunkCount, includeLegacy, extraCookies) {
1483
+ const sessionBases = includeLegacy ? [...SESSION_TOKEN_BASE_NAMES_AUTHJS, ...SESSION_TOKEN_BASE_NAMES_LEGACY] : SESSION_TOKEN_BASE_NAMES_AUTHJS;
1484
+ const sessionExpanded = [];
1485
+ for (const base of sessionBases) {
1486
+ sessionExpanded.push(base);
1487
+ for (let i = 0; i < chunkCount; i++) {
1488
+ sessionExpanded.push(`${base}.${i}`);
1489
+ }
1490
+ }
1491
+ const nonSession = includeLegacy ? [...NON_SESSION_COOKIE_NAMES_AUTHJS, ...NON_SESSION_COOKIE_NAMES_LEGACY] : NON_SESSION_COOKIE_NAMES_AUTHJS;
1492
+ const hostPrefixed = includeLegacy ? [...HOST_COOKIES_AUTHJS, ...HOST_COOKIES_LEGACY] : HOST_COOKIES_AUTHJS;
1493
+ return {
1494
+ scoped: [...sessionExpanded, ...nonSession, ...extraCookies],
1495
+ hostPrefixed
1496
+ };
1497
+ }
1454
1498
  function buildFederatedLogoutHandler(config) {
1455
- const { auth, domain, baseUrlFallback, extraCookies = [], onError } = config;
1499
+ const {
1500
+ auth,
1501
+ domain,
1502
+ baseUrlFallback,
1503
+ extraCookies = [],
1504
+ onError,
1505
+ chunkCount = 3,
1506
+ includeLegacyNextAuthCookies = true
1507
+ } = config;
1456
1508
  return async function GET(request) {
1457
1509
  const session = await auth();
1458
1510
  const url = new URL(request.url);
@@ -1523,8 +1575,12 @@ function buildFederatedLogoutHandler(config) {
1523
1575
  });
1524
1576
  const isProduction = process.env.NODE_ENV === "production";
1525
1577
  const isSecure = isProduction;
1526
- const allCookieNames = [...AUTH_COOKIE_NAMES, ...extraCookies];
1527
- for (const name of allCookieNames) {
1578
+ const { scoped, hostPrefixed } = buildCookieNames(
1579
+ chunkCount,
1580
+ includeLegacyNextAuthCookies,
1581
+ extraCookies
1582
+ );
1583
+ for (const name of scoped) {
1528
1584
  const needsSecure = isSecure || name.startsWith("__Secure-");
1529
1585
  response.headers.append(
1530
1586
  "Set-Cookie",
@@ -1537,7 +1593,7 @@ function buildFederatedLogoutHandler(config) {
1537
1593
  );
1538
1594
  }
1539
1595
  }
1540
- for (const name of HOST_COOKIES) {
1596
+ for (const name of hostPrefixed) {
1541
1597
  response.headers.append(
1542
1598
  "Set-Cookie",
1543
1599
  expireCookie(name, { hostPrefix: true })
@@ -1979,6 +2035,8 @@ function getEnvSummary(keys) {
1979
2035
  sanitizeApiError,
1980
2036
  storeBetaCode,
1981
2037
  stripHtml,
2038
+ stripNullBytes,
2039
+ stripNullBytesDeep,
1982
2040
  validateBetaCode,
1983
2041
  validateEnvVars,
1984
2042
  verifyCronAuth,