@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.mjs CHANGED
@@ -359,6 +359,29 @@ function containsHtml(str) {
359
359
  function stripHtml(str) {
360
360
  return str.replace(/<[^>]*>/g, "");
361
361
  }
362
+ function stripNullBytes(value) {
363
+ if (value === null || value === void 0) return value;
364
+ return value.replace(/\u0000/g, "");
365
+ }
366
+ function stripNullBytesDeep(value, depth = 8) {
367
+ if (depth <= 0) {
368
+ throw new Error("stripNullBytesDeep: max depth exceeded (circular?)");
369
+ }
370
+ if (typeof value === "string") {
371
+ return value.replace(/\u0000/g, "");
372
+ }
373
+ if (Array.isArray(value)) {
374
+ return value.map((v) => stripNullBytesDeep(v, depth - 1));
375
+ }
376
+ if (value !== null && typeof value === "object") {
377
+ const out = {};
378
+ for (const [k, v] of Object.entries(value)) {
379
+ out[k] = stripNullBytesDeep(v, depth - 1);
380
+ }
381
+ return out;
382
+ }
383
+ return value;
384
+ }
362
385
  function constantTimeEqual(a, b) {
363
386
  try {
364
387
  const aBuf = Buffer.from(a, "utf-8");
@@ -1316,9 +1339,15 @@ function isAllowedCallbackUrl(url, baseUrl) {
1316
1339
  return false;
1317
1340
  }
1318
1341
  }
1319
- var AUTH_COOKIE_NAMES = [
1342
+ var SESSION_TOKEN_BASE_NAMES_AUTHJS = [
1320
1343
  "authjs.session-token",
1321
- "__Secure-authjs.session-token",
1344
+ "__Secure-authjs.session-token"
1345
+ ];
1346
+ var SESSION_TOKEN_BASE_NAMES_LEGACY = [
1347
+ "next-auth.session-token",
1348
+ "__Secure-next-auth.session-token"
1349
+ ];
1350
+ var NON_SESSION_COOKIE_NAMES_AUTHJS = [
1322
1351
  "authjs.callback-url",
1323
1352
  "__Secure-authjs.callback-url",
1324
1353
  "authjs.csrf-token",
@@ -1326,21 +1355,42 @@ var AUTH_COOKIE_NAMES = [
1326
1355
  "authjs.pkce.code_verifier",
1327
1356
  "__Secure-authjs.pkce.code_verifier",
1328
1357
  "authjs.state",
1329
- "__Secure-authjs.state",
1330
- // Legacy next-auth names
1331
- "next-auth.session-token",
1332
- "__Secure-next-auth.session-token",
1358
+ "__Secure-authjs.state"
1359
+ ];
1360
+ var NON_SESSION_COOKIE_NAMES_LEGACY = [
1333
1361
  "next-auth.callback-url",
1334
1362
  "__Secure-next-auth.callback-url",
1335
1363
  "next-auth.csrf-token",
1336
1364
  "__Secure-next-auth.csrf-token"
1337
1365
  ];
1338
- var HOST_COOKIES = [
1339
- "__Host-authjs.csrf-token",
1340
- "__Host-next-auth.csrf-token"
1341
- ];
1366
+ var HOST_COOKIES_AUTHJS = ["__Host-authjs.csrf-token"];
1367
+ var HOST_COOKIES_LEGACY = ["__Host-next-auth.csrf-token"];
1368
+ function buildCookieNames(chunkCount, includeLegacy, extraCookies) {
1369
+ const sessionBases = includeLegacy ? [...SESSION_TOKEN_BASE_NAMES_AUTHJS, ...SESSION_TOKEN_BASE_NAMES_LEGACY] : SESSION_TOKEN_BASE_NAMES_AUTHJS;
1370
+ const sessionExpanded = [];
1371
+ for (const base of sessionBases) {
1372
+ sessionExpanded.push(base);
1373
+ for (let i = 0; i < chunkCount; i++) {
1374
+ sessionExpanded.push(`${base}.${i}`);
1375
+ }
1376
+ }
1377
+ const nonSession = includeLegacy ? [...NON_SESSION_COOKIE_NAMES_AUTHJS, ...NON_SESSION_COOKIE_NAMES_LEGACY] : NON_SESSION_COOKIE_NAMES_AUTHJS;
1378
+ const hostPrefixed = includeLegacy ? [...HOST_COOKIES_AUTHJS, ...HOST_COOKIES_LEGACY] : HOST_COOKIES_AUTHJS;
1379
+ return {
1380
+ scoped: [...sessionExpanded, ...nonSession, ...extraCookies],
1381
+ hostPrefixed
1382
+ };
1383
+ }
1342
1384
  function buildFederatedLogoutHandler(config) {
1343
- const { auth, domain, baseUrlFallback, extraCookies = [], onError } = config;
1385
+ const {
1386
+ auth,
1387
+ domain,
1388
+ baseUrlFallback,
1389
+ extraCookies = [],
1390
+ onError,
1391
+ chunkCount = 3,
1392
+ includeLegacyNextAuthCookies = true
1393
+ } = config;
1344
1394
  return async function GET(request) {
1345
1395
  const session = await auth();
1346
1396
  const url = new URL(request.url);
@@ -1411,8 +1461,12 @@ function buildFederatedLogoutHandler(config) {
1411
1461
  });
1412
1462
  const isProduction = process.env.NODE_ENV === "production";
1413
1463
  const isSecure = isProduction;
1414
- const allCookieNames = [...AUTH_COOKIE_NAMES, ...extraCookies];
1415
- for (const name of allCookieNames) {
1464
+ const { scoped, hostPrefixed } = buildCookieNames(
1465
+ chunkCount,
1466
+ includeLegacyNextAuthCookies,
1467
+ extraCookies
1468
+ );
1469
+ for (const name of scoped) {
1416
1470
  const needsSecure = isSecure || name.startsWith("__Secure-");
1417
1471
  response.headers.append(
1418
1472
  "Set-Cookie",
@@ -1425,7 +1479,7 @@ function buildFederatedLogoutHandler(config) {
1425
1479
  );
1426
1480
  }
1427
1481
  }
1428
- for (const name of HOST_COOKIES) {
1482
+ for (const name of hostPrefixed) {
1429
1483
  response.headers.append(
1430
1484
  "Set-Cookie",
1431
1485
  expireCookie(name, { hostPrefix: true })
@@ -1866,6 +1920,8 @@ export {
1866
1920
  sanitizeApiError,
1867
1921
  storeBetaCode,
1868
1922
  stripHtml,
1923
+ stripNullBytes,
1924
+ stripNullBytesDeep,
1869
1925
  validateBetaCode,
1870
1926
  validateEnvVars,
1871
1927
  verifyCronAuth,