@thexjs/core 1.11.0 → 1.11.1
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/adapter.js +1 -1
- package/dist/{chunk-GVDJW4PD.js → chunk-5FY3ROGN.js} +28 -2
- package/dist/index.d.ts +26 -1
- package/dist/index.js +7 -14
- package/package.json +1 -1
package/dist/adapter.js
CHANGED
|
@@ -466,11 +466,33 @@ function enforceRequestBodySize(req, maxBytes) {
|
|
|
466
466
|
});
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
// src/security/trusted-proxy.ts
|
|
470
|
+
var trustForwardedHeaders = false;
|
|
471
|
+
function isTrustedProxy() {
|
|
472
|
+
return trustForwardedHeaders;
|
|
473
|
+
}
|
|
474
|
+
function configureTrustedProxy(options) {
|
|
475
|
+
trustForwardedHeaders = options.trustForwardedHeaders ?? false;
|
|
476
|
+
}
|
|
477
|
+
function resetTrustedProxy() {
|
|
478
|
+
trustForwardedHeaders = false;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/security/secure-request.ts
|
|
482
|
+
function isSecureRequest(req) {
|
|
483
|
+
if (new URL(req.url).protocol === "https:") return true;
|
|
484
|
+
if (!isTrustedProxy()) return false;
|
|
485
|
+
return req.headers.get("x-forwarded-proto") === "https";
|
|
486
|
+
}
|
|
487
|
+
|
|
469
488
|
// src/security/csrf.ts
|
|
470
489
|
var CSRF_COOKIE_NAME = "x_csrf_token";
|
|
471
490
|
var CSRF_HEADER_NAME = "x-csrf-token";
|
|
472
491
|
var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
473
|
-
|
|
492
|
+
function secureCookieFlag(req) {
|
|
493
|
+
const secure = process.env.NODE_ENV === "production" || isSecureRequest(req);
|
|
494
|
+
return secure ? "; Secure" : "";
|
|
495
|
+
}
|
|
474
496
|
function originFromHeader(value) {
|
|
475
497
|
if (!value) return null;
|
|
476
498
|
try {
|
|
@@ -536,7 +558,7 @@ function withCsrfCookie(req, res) {
|
|
|
536
558
|
const headers = new Headers(res.headers);
|
|
537
559
|
headers.append(
|
|
538
560
|
"Set-Cookie",
|
|
539
|
-
`${CSRF_COOKIE_NAME}=${token}; Path=/; SameSite=Lax${
|
|
561
|
+
`${CSRF_COOKIE_NAME}=${token}; Path=/; SameSite=Lax${secureCookieFlag(req)}`
|
|
540
562
|
);
|
|
541
563
|
return new Response(res.body, { status: res.status, statusText: res.statusText, headers });
|
|
542
564
|
}
|
|
@@ -893,6 +915,10 @@ export {
|
|
|
893
915
|
DEFAULT_MAX_BODY_SIZE,
|
|
894
916
|
RequestBodyTooLargeError,
|
|
895
917
|
enforceRequestBodySize,
|
|
918
|
+
isTrustedProxy,
|
|
919
|
+
configureTrustedProxy,
|
|
920
|
+
resetTrustedProxy,
|
|
921
|
+
isSecureRequest,
|
|
896
922
|
originFromHeader,
|
|
897
923
|
requestOrigin,
|
|
898
924
|
verifyOrigin,
|
package/dist/index.d.ts
CHANGED
|
@@ -1141,6 +1141,31 @@ declare class EnvLeakageError extends Error {
|
|
|
1141
1141
|
/** Throws EnvLeakageError if the given bundle source references non-public env vars. */
|
|
1142
1142
|
declare function assertNoEnvLeakage(code: string, file: string): void;
|
|
1143
1143
|
|
|
1144
|
+
/**
|
|
1145
|
+
* True when a request should be treated as HTTPS for deciding whether a
|
|
1146
|
+
* cookie needs the `Secure` flag. Checks, in order:
|
|
1147
|
+
*
|
|
1148
|
+
* 1. The request URL's own protocol. Every adapter bridge (adapter-node,
|
|
1149
|
+
* adapter-vercel) and `Bun.serve` itself already resolve this correctly
|
|
1150
|
+
* for direct TLS termination — `req.url` reads `https:` whenever the
|
|
1151
|
+
* process itself holds the TLS connection, with no trust decision
|
|
1152
|
+
* involved.
|
|
1153
|
+
* 2. `X-Forwarded-Proto`, but only when the application has opted in to
|
|
1154
|
+
* trusting forwarded headers (`configureTrustedProxy({
|
|
1155
|
+
* trustForwardedHeaders: true })`) — the same trust boundary
|
|
1156
|
+
* `clientIpFromRequest` (`security/ip.ts`) already gates on. Without
|
|
1157
|
+
* this gate a client could set the header to downgrade the check at
|
|
1158
|
+
* will; with it, a reverse-proxy deployment that terminates TLS in
|
|
1159
|
+
* front of a plain-HTTP Bun process is correctly recognized as secure.
|
|
1160
|
+
*
|
|
1161
|
+
* This is meant to be used *alongside* an explicit `NODE_ENV === "production"`
|
|
1162
|
+
* / `forceSecureCookie` check, not as a replacement for one — a request can
|
|
1163
|
+
* be genuinely HTTPS in a non-"production" environment (a staging
|
|
1164
|
+
* deployment, a platform that names its env var something else), and this
|
|
1165
|
+
* closes exactly that gap.
|
|
1166
|
+
*/
|
|
1167
|
+
declare function isSecureRequest(req: Request): boolean;
|
|
1168
|
+
|
|
1144
1169
|
/**
|
|
1145
1170
|
* Global setting that controls whether client-supplied forwarding headers
|
|
1146
1171
|
* (`X-Forwarded-For`, `X-Real-IP`) are trusted for IP resolution.
|
|
@@ -1202,5 +1227,5 @@ declare function resetServerFunctions(): void;
|
|
|
1202
1227
|
declare function registerServerFunctions(routePath: string, paramNames: string[], fns: Record<string, (...args: unknown[]) => Promise<unknown>>): void;
|
|
1203
1228
|
declare function getServerFunctionHandler(csrfOptions?: CsrfOptions): (req: Request) => Promise<Response | null>;
|
|
1204
1229
|
|
|
1205
|
-
export { BackpressureOptions, CLIENT_NAV_SCRIPT, DEFAULT_HISTOGRAM_BUCKETS_MS, DEFAULT_MAX_BODY_SIZE, DefaultNotFound, EnvLeakageError, Image, Island, IslandProvider, Link, OTEL_ERROR_STATUS_CODE, PUBLIC_ENV_PREFIX, REDACTED, RequestBodyTooLargeError, SRCSET_WIDTHS, applySecurityHeaders, assertNoEnvLeakage, audit, auditLoginFailure, auditLoginSuccess, auditLogout, auditPasswordChanged, auditPermissionDenied, auditRoleChanged, auditSessionRevoked, build, buildSecurityHeaders, buildSrcSet, checkCsrf, clientIpFromRequest, combineReporters, composeMiddleware, configureTrustedProxy, createApp, createConsoleAuditSink, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, createRedisIsrCacheStore, createRedisRateLimitStore, createSentryReporter, dbTraceAttributes, defineConfig, enforceRequestBodySize, escapeHtml, findLayoutChain, findLeakedEnvKeys, findMiddlewareChain, generateCsrfToken, generateManifestSource, generateServerFunctionClient, getAuditSink, getErrorReporter, getServerFunctionHandler, getTracer, installProcessCrashHandlers, isSensitiveKey, isTrustedProxy, logger, noopAuditSink, noopMetrics, noopReporter, rateLimitMiddleware, redactString, redactValue, registerServerFunctions, renderErrorOverlay, renderMarkdown, renderPage, renderStaticPage, renderStreamingPage, reportException, requestIdFromRequest, resetServerFunctions, resetTrustedProxy, runWithRequestSpan, scanApiDir, scanContent, scanLayouts, scanLayoutsDir, scanMiddleware, scanNotFound, scanPages, scanRoutes, setAuditSink, setErrorReporter, setImageRemoteHosts, setTracer, tracePhase, tracePhaseSync, traceRequestId, verifyCsrfToken, verifyOrigin, withCsrfCookie, withRequestLogging, withRequestMetrics, withRequestTracing, writeManifest };
|
|
1230
|
+
export { BackpressureOptions, CLIENT_NAV_SCRIPT, DEFAULT_HISTOGRAM_BUCKETS_MS, DEFAULT_MAX_BODY_SIZE, DefaultNotFound, EnvLeakageError, Image, Island, IslandProvider, Link, OTEL_ERROR_STATUS_CODE, PUBLIC_ENV_PREFIX, REDACTED, RequestBodyTooLargeError, SRCSET_WIDTHS, applySecurityHeaders, assertNoEnvLeakage, audit, auditLoginFailure, auditLoginSuccess, auditLogout, auditPasswordChanged, auditPermissionDenied, auditRoleChanged, auditSessionRevoked, build, buildSecurityHeaders, buildSrcSet, checkCsrf, clientIpFromRequest, combineReporters, composeMiddleware, configureTrustedProxy, createApp, createConsoleAuditSink, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, createRedisIsrCacheStore, createRedisRateLimitStore, createSentryReporter, dbTraceAttributes, defineConfig, enforceRequestBodySize, escapeHtml, findLayoutChain, findLeakedEnvKeys, findMiddlewareChain, generateCsrfToken, generateManifestSource, generateServerFunctionClient, getAuditSink, getErrorReporter, getServerFunctionHandler, getTracer, installProcessCrashHandlers, isSecureRequest, isSensitiveKey, isTrustedProxy, logger, noopAuditSink, noopMetrics, noopReporter, rateLimitMiddleware, redactString, redactValue, registerServerFunctions, renderErrorOverlay, renderMarkdown, renderPage, renderStaticPage, renderStreamingPage, reportException, requestIdFromRequest, resetServerFunctions, resetTrustedProxy, runWithRequestSpan, scanApiDir, scanContent, scanLayouts, scanLayoutsDir, scanMiddleware, scanNotFound, scanPages, scanRoutes, setAuditSink, setErrorReporter, setImageRemoteHosts, setTracer, tracePhase, tracePhaseSync, traceRequestId, verifyCsrfToken, verifyOrigin, withCsrfCookie, withRequestLogging, withRequestMetrics, withRequestTracing, writeManifest };
|
|
1206
1231
|
export type { AuditEntry, AuditEvent, AuditSink, BuildOptions, ContentEntry, CounterSeries, CreateAppOptions, CsrfOptions, CsrfResult, ErrorContext, ErrorReporter, Frontmatter, HealthCheck, HealthCheckOptions, HistogramSeries, ImageProps, ImageProxyOptions, InMemoryMetricsOptions, InMemoryMetricsReporter, IslandEntry, IslandMode, IsrCacheStore, LayoutEntry, LinkProps, LoaderArgs, LoaderReturn, LogFields, Logger, MetricLabels, MetricsReporter, MetricsSnapshot, MiddlewareContext, MiddlewareEntry, MiddlewareFn, MiddlewareNext, NotFoundEntry, OtelMeterLike, OtelTracerLike, ProcessCrashHandlerOptions, RateLimitOptions, RateLimitResult, RateLimitStore, ReadinessResult, RevalidateOptions, RouteEntry, RouteMode, RouteProps, SecurityHeadersOptions, SentryLike, TraceSpan, TracerLike, TrustedProxyOptions };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
bundleRouteIslandsToDisk,
|
|
9
9
|
checkCsrf,
|
|
10
10
|
combineReporters,
|
|
11
|
+
configureTrustedProxy,
|
|
11
12
|
createOtelReporter,
|
|
12
13
|
createSentryReporter,
|
|
13
14
|
enforceRequestBodySize,
|
|
@@ -20,6 +21,8 @@ import {
|
|
|
20
21
|
generateServerFunctionClient,
|
|
21
22
|
getErrorReporter,
|
|
22
23
|
getServerFunctionHandler,
|
|
24
|
+
isSecureRequest,
|
|
25
|
+
isTrustedProxy,
|
|
23
26
|
islandEntryId,
|
|
24
27
|
noopReporter,
|
|
25
28
|
originFromHeader,
|
|
@@ -27,6 +30,7 @@ import {
|
|
|
27
30
|
reportException,
|
|
28
31
|
requestOrigin,
|
|
29
32
|
resetServerFunctions,
|
|
33
|
+
resetTrustedProxy,
|
|
30
34
|
scanApiDir,
|
|
31
35
|
scanLayouts,
|
|
32
36
|
scanLayoutsDir,
|
|
@@ -39,7 +43,7 @@ import {
|
|
|
39
43
|
verifyOrigin,
|
|
40
44
|
withCsrfCookie,
|
|
41
45
|
writeManifest
|
|
42
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-5FY3ROGN.js";
|
|
43
47
|
import {
|
|
44
48
|
OTEL_ERROR_STATUS_CODE,
|
|
45
49
|
REDACTED,
|
|
@@ -319,7 +323,7 @@ function decodeLinkUrl(url) {
|
|
|
319
323
|
return prev;
|
|
320
324
|
}
|
|
321
325
|
function stripUrlControlChars(url) {
|
|
322
|
-
return url.replace(/[\
|
|
326
|
+
return url.replace(/[\x00-\x1F]/g, "");
|
|
323
327
|
}
|
|
324
328
|
function isSafeLinkUrl(url) {
|
|
325
329
|
const clean = stripUrlControlChars(url);
|
|
@@ -1649,18 +1653,6 @@ function createRedisIsrCacheStoreFromClient(clientFactory, ttlSeconds = 7 * 24 *
|
|
|
1649
1653
|
};
|
|
1650
1654
|
}
|
|
1651
1655
|
|
|
1652
|
-
// src/security/trusted-proxy.ts
|
|
1653
|
-
var trustForwardedHeaders = false;
|
|
1654
|
-
function isTrustedProxy() {
|
|
1655
|
-
return trustForwardedHeaders;
|
|
1656
|
-
}
|
|
1657
|
-
function configureTrustedProxy(options) {
|
|
1658
|
-
trustForwardedHeaders = options.trustForwardedHeaders ?? false;
|
|
1659
|
-
}
|
|
1660
|
-
function resetTrustedProxy() {
|
|
1661
|
-
trustForwardedHeaders = false;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
1656
|
// src/security/rate-limit.ts
|
|
1665
1657
|
function defaultKeyFn(req, server) {
|
|
1666
1658
|
if (server?.requestIP) {
|
|
@@ -3335,6 +3327,7 @@ export {
|
|
|
3335
3327
|
getServerFunctionHandler,
|
|
3336
3328
|
getTracer,
|
|
3337
3329
|
installProcessCrashHandlers,
|
|
3330
|
+
isSecureRequest,
|
|
3338
3331
|
isSensitiveKey,
|
|
3339
3332
|
isTrustedProxy,
|
|
3340
3333
|
logger,
|
package/package.json
CHANGED