@thexjs/core 1.7.1 → 1.8.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/adapter.js
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
scanNotFound,
|
|
10
10
|
scanPages,
|
|
11
11
|
scanRoutes
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-3VMZCMAF.js";
|
|
13
|
+
import "./chunk-OXV2QTWV.js";
|
|
14
14
|
|
|
15
15
|
// src/adapter/bundle.ts
|
|
16
16
|
import { mkdirSync, rmSync, writeFileSync } from "fs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OTEL_ERROR_STATUS_CODE,
|
|
3
3
|
tracePhase
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OXV2QTWV.js";
|
|
5
5
|
|
|
6
6
|
// src/security/env-isolation.ts
|
|
7
7
|
var PUBLIC_ENV_PREFIX = "THEXJS_PUBLIC_";
|
|
@@ -661,16 +661,21 @@ function reportHydrationMismatch(error, name) {
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
+
// Preserve roots from a prior hydration entry on the same page (e.g. partial
|
|
665
|
+
// re-hydration). Only initialize when the array doesn't exist yet.
|
|
666
|
+
if (!window.__xIslandRoots) window.__xIslandRoots = [];
|
|
667
|
+
|
|
664
668
|
document.querySelectorAll("[data-island]").forEach((el) => {
|
|
665
669
|
const name = el.getAttribute("data-island");
|
|
666
670
|
if (!name) return;
|
|
667
671
|
const Component = resolveIsland(name);
|
|
668
672
|
if (!Component) return;
|
|
669
|
-
hydrateRoot(el, React.createElement(Component), {
|
|
673
|
+
const root = hydrateRoot(el, React.createElement(Component), {
|
|
670
674
|
onRecoverableError(error) {
|
|
671
675
|
reportHydrationMismatch(error, name);
|
|
672
676
|
},
|
|
673
677
|
});
|
|
678
|
+
window.__xIslandRoots.push(root);
|
|
674
679
|
});
|
|
675
680
|
`;
|
|
676
681
|
}
|
|
@@ -21,6 +21,9 @@ function redactValue(value, depth = 0) {
|
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// src/security/validation.ts
|
|
25
|
+
var SAFE_REQUEST_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
26
|
+
|
|
24
27
|
// src/observability/tracing.ts
|
|
25
28
|
var noopSpan = {
|
|
26
29
|
setAttribute: () => {
|
|
@@ -132,12 +135,16 @@ function dbTraceAttributes(system, statement) {
|
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
137
|
var requestIds = /* @__PURE__ */ new WeakMap();
|
|
138
|
+
function safeRequestId(raw) {
|
|
139
|
+
if (raw === null) return null;
|
|
140
|
+
return SAFE_REQUEST_ID_RE.test(raw) ? raw : null;
|
|
141
|
+
}
|
|
135
142
|
function traceRequestId(req) {
|
|
136
|
-
return requestIds.get(req) ?? req.headers.get("x-request-id") ?? crypto.randomUUID();
|
|
143
|
+
return requestIds.get(req) ?? safeRequestId(req.headers.get("x-request-id")) ?? crypto.randomUUID();
|
|
137
144
|
}
|
|
138
145
|
function withRequestTracing(handler) {
|
|
139
146
|
return async (req, server) => {
|
|
140
|
-
const existing = req.headers.get("x-request-id");
|
|
147
|
+
const existing = safeRequestId(req.headers.get("x-request-id"));
|
|
141
148
|
const requestId = existing ?? crypto.randomUUID();
|
|
142
149
|
if (!existing) requestIds.set(req, requestId);
|
|
143
150
|
const url = new URL(req.url);
|
|
@@ -154,6 +161,7 @@ function withRequestTracing(handler) {
|
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
export {
|
|
164
|
+
SAFE_REQUEST_ID_RE,
|
|
157
165
|
REDACTED,
|
|
158
166
|
isSensitiveKey,
|
|
159
167
|
redactString,
|
package/dist/data.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,13 @@ declare function build(options: BuildOptions): Promise<void>;
|
|
|
83
83
|
* - data-no-nav — skip client navigation (full page load)
|
|
84
84
|
* - data-no-prefetch — skip hover prefetch (navigation still works)
|
|
85
85
|
*/
|
|
86
|
+
declare global {
|
|
87
|
+
interface Window {
|
|
88
|
+
__xIslandRoots?: Array<{
|
|
89
|
+
unmount(): void;
|
|
90
|
+
}>;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
86
93
|
declare const CLIENT_NAV_SCRIPT: string;
|
|
87
94
|
|
|
88
95
|
interface Frontmatter {
|
|
@@ -552,6 +559,12 @@ interface CreateAppOptions {
|
|
|
552
559
|
* crossed. Default: 1 MiB.
|
|
553
560
|
*/
|
|
554
561
|
maxBodySize?: number;
|
|
562
|
+
/**
|
|
563
|
+
* Maximum entries in the per-route island bundle caches (both the
|
|
564
|
+
* route→script-list mapping and the URL→bundled-JS file cache). Entries are
|
|
565
|
+
* evicted LRU (oldest-first) once the cap is exceeded. Default: 500.
|
|
566
|
+
*/
|
|
567
|
+
islandCacheMaxEntries?: number;
|
|
555
568
|
/**
|
|
556
569
|
* Pre-resolved routes/actions for runtimes that can't scan the filesystem
|
|
557
570
|
* or dynamically `import()` a `.tsx` file at request time (e.g. Vercel's
|
|
@@ -682,9 +695,18 @@ declare function Link({ href, children, clientNav, prefetch, ...rest }: LinkProp
|
|
|
682
695
|
declare function DefaultNotFound(_props: RouteProps): react.JSX.Element;
|
|
683
696
|
|
|
684
697
|
/**
|
|
685
|
-
* Returns the client IP from a request
|
|
686
|
-
*
|
|
687
|
-
* to
|
|
698
|
+
* Returns the client IP from a request.
|
|
699
|
+
*
|
|
700
|
+
* When the application has opted in to trusting forwarded headers (via
|
|
701
|
+
* `configureTrustedProxy({ trustForwardedHeaders: true })`), this function
|
|
702
|
+
* checks `X-Forwarded-For` first (for proxied/edge deployments), falls back
|
|
703
|
+
* to `X-Real-IP`, and finally to `null` if neither is present.
|
|
704
|
+
*
|
|
705
|
+
* When forwarded headers are **not** trusted (the default), both headers are
|
|
706
|
+
* ignored entirely and the function returns `null` — the IP is simply
|
|
707
|
+
* unavailable. This is the safe behaviour: a client can set
|
|
708
|
+
* `X-Forwarded-For` to any value on every request, defeating IP-based rate
|
|
709
|
+
* limiting and poisoning audit trails if trusted.
|
|
688
710
|
*/
|
|
689
711
|
declare function clientIpFromRequest(req: Request): string | null;
|
|
690
712
|
|
|
@@ -1006,9 +1028,65 @@ declare class EnvLeakageError extends Error {
|
|
|
1006
1028
|
/** Throws EnvLeakageError if the given bundle source references non-public env vars. */
|
|
1007
1029
|
declare function assertNoEnvLeakage(code: string, file: string): void;
|
|
1008
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* Global setting that controls whether client-supplied forwarding headers
|
|
1033
|
+
* (`X-Forwarded-For`, `X-Real-IP`) are trusted for IP resolution.
|
|
1034
|
+
*
|
|
1035
|
+
* ## Security boundary
|
|
1036
|
+
*
|
|
1037
|
+
* When `trustForwardedHeaders` is **false** (the default), the framework
|
|
1038
|
+
* ignores `X-Forwarded-For` and `X-Real-IP` entirely. A client can set
|
|
1039
|
+
* these headers to arbitrary values on every request, which — if trusted —
|
|
1040
|
+
* lets them defeat IP-based rate limiting (brute-force guards) and poison
|
|
1041
|
+
* audit trails with attacker-chosen IPs. This is the safe default because
|
|
1042
|
+
* the framework cannot distinguish a legitimate proxy chain from a direct
|
|
1043
|
+
* connection with spoofed headers.
|
|
1044
|
+
*
|
|
1045
|
+
* Only set `trustForwardedHeaders: true` when **all** of the following hold:
|
|
1046
|
+
* 1. The application sits behind a reverse proxy / edge that scrubs or
|
|
1047
|
+
* overwrites forwarded headers (e.g. Vercel Edge, Cloudflare, AWS ALB).
|
|
1048
|
+
* 2. The proxy always sets `X-Forwarded-For` to the real client IP chain,
|
|
1049
|
+
* and clients cannot reach the origin without going through that proxy.
|
|
1050
|
+
*
|
|
1051
|
+
* Adapters (e.g. `@thexjs/adapter-vercel`) call {@link configureTrustedProxy}
|
|
1052
|
+
* at their own initialization point when the deployment platform guarantees
|
|
1053
|
+
* header integrity. Applications that deploy directly (no proxy) or sit
|
|
1054
|
+
* behind a proxy that does not scrub headers must **not** enable this.
|
|
1055
|
+
*/
|
|
1056
|
+
interface TrustedProxyOptions {
|
|
1057
|
+
/**
|
|
1058
|
+
* When `true`, `clientIpFromRequest()` reads `X-Forwarded-For` /
|
|
1059
|
+
* `X-Real-IP` headers. When `false` (default), those headers are ignored
|
|
1060
|
+
* and `clientIpFromRequest()` returns `null` (unavailable).
|
|
1061
|
+
*/
|
|
1062
|
+
trustForwardedHeaders?: boolean;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Returns `true` when the application has opted in to trusting client-supplied
|
|
1066
|
+
* forwarding headers for IP resolution.
|
|
1067
|
+
*/
|
|
1068
|
+
declare function isTrustedProxy(): boolean;
|
|
1069
|
+
/**
|
|
1070
|
+
* Configures the global trusted-proxy policy. Call once at application
|
|
1071
|
+
* initialization (e.g. inside an adapter's build output or a top-level
|
|
1072
|
+
* `x.config.ts` callback). Subsequent calls overwrite the previous value.
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```ts
|
|
1076
|
+
* // Vercel adapter — edge always sets X-Forwarded-For correctly
|
|
1077
|
+
* configureTrustedProxy({ trustForwardedHeaders: true });
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
declare function configureTrustedProxy(options: TrustedProxyOptions): void;
|
|
1081
|
+
/**
|
|
1082
|
+
* Resets the trusted-proxy setting to the default (`false`).
|
|
1083
|
+
* Exported for test isolation — production code should never need this.
|
|
1084
|
+
*/
|
|
1085
|
+
declare function resetTrustedProxy(): void;
|
|
1086
|
+
|
|
1009
1087
|
declare function generateServerFunctionClient(routeFilePath: string, fnNames: string[], endpointBase: string): string;
|
|
1010
1088
|
declare function resetServerFunctions(): void;
|
|
1011
1089
|
declare function registerServerFunctions(routePath: string, paramNames: string[], fns: Record<string, (...args: unknown[]) => Promise<unknown>>): void;
|
|
1012
1090
|
declare function getServerFunctionHandler(csrfOptions?: CsrfOptions): (req: Request) => Promise<Response | null>;
|
|
1013
1091
|
|
|
1014
|
-
export { type AuditEntry, type AuditEvent, type AuditSink, type BackpressureController, type BackpressureHandler, type BackpressureLease, type BackpressureOptions, BackpressureSaturatedError, type BackpressureSnapshot, type BuildOptions, CLIENT_NAV_SCRIPT, type ContentEntry, type CounterSeries, type CreateAppOptions, type CsrfOptions, type CsrfResult, DEFAULT_HISTOGRAM_BUCKETS_MS, DEFAULT_MAX_BODY_SIZE, DefaultNotFound, EnvLeakageError, type ErrorContext, type ErrorReporter, type Frontmatter, type HealthCheck, type HealthCheckOptions, type HistogramSeries, Image, type ImageProps, type ImageProxyOptions, type InMemoryMetricsOptions, type InMemoryMetricsReporter, Island, type IslandEntry, type IslandMode, IslandProvider, type LayoutEntry, Link, type LinkProps, type LoaderArgs, type LoaderReturn, type LogFields, type Logger, type MetricLabels, type MetricsReporter, type MetricsSnapshot, type MiddlewareContext, type MiddlewareEntry, type MiddlewareFn, type MiddlewareNext, type NotFoundEntry, OTEL_ERROR_STATUS_CODE, type OtelMeterLike, type OtelTracerLike, PUBLIC_ENV_PREFIX, type ProcessCrashHandlerOptions, REDACTED, type RateLimitOptions, type RateLimitResult, type RateLimitStore, type ReadinessResult, RequestBodyTooLargeError, type RevalidateOptions, type RouteEntry, type RouteMode, type RouteProps, SRCSET_WIDTHS, type SecurityHeadersOptions, type SentryLike, type TraceSpan, type TracerLike, applySecurityHeaders, assertNoEnvLeakage, audit, auditLoginFailure, auditLoginSuccess, auditLogout, auditPasswordChanged, auditPermissionDenied, auditRoleChanged, auditSessionRevoked, build, buildSecurityHeaders, buildSrcSet, checkCsrf, clientIpFromRequest, combineReporters, composeMiddleware, createApp, createBackpressureController, createConsoleAuditSink, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, createRedisRateLimitStore, createSentryReporter, dbTraceAttributes, defineConfig, enforceRequestBodySize, escapeHtml, findLayoutChain, findLeakedEnvKeys, findMiddlewareChain, generateCsrfToken, generateManifestSource, generateServerFunctionClient, getAuditSink, getErrorReporter, getServerFunctionHandler, getTracer, installProcessCrashHandlers, isSensitiveKey, logger, noopAuditSink, noopMetrics, noopReporter, rateLimitMiddleware, redactString, redactValue, registerServerFunctions, renderErrorOverlay, renderMarkdown, renderPage, renderStaticPage, renderStreamingPage, reportException, requestIdFromRequest, resetServerFunctions, runWithRequestSpan, scanApiDir, scanContent, scanLayouts, scanLayoutsDir, scanMiddleware, scanNotFound, scanPages, scanRoutes, setAuditSink, setErrorReporter, setImageRemoteHosts, setTracer, tracePhase, tracePhaseSync, traceRequestId, verifyCsrfToken, verifyOrigin, withBackpressure, withCsrfCookie, withRequestLogging, withRequestMetrics, withRequestTracing, writeManifest };
|
|
1092
|
+
export { type AuditEntry, type AuditEvent, type AuditSink, type BackpressureController, type BackpressureHandler, type BackpressureLease, type BackpressureOptions, BackpressureSaturatedError, type BackpressureSnapshot, type BuildOptions, CLIENT_NAV_SCRIPT, type ContentEntry, type CounterSeries, type CreateAppOptions, type CsrfOptions, type CsrfResult, DEFAULT_HISTOGRAM_BUCKETS_MS, DEFAULT_MAX_BODY_SIZE, DefaultNotFound, EnvLeakageError, type ErrorContext, type ErrorReporter, type Frontmatter, type HealthCheck, type HealthCheckOptions, type HistogramSeries, Image, type ImageProps, type ImageProxyOptions, type InMemoryMetricsOptions, type InMemoryMetricsReporter, Island, type IslandEntry, type IslandMode, IslandProvider, type LayoutEntry, Link, type LinkProps, type LoaderArgs, type LoaderReturn, type LogFields, type Logger, type MetricLabels, type MetricsReporter, type MetricsSnapshot, type MiddlewareContext, type MiddlewareEntry, type MiddlewareFn, type MiddlewareNext, type NotFoundEntry, OTEL_ERROR_STATUS_CODE, type OtelMeterLike, type OtelTracerLike, PUBLIC_ENV_PREFIX, type ProcessCrashHandlerOptions, REDACTED, type RateLimitOptions, type RateLimitResult, type RateLimitStore, type ReadinessResult, RequestBodyTooLargeError, type RevalidateOptions, type RouteEntry, type RouteMode, type RouteProps, SRCSET_WIDTHS, type SecurityHeadersOptions, type SentryLike, type TraceSpan, type TracerLike, type TrustedProxyOptions, applySecurityHeaders, assertNoEnvLeakage, audit, auditLoginFailure, auditLoginSuccess, auditLogout, auditPasswordChanged, auditPermissionDenied, auditRoleChanged, auditSessionRevoked, build, buildSecurityHeaders, buildSrcSet, checkCsrf, clientIpFromRequest, combineReporters, composeMiddleware, configureTrustedProxy, createApp, createBackpressureController, createConsoleAuditSink, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, 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, withBackpressure, withCsrfCookie, withRequestLogging, withRequestMetrics, withRequestTracing, writeManifest };
|
package/dist/index.js
CHANGED
|
@@ -39,10 +39,11 @@ import {
|
|
|
39
39
|
verifyOrigin,
|
|
40
40
|
withCsrfCookie,
|
|
41
41
|
writeManifest
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-3VMZCMAF.js";
|
|
43
43
|
import {
|
|
44
44
|
OTEL_ERROR_STATUS_CODE,
|
|
45
45
|
REDACTED,
|
|
46
|
+
SAFE_REQUEST_ID_RE,
|
|
46
47
|
dbTraceAttributes,
|
|
47
48
|
getTracer,
|
|
48
49
|
isSensitiveKey,
|
|
@@ -54,7 +55,7 @@ import {
|
|
|
54
55
|
tracePhaseSync,
|
|
55
56
|
traceRequestId,
|
|
56
57
|
withRequestTracing
|
|
57
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-OXV2QTWV.js";
|
|
58
59
|
|
|
59
60
|
// src/backpressure.ts
|
|
60
61
|
var BackpressureSaturatedError = class extends Error {
|
|
@@ -457,6 +458,14 @@ var CLIENT_NAV_SCRIPT = `
|
|
|
457
458
|
}
|
|
458
459
|
if (push) history.pushState({ xNav: true }, "", payload.finalUrl);
|
|
459
460
|
if (doc.title) document.title = doc.title;
|
|
461
|
+
if (window.__xIslandRoots) {
|
|
462
|
+
// Must stay in sync with unmountIslandRoots() \u2014 same logic, different
|
|
463
|
+
// execution context (this is an inline script, not a module import).
|
|
464
|
+
for (var i = 0; i < window.__xIslandRoots.length; i++) {
|
|
465
|
+
try { window.__xIslandRoots[i]?.unmount(); } catch (_) {}
|
|
466
|
+
}
|
|
467
|
+
window.__xIslandRoots.length = 0;
|
|
468
|
+
}
|
|
460
469
|
root.innerHTML = next.innerHTML;
|
|
461
470
|
reexecuteScripts(root);
|
|
462
471
|
if (url.hash) {
|
|
@@ -956,6 +965,44 @@ import { existsSync as existsSync2, watch } from "fs";
|
|
|
956
965
|
import { join as join3, resolve, sep as sep2 } from "path";
|
|
957
966
|
import { createElement as createElement2 } from "react";
|
|
958
967
|
|
|
968
|
+
// src/bounded-cache.ts
|
|
969
|
+
var BoundedCache = class {
|
|
970
|
+
entries = /* @__PURE__ */ new Map();
|
|
971
|
+
maxEntries;
|
|
972
|
+
constructor(maxEntries = 500) {
|
|
973
|
+
this.maxEntries = maxEntries;
|
|
974
|
+
}
|
|
975
|
+
get(key) {
|
|
976
|
+
const value = this.entries.get(key);
|
|
977
|
+
if (value !== void 0) {
|
|
978
|
+
this.entries.delete(key);
|
|
979
|
+
this.entries.set(key, value);
|
|
980
|
+
}
|
|
981
|
+
return value;
|
|
982
|
+
}
|
|
983
|
+
set(key, value) {
|
|
984
|
+
this.entries.delete(key);
|
|
985
|
+
this.entries.set(key, value);
|
|
986
|
+
this.evict();
|
|
987
|
+
}
|
|
988
|
+
delete(key) {
|
|
989
|
+
this.entries.delete(key);
|
|
990
|
+
}
|
|
991
|
+
clear() {
|
|
992
|
+
this.entries.clear();
|
|
993
|
+
}
|
|
994
|
+
get size() {
|
|
995
|
+
return this.entries.size;
|
|
996
|
+
}
|
|
997
|
+
evict() {
|
|
998
|
+
while (this.entries.size > this.maxEntries) {
|
|
999
|
+
const oldestKey = this.entries.keys().next().value;
|
|
1000
|
+
if (oldestKey === void 0) break;
|
|
1001
|
+
this.entries.delete(oldestKey);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
|
|
959
1006
|
// src/error-overlay.ts
|
|
960
1007
|
function escapeHtml3(s) {
|
|
961
1008
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -1769,15 +1816,31 @@ function isrCacheKey(requestUrl) {
|
|
|
1769
1816
|
return url.pathname + url.search;
|
|
1770
1817
|
}
|
|
1771
1818
|
|
|
1819
|
+
// src/security/trusted-proxy.ts
|
|
1820
|
+
var trustForwardedHeaders = false;
|
|
1821
|
+
function isTrustedProxy() {
|
|
1822
|
+
return trustForwardedHeaders;
|
|
1823
|
+
}
|
|
1824
|
+
function configureTrustedProxy(options) {
|
|
1825
|
+
trustForwardedHeaders = options.trustForwardedHeaders ?? false;
|
|
1826
|
+
}
|
|
1827
|
+
function resetTrustedProxy() {
|
|
1828
|
+
trustForwardedHeaders = false;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1772
1831
|
// src/security/rate-limit.ts
|
|
1773
1832
|
function defaultKeyFn(req, server) {
|
|
1774
1833
|
if (server?.requestIP) {
|
|
1775
1834
|
const ip = server.requestIP(req);
|
|
1776
1835
|
if (ip) return ip.address;
|
|
1777
1836
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1837
|
+
if (isTrustedProxy()) {
|
|
1838
|
+
const forwarded = req.headers.get("x-forwarded-for");
|
|
1839
|
+
if (forwarded) return forwarded.split(",")[0]?.trim() ?? "unknown";
|
|
1840
|
+
const realIp = req.headers.get("x-real-ip");
|
|
1841
|
+
if (realIp) return realIp;
|
|
1842
|
+
}
|
|
1843
|
+
return "unknown";
|
|
1781
1844
|
}
|
|
1782
1845
|
function createRateLimiter(options = {}) {
|
|
1783
1846
|
const limit = options.limit ?? 60;
|
|
@@ -1975,8 +2038,10 @@ async function createApp(options) {
|
|
|
1975
2038
|
const serverFnHandler = getServerFunctionHandler(options.security?.csrf);
|
|
1976
2039
|
const staticCache = new IsrCache(500);
|
|
1977
2040
|
let actionModules = /* @__PURE__ */ new Map();
|
|
1978
|
-
const islandBundleCache =
|
|
1979
|
-
|
|
2041
|
+
const islandBundleCache = new BoundedCache(
|
|
2042
|
+
options.islandCacheMaxEntries ?? 500
|
|
2043
|
+
);
|
|
2044
|
+
const islandFileCache = new BoundedCache(options.islandCacheMaxEntries ?? 500);
|
|
1980
2045
|
async function resolveIslandScripts(routeFilePath, layoutFilePaths, entries) {
|
|
1981
2046
|
if (entries.length === 0) return [];
|
|
1982
2047
|
const uniqueNames = [...new Set(entries.map((e) => e.name))].sort();
|
|
@@ -2861,6 +2926,7 @@ function Link({ href, children, clientNav = true, prefetch = true, ...rest }) {
|
|
|
2861
2926
|
|
|
2862
2927
|
// src/security/ip.ts
|
|
2863
2928
|
function clientIpFromRequest(req) {
|
|
2929
|
+
if (!isTrustedProxy()) return null;
|
|
2864
2930
|
const forwarded = req.headers.get("x-forwarded-for");
|
|
2865
2931
|
if (forwarded) return forwarded.split(",")[0]?.trim() || null;
|
|
2866
2932
|
return req.headers.get("x-real-ip");
|
|
@@ -2886,7 +2952,10 @@ function getAuditSink() {
|
|
|
2886
2952
|
return activeSink;
|
|
2887
2953
|
}
|
|
2888
2954
|
function requestIdFromRequest(req) {
|
|
2889
|
-
|
|
2955
|
+
const raw = req.headers.get("x-request-id");
|
|
2956
|
+
if (raw === null) return void 0;
|
|
2957
|
+
if (!SAFE_REQUEST_ID_RE.test(raw)) return void 0;
|
|
2958
|
+
return raw;
|
|
2890
2959
|
}
|
|
2891
2960
|
function audit(entry) {
|
|
2892
2961
|
const redacted = {
|
|
@@ -3006,6 +3075,7 @@ export {
|
|
|
3006
3075
|
clientIpFromRequest,
|
|
3007
3076
|
combineReporters,
|
|
3008
3077
|
composeMiddleware,
|
|
3078
|
+
configureTrustedProxy,
|
|
3009
3079
|
createApp,
|
|
3010
3080
|
createBackpressureController,
|
|
3011
3081
|
createConsoleAuditSink,
|
|
@@ -3033,6 +3103,7 @@ export {
|
|
|
3033
3103
|
getTracer,
|
|
3034
3104
|
installProcessCrashHandlers,
|
|
3035
3105
|
isSensitiveKey,
|
|
3106
|
+
isTrustedProxy,
|
|
3036
3107
|
logger,
|
|
3037
3108
|
noopAuditSink,
|
|
3038
3109
|
noopMetrics,
|
|
@@ -3049,6 +3120,7 @@ export {
|
|
|
3049
3120
|
reportException,
|
|
3050
3121
|
requestIdFromRequest,
|
|
3051
3122
|
resetServerFunctions,
|
|
3123
|
+
resetTrustedProxy,
|
|
3052
3124
|
runWithRequestSpan,
|
|
3053
3125
|
scanApiDir,
|
|
3054
3126
|
scanContent,
|
package/package.json
CHANGED