@digilogiclabs/platform-core 1.17.2 → 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 +20 -1
- package/dist/auth.d.ts +20 -1
- package/dist/auth.js +30 -0
- package/dist/auth.js.map +1 -1
- package/dist/auth.mjs +28 -0
- package/dist/auth.mjs.map +1 -1
- package/dist/email-templates.d.mts +1 -1
- package/dist/email-templates.d.ts +1 -1
- package/dist/email-templates.js.map +1 -1
- package/dist/email-templates.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{security-BvLXaQkv.d.mts → security-DMUNYqQI.d.mts} +42 -1
- package/dist/{security-BvLXaQkv.d.ts → security-DMUNYqQI.d.ts} +42 -1
- package/package.json +1 -1
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,
|
|
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
|
/**
|
|
@@ -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
|
@@ -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,
|
|
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
|
/**
|
|
@@ -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
|
@@ -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");
|
|
@@ -1687,6 +1712,9 @@ function createSecureHandlerFactory(factoryConfig) {
|
|
|
1687
1712
|
const ct = request.headers.get("content-type");
|
|
1688
1713
|
input = ct?.includes("application/json") ? await request.json() : {};
|
|
1689
1714
|
}
|
|
1715
|
+
if (factoryConfig.sanitizeNullBytes !== false) {
|
|
1716
|
+
input = stripNullBytesDeep(input);
|
|
1717
|
+
}
|
|
1690
1718
|
const result = routeConfig.validate.safeParse(input);
|
|
1691
1719
|
if (!result.success) {
|
|
1692
1720
|
const fieldErrors = result.error?.flatten ? result.error.flatten().fieldErrors : void 0;
|
|
@@ -2010,6 +2038,8 @@ function getEnvSummary(keys) {
|
|
|
2010
2038
|
sanitizeApiError,
|
|
2011
2039
|
storeBetaCode,
|
|
2012
2040
|
stripHtml,
|
|
2041
|
+
stripNullBytes,
|
|
2042
|
+
stripNullBytesDeep,
|
|
2013
2043
|
validateBetaCode,
|
|
2014
2044
|
validateEnvVars,
|
|
2015
2045
|
verifyCronAuth,
|