@thexjs/core 1.8.2 → 1.8.4
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-3VMZCMAF.js → chunk-VGTN4YI5.js} +70 -3
- package/dist/index.d.ts +20 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/adapter.js
CHANGED
|
@@ -43,10 +43,67 @@ function findLeakedEnvKeys(code) {
|
|
|
43
43
|
}
|
|
44
44
|
return [...found];
|
|
45
45
|
}
|
|
46
|
+
var MIN_LEAKED_VALUE_LENGTH = 6;
|
|
47
|
+
var SAFE_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
48
|
+
"NODE_ENV",
|
|
49
|
+
"PWD",
|
|
50
|
+
"OLDPWD",
|
|
51
|
+
"INIT_CWD",
|
|
52
|
+
"HOSTNAME",
|
|
53
|
+
"HOME",
|
|
54
|
+
"USER",
|
|
55
|
+
"USERNAME",
|
|
56
|
+
"SHELL",
|
|
57
|
+
"LANG",
|
|
58
|
+
"LC_ALL",
|
|
59
|
+
"TERM",
|
|
60
|
+
"PATH",
|
|
61
|
+
"TMPDIR",
|
|
62
|
+
"TEMP",
|
|
63
|
+
"TMP"
|
|
64
|
+
]);
|
|
65
|
+
var SENSITIVE_KEY_PATTERNS = [
|
|
66
|
+
/SECRET/i,
|
|
67
|
+
/TOKEN/i,
|
|
68
|
+
/PASSWORD/i,
|
|
69
|
+
/PRIVATE/i,
|
|
70
|
+
/CREDENTIAL/i,
|
|
71
|
+
/API_KEY/i,
|
|
72
|
+
/_KEY$/i,
|
|
73
|
+
/AUTH/i,
|
|
74
|
+
/SALT/i,
|
|
75
|
+
/DSN/i,
|
|
76
|
+
/DATABASE_URL/i,
|
|
77
|
+
/CONNECTION_STRING/i
|
|
78
|
+
];
|
|
79
|
+
var ENV_SCAN_IGNORE_KEY = "THEXJS_ENV_SCAN_IGNORE";
|
|
80
|
+
function isSensitiveEnvKey(key) {
|
|
81
|
+
return SENSITIVE_KEY_PATTERNS.some((re) => re.test(key));
|
|
82
|
+
}
|
|
83
|
+
var MIN_RANDOM_VALUE_LENGTH = 24;
|
|
84
|
+
var RANDOM_LOOKING_VALUE_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
85
|
+
function looksRandom(value) {
|
|
86
|
+
return value.length >= MIN_RANDOM_VALUE_LENGTH && /[0-9]/.test(value) && RANDOM_LOOKING_VALUE_RE.test(value);
|
|
87
|
+
}
|
|
88
|
+
function findLeakedEnvValues(code, env) {
|
|
89
|
+
const found = /* @__PURE__ */ new Set();
|
|
90
|
+
const ignored = new Set(
|
|
91
|
+
(env[ENV_SCAN_IGNORE_KEY] ?? "").split(",").map((k) => k.trim()).filter(Boolean)
|
|
92
|
+
);
|
|
93
|
+
for (const [key, value] of Object.entries(env)) {
|
|
94
|
+
if (!value || key.startsWith(PUBLIC_ENV_PREFIX) || SAFE_ENV_KEYS.has(key)) continue;
|
|
95
|
+
if (key === ENV_SCAN_IGNORE_KEY || ignored.has(key)) continue;
|
|
96
|
+
if (value.length < MIN_LEAKED_VALUE_LENGTH) continue;
|
|
97
|
+
if (!isSensitiveEnvKey(key) && !looksRandom(value)) continue;
|
|
98
|
+
if (code.includes(value)) found.add(key);
|
|
99
|
+
}
|
|
100
|
+
return [...found];
|
|
101
|
+
}
|
|
46
102
|
var EnvLeakageError = class extends Error {
|
|
47
|
-
constructor(file, keys) {
|
|
103
|
+
constructor(file, keys, kind = "access") {
|
|
104
|
+
const detail = kind === "value" ? "its value was found literally in the bundled output (no process.env.* reference, only a value match) \u2014 track down where this string is embedded and move it out of client-shipped code" : "move this access into a loader, server function, or API route";
|
|
48
105
|
super(
|
|
49
|
-
`[x] server-only environment variable(s) leaked into client bundle "${file}": ${keys.join(", ")}. Only "${PUBLIC_ENV_PREFIX}*" variables may be referenced in client-shipped code \u2014
|
|
106
|
+
`[x] server-only environment variable(s) leaked into client bundle "${file}": ${keys.join(", ")}. Only "${PUBLIC_ENV_PREFIX}*" variables may be referenced in client-shipped code \u2014 ${detail}.`
|
|
50
107
|
);
|
|
51
108
|
this.file = file;
|
|
52
109
|
this.keys = keys;
|
|
@@ -58,7 +115,13 @@ var EnvLeakageError = class extends Error {
|
|
|
58
115
|
function assertNoEnvLeakage(code, file) {
|
|
59
116
|
const leaked = findLeakedEnvKeys(code);
|
|
60
117
|
if (leaked.length > 0) {
|
|
61
|
-
throw new EnvLeakageError(file, leaked);
|
|
118
|
+
throw new EnvLeakageError(file, leaked, "access");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function assertNoEnvValueLeakage(code, file, env) {
|
|
122
|
+
const leaked = findLeakedEnvValues(code, env);
|
|
123
|
+
if (leaked.length > 0) {
|
|
124
|
+
throw new EnvLeakageError(file, leaked, "value");
|
|
62
125
|
}
|
|
63
126
|
}
|
|
64
127
|
|
|
@@ -713,6 +776,7 @@ async function buildIslandBundleInMemory(routeFilePath, layoutFilePaths, islandN
|
|
|
713
776
|
const result = await Bun.build({
|
|
714
777
|
entrypoints: [entryPath],
|
|
715
778
|
target: "browser",
|
|
779
|
+
env: "disable",
|
|
716
780
|
plugins: [actionsRewritePlugin(actionModules)]
|
|
717
781
|
});
|
|
718
782
|
if (!result.success) {
|
|
@@ -726,6 +790,7 @@ async function buildIslandBundleInMemory(routeFilePath, layoutFilePaths, islandN
|
|
|
726
790
|
if (!built) return wrapIslandBundle(generateFallbackHydration(islandNames));
|
|
727
791
|
const code = await built.text();
|
|
728
792
|
assertNoEnvLeakage(code, entryPath);
|
|
793
|
+
assertNoEnvValueLeakage(code, entryPath, process.env);
|
|
729
794
|
return wrapIslandBundle(code);
|
|
730
795
|
} catch (err) {
|
|
731
796
|
if (err instanceof EnvLeakageError) {
|
|
@@ -753,6 +818,7 @@ async function bundleRouteIslandsToDisk(routeFilePath, layoutFilePaths, islandNa
|
|
|
753
818
|
const result = await Bun.build({
|
|
754
819
|
entrypoints: [entryPath],
|
|
755
820
|
target: "browser",
|
|
821
|
+
env: "disable",
|
|
756
822
|
plugins: [actionsRewritePlugin(actionModules)]
|
|
757
823
|
});
|
|
758
824
|
if (result.success) {
|
|
@@ -761,6 +827,7 @@ async function bundleRouteIslandsToDisk(routeFilePath, layoutFilePaths, islandNa
|
|
|
761
827
|
if (built) {
|
|
762
828
|
const code = await built.text();
|
|
763
829
|
assertNoEnvLeakage(code, bundlePath);
|
|
830
|
+
assertNoEnvValueLeakage(code, bundlePath, process.env);
|
|
764
831
|
writeFileSync3(bundlePath, wrapIslandBundle(code), "utf-8");
|
|
765
832
|
return [`/_islands/${entryId}/${entryId}.js`];
|
|
766
833
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1028,6 +1028,25 @@ declare function enforceRequestBodySize(req: Request, maxBytes: number): Request
|
|
|
1028
1028
|
* bundle is a build error, not a warning — secrets like `STRIPE_SECRET_KEY`
|
|
1029
1029
|
* or `DATABASE_URL` must never round-trip through the bundler into
|
|
1030
1030
|
* browser-shipped JS.
|
|
1031
|
+
*
|
|
1032
|
+
* Two layers of defense, run together at every client-bundle call site:
|
|
1033
|
+
* - `findLeakedEnvKeys` / `assertNoEnvLeakage`: a static scan for the
|
|
1034
|
+
* *syntax* `process.env.X` (and the `Bun.env` / `import.meta.env`
|
|
1035
|
+
* equivalents) in the bundled output. This is what catches a leak today,
|
|
1036
|
+
* since the pinned Bun toolchain preserves that syntax rather than
|
|
1037
|
+
* inlining it.
|
|
1038
|
+
* - `findLeakedEnvValues`: a scan for the literal serialized *value* of any
|
|
1039
|
+
* non-public env var in the bundled output, regardless of what syntax (if
|
|
1040
|
+
* any) produced it. This exists so a future bundler/config change that
|
|
1041
|
+
* inlines `process.env.X` into a string literal — which would make the
|
|
1042
|
+
* key-scan above match nothing — still gets caught. Restricted to
|
|
1043
|
+
* sensitive-looking names/values (see `isSensitiveEnvKey` / `looksRandom`)
|
|
1044
|
+
* so ordinary values like `VERCEL_ENV=production` don't fail real builds
|
|
1045
|
+
* just because the word "production" also appears somewhere in the
|
|
1046
|
+
* bundle.
|
|
1047
|
+
* Neither catches a value that a build plugin re-encodes (e.g. base64,
|
|
1048
|
+
* concatenation) before it lands in the bundle; that's a known gap, not a
|
|
1049
|
+
* silent one, since both scans run on the final emitted text.
|
|
1031
1050
|
*/
|
|
1032
1051
|
declare const PUBLIC_ENV_PREFIX = "THEXJS_PUBLIC_";
|
|
1033
1052
|
/**
|
|
@@ -1039,7 +1058,7 @@ declare function findLeakedEnvKeys(code: string): string[];
|
|
|
1039
1058
|
declare class EnvLeakageError extends Error {
|
|
1040
1059
|
readonly file: string;
|
|
1041
1060
|
readonly keys: string[];
|
|
1042
|
-
constructor(file: string, keys: string[]);
|
|
1061
|
+
constructor(file: string, keys: string[], kind?: "access" | "value");
|
|
1043
1062
|
}
|
|
1044
1063
|
/** Throws EnvLeakageError if the given bundle source references non-public env vars. */
|
|
1045
1064
|
declare function assertNoEnvLeakage(code: string, file: string): void;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thexjs/core",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
4
4
|
"description": "Full-stack React framework core (router, SSR/SSG renderer, islands, server functions) for the x framework, built on Bun.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.0.0",
|
|
56
|
-
"@types/react-dom": "^19.
|
|
56
|
+
"@types/react-dom": "^19.2.5",
|
|
57
57
|
"tsup": "^8.3.0"
|
|
58
58
|
}
|
|
59
59
|
}
|