@digilogiclabs/platform-core 1.17.3 → 1.18.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.
package/dist/auth.d.mts CHANGED
@@ -539,6 +539,25 @@ interface SecureHandlerFactoryConfig<TSession extends SecureSession = SecureSess
539
539
  };
540
540
  /** Is the app running in development mode (default: NODE_ENV check) */
541
541
  isDevelopment?: boolean;
542
+ /**
543
+ * Auto-strip NUL bytes (U+0000) from query params and JSON body before
544
+ * they reach `validate.safeParse` and the handler's validated context.
545
+ *
546
+ * Why: Postgres rejects NUL bytes in text columns with an unhelpful
547
+ * `invalid byte sequence` → HTTP 500 `DATABASE_ERROR`. Since 1.17.3 apps
548
+ * have had `stripNullBytes` / `stripNullBytesDeep` utilities and have
549
+ * been inlining them at every route that forwards user input to the DB.
550
+ * This factory option moves the strip to a single place — every
551
+ * schema-validated route gets it for free.
552
+ *
553
+ * Scope: only applies to routes that use `validate` (we sanitize `input`
554
+ * right before `safeParse`). Routes that parse `request.url` or
555
+ * `request.json()` themselves still need to call `stripNullBytes` /
556
+ * `stripNullBytesDeep` manually.
557
+ *
558
+ * @default true
559
+ */
560
+ sanitizeNullBytes?: boolean;
542
561
  }
543
562
  /** Timed audit helper placed on context for handler-level audit control */
544
563
  interface SecureTimedAudit {
package/dist/auth.d.ts CHANGED
@@ -539,6 +539,25 @@ interface SecureHandlerFactoryConfig<TSession extends SecureSession = SecureSess
539
539
  };
540
540
  /** Is the app running in development mode (default: NODE_ENV check) */
541
541
  isDevelopment?: boolean;
542
+ /**
543
+ * Auto-strip NUL bytes (U+0000) from query params and JSON body before
544
+ * they reach `validate.safeParse` and the handler's validated context.
545
+ *
546
+ * Why: Postgres rejects NUL bytes in text columns with an unhelpful
547
+ * `invalid byte sequence` → HTTP 500 `DATABASE_ERROR`. Since 1.17.3 apps
548
+ * have had `stripNullBytes` / `stripNullBytesDeep` utilities and have
549
+ * been inlining them at every route that forwards user input to the DB.
550
+ * This factory option moves the strip to a single place — every
551
+ * schema-validated route gets it for free.
552
+ *
553
+ * Scope: only applies to routes that use `validate` (we sanitize `input`
554
+ * right before `safeParse`). Routes that parse `request.url` or
555
+ * `request.json()` themselves still need to call `stripNullBytes` /
556
+ * `stripNullBytesDeep` manually.
557
+ *
558
+ * @default true
559
+ */
560
+ sanitizeNullBytes?: boolean;
542
561
  }
543
562
  /** Timed audit helper placed on context for handler-level audit control */
544
563
  interface SecureTimedAudit {
package/dist/auth.js CHANGED
@@ -1712,6 +1712,9 @@ function createSecureHandlerFactory(factoryConfig) {
1712
1712
  const ct = request.headers.get("content-type");
1713
1713
  input = ct?.includes("application/json") ? await request.json() : {};
1714
1714
  }
1715
+ if (factoryConfig.sanitizeNullBytes !== false) {
1716
+ input = stripNullBytesDeep(input);
1717
+ }
1715
1718
  const result = routeConfig.validate.safeParse(input);
1716
1719
  if (!result.success) {
1717
1720
  const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;