unpeek 4.0.0 → 4.0.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/README.md +7 -6
- package/README.tr.md +6 -5
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +5 -5
- package/dist/adapters/next/adapter.js +4 -4
- package/dist/adapters/next/index.cjs +5 -5
- package/dist/adapters/next/index.js +4 -4
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.js +3 -3
- package/dist/browser.cjs +2 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-3LWXEJU6.cjs → chunk-3GDHYBVH.cjs} +56 -18
- package/dist/{chunk-YCRMTXOE.js → chunk-4G2HCME5.js} +2 -2
- package/dist/{chunk-2JU3V7HW.js → chunk-4SOS3LRV.js} +50 -9
- package/dist/{chunk-7HXLHLLQ.cjs → chunk-7ZEVJ4OR.cjs} +121 -29
- package/dist/{chunk-4FNZNIBW.js → chunk-LGTXAAZH.js} +686 -344
- package/dist/{chunk-KLYFNMKS.cjs → chunk-M46SFJE7.cjs} +813 -471
- package/dist/{chunk-ZG7BIAUI.cjs → chunk-NNAAPDUS.cjs} +58 -17
- package/dist/{chunk-VG4Y26ZN.cjs → chunk-OTA75YI6.cjs} +14 -14
- package/dist/{chunk-ADKRENAP.js → chunk-TYL32LUK.js} +46 -8
- package/dist/{chunk-HHC7BUCK.js → chunk-XYN5NYSD.js} +95 -3
- package/dist/cli/index.js +921 -372
- package/dist/index.cjs +184 -45
- package/dist/index.js +170 -31
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -80,6 +80,28 @@ function hasNextServerSegment(fullPath, rootDir, serverDirPrefixes) {
|
|
|
80
80
|
}
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
|
+
function hasJsBundleFiles(dir) {
|
|
84
|
+
if (!fs.existsSync(dir)) return false;
|
|
85
|
+
let entries;
|
|
86
|
+
try {
|
|
87
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
for (const entry of entries) {
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
if (EXCLUDED_DIR_NAMES.has(entry.name.toLowerCase())) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (hasJsBundleFiles(path.join(dir, entry.name))) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
} else if (entry.isFile() && SUPPORTED_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
83
105
|
function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
84
106
|
let config = explicitConfig;
|
|
85
107
|
let outDirOverride;
|
|
@@ -130,16 +152,18 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
130
152
|
}
|
|
131
153
|
}
|
|
132
154
|
}
|
|
133
|
-
const
|
|
155
|
+
const nextStaticDir = path.join(rootDir, nextDist, "static");
|
|
156
|
+
const nextChunksDir = path.join(nextStaticDir, "chunks");
|
|
134
157
|
const nextExportChunksDir = path.join(rootDir, "out", "_next", "static", "chunks");
|
|
135
158
|
const nextExportDir = path.join(rootDir, "out");
|
|
136
159
|
const nextDistDir = path.join(rootDir, nextDist);
|
|
160
|
+
const vercelNextStaticDir = path.join(rootDir, ".vercel", "output", "static", "_next", "static");
|
|
137
161
|
const distAssetsDir = path.join(rootDir, viteOut, viteAssets);
|
|
138
162
|
const distDir = path.join(rootDir, viteOut);
|
|
139
163
|
const buildDir = path.join(rootDir, "build");
|
|
140
164
|
const publicDir = path.join(rootDir, "public");
|
|
141
165
|
if (!framework) {
|
|
142
|
-
if (fs.existsSync(nextChunksDir) || fs.existsSync(nextDistDir) || fs.existsSync(nextExportChunksDir) || discoveredNextDist !== void 0) {
|
|
166
|
+
if (fs.existsSync(nextChunksDir) || fs.existsSync(nextDistDir) || fs.existsSync(nextExportChunksDir) || fs.existsSync(vercelNextStaticDir) || discoveredNextDist !== void 0) {
|
|
143
167
|
framework = "nextjs";
|
|
144
168
|
} else if (fs.existsSync(distAssetsDir) || discoveredViteOut !== void 0) {
|
|
145
169
|
framework = "vite";
|
|
@@ -147,7 +171,7 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
147
171
|
framework = "webpack";
|
|
148
172
|
} else if (outDirOverride) {
|
|
149
173
|
const normExplicit = outDirOverride.replace(/\\/g, "/");
|
|
150
|
-
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next")) {
|
|
174
|
+
if (normExplicit.includes(nextDist) || normExplicit.includes(".next") || normExplicit.includes("out/_next") || normExplicit.includes("_next/static")) {
|
|
151
175
|
framework = "nextjs";
|
|
152
176
|
} else if (normExplicit.includes(`${viteOut}/${viteAssets}`) || normExplicit.includes("dist/assets")) {
|
|
153
177
|
framework = "vite";
|
|
@@ -170,6 +194,12 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
170
194
|
if (framework === "nextjs") {
|
|
171
195
|
if (fs.existsSync(nextExportChunksDir)) {
|
|
172
196
|
outDir = nextExportChunksDir;
|
|
197
|
+
} else if (fs.existsSync(nextChunksDir) && hasJsBundleFiles(nextChunksDir)) {
|
|
198
|
+
outDir = nextChunksDir;
|
|
199
|
+
} else if (fs.existsSync(nextStaticDir) && hasJsBundleFiles(nextStaticDir)) {
|
|
200
|
+
outDir = nextStaticDir;
|
|
201
|
+
} else if (fs.existsSync(vercelNextStaticDir)) {
|
|
202
|
+
outDir = vercelNextStaticDir;
|
|
173
203
|
} else if (fs.existsSync(nextChunksDir)) {
|
|
174
204
|
outDir = nextChunksDir;
|
|
175
205
|
} else if (fs.existsSync(nextExportDir)) {
|
|
@@ -190,7 +220,15 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
190
220
|
outDir = distDir;
|
|
191
221
|
}
|
|
192
222
|
} else {
|
|
193
|
-
const candidates = [
|
|
223
|
+
const candidates = [
|
|
224
|
+
nextExportChunksDir,
|
|
225
|
+
nextChunksDir,
|
|
226
|
+
vercelNextStaticDir,
|
|
227
|
+
distAssetsDir,
|
|
228
|
+
distDir,
|
|
229
|
+
buildDir,
|
|
230
|
+
publicDir
|
|
231
|
+
];
|
|
194
232
|
const existing = candidates.find((candidate) => fs.existsSync(candidate));
|
|
195
233
|
outDir = existing ?? distDir;
|
|
196
234
|
}
|
|
@@ -448,6 +486,8 @@ function initProject(cwd = process.cwd(), options = {}) {
|
|
|
448
486
|
import fs6 from "fs";
|
|
449
487
|
import path5 from "path";
|
|
450
488
|
import zlib from "zlib";
|
|
489
|
+
import * as acorn7 from "acorn";
|
|
490
|
+
import { simple as walkSimple } from "acorn-walk";
|
|
451
491
|
|
|
452
492
|
// src/internal/config.ts
|
|
453
493
|
import fs3, { existsSync, readFileSync } from "fs";
|
|
@@ -1753,6 +1793,8 @@ var DEFAULT_HOC_WRAPPERS = /* @__PURE__ */ new Set([
|
|
|
1753
1793
|
"connect"
|
|
1754
1794
|
]);
|
|
1755
1795
|
var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Animate|Physics)[A-Z]/;
|
|
1796
|
+
var CRITICAL_COLD_HANDLER_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout)$/i;
|
|
1797
|
+
var CRITICAL_COLD_CALLEE_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout|createServerReference|fetch)$/i;
|
|
1756
1798
|
var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
|
|
1757
1799
|
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
1758
1800
|
"useState",
|
|
@@ -2538,6 +2580,26 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2538
2580
|
}
|
|
2539
2581
|
}
|
|
2540
2582
|
}
|
|
2583
|
+
for (const fn of allFunctions) {
|
|
2584
|
+
if (!serializedWorkerNodes.has(fn.node) && !trueHotNodes.has(fn.node) && !shallowComponentNodes.has(fn.node) && !containsLoopOrAnimation(fn.node, animationCalls)) {
|
|
2585
|
+
let isCriticalHandler = CRITICAL_COLD_HANDLER_REGEX.test(fn.name);
|
|
2586
|
+
if (!isCriticalHandler) {
|
|
2587
|
+
const callees = callerToCallees.get(fn.node);
|
|
2588
|
+
if (callees) {
|
|
2589
|
+
for (const cName of callees) {
|
|
2590
|
+
const bare = cName.includes(".") ? cName.split(".").pop() : cName;
|
|
2591
|
+
if (CRITICAL_COLD_CALLEE_REGEX.test(bare)) {
|
|
2592
|
+
isCriticalHandler = true;
|
|
2593
|
+
break;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
if (isCriticalHandler) {
|
|
2599
|
+
coldForcedNodes.add(fn.node);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2541
2603
|
const calleeToCallers = /* @__PURE__ */ new Map();
|
|
2542
2604
|
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
2543
2605
|
for (const cName of calleeNames) {
|
|
@@ -2579,9 +2641,10 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2579
2641
|
hotFunctionNodes.delete(node);
|
|
2580
2642
|
hotExemptNodes.delete(node);
|
|
2581
2643
|
}
|
|
2644
|
+
const criticalAnnotation = typeof config?.critical?.annotation === "string" && config.critical.annotation.length > 0 ? config.critical.annotation : "@unpeek-critical";
|
|
2582
2645
|
const astComments = ast?.__unpeekComments ?? ast?.comments ?? [];
|
|
2583
2646
|
const criticalComments = astComments.filter(
|
|
2584
|
-
(c) => typeof c?.value === "string" && c.value.includes(
|
|
2647
|
+
(c) => typeof c?.value === "string" && c.value.includes(criticalAnnotation)
|
|
2585
2648
|
);
|
|
2586
2649
|
const criticalCommentNodes = /* @__PURE__ */ new Set();
|
|
2587
2650
|
if (criticalComments.length > 0 && allFunctions.length > 0) {
|
|
@@ -2695,24 +2758,25 @@ var DISALLOWED_IDENTS = /* @__PURE__ */ new Set([
|
|
|
2695
2758
|
function derivePolymorphicIdent(seed, role) {
|
|
2696
2759
|
let h = (2166136261 ^ seed >>> 0) >>> 0;
|
|
2697
2760
|
for (let i = 0; i < role.length; i++) {
|
|
2698
|
-
h
|
|
2761
|
+
h = (h ^ role.charCodeAt(i)) >>> 0;
|
|
2699
2762
|
h = Math.imul(h, 16777619) >>> 0;
|
|
2700
2763
|
}
|
|
2701
|
-
h
|
|
2764
|
+
h = (h ^ h >>> 16) >>> 0;
|
|
2702
2765
|
h = Math.imul(h, 2246822507) >>> 0;
|
|
2703
|
-
h
|
|
2766
|
+
h = (h ^ h >>> 13) >>> 0;
|
|
2704
2767
|
h = Math.imul(h, 3266489909) >>> 0;
|
|
2705
|
-
h
|
|
2768
|
+
h = (h ^ h >>> 16) >>> 0;
|
|
2706
2769
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
2707
|
-
const
|
|
2708
|
-
const
|
|
2709
|
-
const
|
|
2710
|
-
const
|
|
2770
|
+
const u = h >>> 0;
|
|
2771
|
+
const c0 = IDENT_START_CHARS[u % IDENT_START_CHARS.length];
|
|
2772
|
+
const c1 = IDENT_CONT_CHARS[(u >>> 6) % IDENT_CONT_CHARS.length];
|
|
2773
|
+
const c2 = IDENT_CONT_CHARS[(u >>> 12) % IDENT_CONT_CHARS.length];
|
|
2774
|
+
const c3 = IDENT_CONT_CHARS[(u >>> 18) % IDENT_CONT_CHARS.length];
|
|
2711
2775
|
const ident = `${c0}${c1}${c2}${c3}`;
|
|
2712
2776
|
if (!DISALLOWED_IDENTS.has(ident) && !ident.startsWith("__") && !ident.startsWith("_u") && !ident.startsWith("_0")) {
|
|
2713
2777
|
return ident;
|
|
2714
2778
|
}
|
|
2715
|
-
h = Math.imul(
|
|
2779
|
+
h = Math.imul(u ^ 2654435769 + attempt, 2246822507) >>> 0;
|
|
2716
2780
|
}
|
|
2717
2781
|
return `_${(h >>> 0).toString(36).slice(0, 3).padStart(3, "0")}`;
|
|
2718
2782
|
}
|
|
@@ -3351,13 +3415,12 @@ function createDeterrentSnippet(config) {
|
|
|
3351
3415
|
const detectHeadless = config.detectHeadless ?? false;
|
|
3352
3416
|
const fnName = deriveIntegrityFnName(seed);
|
|
3353
3417
|
const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
3354
|
-
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=
|
|
3418
|
+
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
|
|
3355
3419
|
const symLit = JSON.stringify(sym);
|
|
3356
|
-
const stateLit = JSON.stringify(`${sym}_s`);
|
|
3357
3420
|
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
3358
3421
|
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
3359
3422
|
const k1Mul = (seed | 1) >>> 0;
|
|
3360
|
-
return `(function ${fnName}(w){var G=
|
|
3423
|
+
return `(function ${fnName}(w){var G=globalThis||w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,RF=G.Reflect,R=RF&&RF.apply,FP=Function.prototype,SP=String.prototype,Q='__unpeek_',y=${symLit},z=y+'_s',U='__unpeek_tampered',K=Q+'seed',T=(o,k)=>{try{for(var r;o;o=O.getPrototypeOf(o))if((r=P(o,k))&&(r.set||!r.writable))return 1;}catch(e){return 1;}},D=k=>T(w,k)|T(G,k),B=(k,v,c,W)=>{W=o=>{try{if(!c||!T(o,k))o[k]=v;}catch(e){}};W(G);W(w);},s=FP.toString${headlessDecl},src='',t=+((G[z]||w[z])?.[0]==2);try{var ps,E=(f,a,b)=>{try{R(f,a,b);t=1;}catch(e){t|=e?.name!='TypeError'||/\\n at (?!.* \\(<anonymous>\\)$)/m.test(e?.stack?.split('\\n at E (')[0]);}},F=(f,n,l)=>typeof f!='function'||'prototype'in f||f.name!=n||f.length!=l||/^function (\\w+)\\(\\)\\s*\\x7b\\s*\\[native code\\]\\s*}$/.exec(R(R,null,[s,f,[]]))?.[1]!=n;E(P,null,[]);E(s,{toString(){}},[]);E(R,s,[null,s,[]]);src=R(s,${fnName},[]);t|=F(R,'apply',3)|F(s,'toString',0)|s.call(T)!==(ps=R(s,T,[]))|FP.call.call(s,T)!==ps|/\\n/.test(src)${headlessCond};}catch(e){t=1;}t|=D(y)|D(z)|D(U)|T(SP,'_u')|T(FP,'toString')|T(FP,'call')|T(RF,'apply');for(var h=2166136261,i=0;i<src.length;)h=Math.imul(h^src.charCodeAt(i++),16777619);var d=h&65535,pd=t?d^((h>>>16^23131)||1):d;B(z,[t+1,h^${seed}^t,h^${k1Mul}^t,1,d^h>>>16],t);B(y,pd,t);if(t){B(y+'_t',!0);B(Q+'delta',pd);try{SP._u=14;}catch(e){}B(K,((w[K]||${seed})^1)>>>0);B(U,!0);try{${consoleSilence}w.dispatchEvent?.(new CustomEvent('unpeek:tamper'));}catch(e){}}}})(typeof window!=='undefined'?window:typeof self<'u'?self:typeof globalThis<'u'?globalThis:0);`;
|
|
3361
3424
|
}
|
|
3362
3425
|
|
|
3363
3426
|
// src/runtime/index.ts
|
|
@@ -4185,6 +4248,43 @@ function exemptWebpackPushArg(arg, exemptSubtreeRoots) {
|
|
|
4185
4248
|
}
|
|
4186
4249
|
exemptSubtreeRoots.add(arg);
|
|
4187
4250
|
}
|
|
4251
|
+
function exemptTurbopackPropertyKeys(objNode, exemptSubtreeRoots) {
|
|
4252
|
+
if (!Array.isArray(objNode?.properties)) return;
|
|
4253
|
+
for (const prop of objNode.properties) {
|
|
4254
|
+
if (prop?.type === "Property" && prop.key && typeof prop.key === "object") {
|
|
4255
|
+
exemptSubtreeRoots.add(prop.key);
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
function exemptTurbopackPushArg(arg, exemptSubtreeRoots) {
|
|
4260
|
+
if (!arg || typeof arg !== "object") return;
|
|
4261
|
+
if (arg.type === "ArrayExpression" && Array.isArray(arg.elements)) {
|
|
4262
|
+
for (let i = 0; i < arg.elements.length; i++) {
|
|
4263
|
+
const el = arg.elements[i];
|
|
4264
|
+
if (!el || typeof el !== "object") continue;
|
|
4265
|
+
if (i === 0) {
|
|
4266
|
+
exemptSubtreeRoots.add(el);
|
|
4267
|
+
continue;
|
|
4268
|
+
}
|
|
4269
|
+
if (el.type === "Literal") {
|
|
4270
|
+
exemptSubtreeRoots.add(el);
|
|
4271
|
+
} else if (el.type === "ObjectExpression") {
|
|
4272
|
+
exemptTurbopackPropertyKeys(el, exemptSubtreeRoots);
|
|
4273
|
+
} else if (el.type === "FunctionExpression" || el.type === "ArrowFunctionExpression") {
|
|
4274
|
+
continue;
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
return;
|
|
4278
|
+
}
|
|
4279
|
+
if (arg.type === "ObjectExpression") {
|
|
4280
|
+
exemptTurbopackPropertyKeys(arg, exemptSubtreeRoots);
|
|
4281
|
+
return;
|
|
4282
|
+
}
|
|
4283
|
+
if (arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression") {
|
|
4284
|
+
return;
|
|
4285
|
+
}
|
|
4286
|
+
exemptSubtreeRoots.add(arg);
|
|
4287
|
+
}
|
|
4188
4288
|
function isHostMember(node, matcher) {
|
|
4189
4289
|
if (!node) return false;
|
|
4190
4290
|
if (node.type === "Identifier" && matchesPropName(node.name, matcher)) {
|
|
@@ -4243,12 +4343,13 @@ function classifyChunkBoundary(ast) {
|
|
|
4243
4343
|
}
|
|
4244
4344
|
} else if (unwrapAssignedHostMember(callee.object, "TURBOPACK")) {
|
|
4245
4345
|
hasEntryBootstrap = true;
|
|
4246
|
-
exemptSubtreeRoots.add(
|
|
4346
|
+
exemptSubtreeRoots.add(callee);
|
|
4347
|
+
if (callee.object && typeof callee.object === "object") {
|
|
4348
|
+
exemptSubtreeRoots.add(callee.object);
|
|
4349
|
+
}
|
|
4247
4350
|
if (Array.isArray(node.arguments)) {
|
|
4248
4351
|
for (const arg of node.arguments) {
|
|
4249
|
-
|
|
4250
|
-
exemptSubtreeRoots.add(arg);
|
|
4251
|
-
}
|
|
4352
|
+
exemptTurbopackPushArg(arg, exemptSubtreeRoots);
|
|
4252
4353
|
}
|
|
4253
4354
|
}
|
|
4254
4355
|
} else if (unwrapAssignedHostMember(callee.object, isWebpackOrRspackChunkName)) {
|
|
@@ -4371,7 +4472,10 @@ function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol
|
|
|
4371
4472
|
fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||a._u||0)!==0);if(!tm&&(i in m))return m[i];var d=tm?(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1):0;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm)m[i]=o;return o;};`;
|
|
4372
4473
|
} else {
|
|
4373
4474
|
const edInit = buildRivestDeltaExpr(seed, expectedDelta, "_ed");
|
|
4374
|
-
|
|
4475
|
+
const hasWindowKey = Boolean(windowKeySymbol);
|
|
4476
|
+
const brDecl = hasWindowKey ? `var _br=typeof window<"u"||typeof document<"u"||typeof self<"u";` : "";
|
|
4477
|
+
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4478
|
+
fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";${edInit}return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||a._u||0)!==0)||${svCheck};if(!tm&&sv===_ed&&(i in m))return m[i];var d=tm?((_ed^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))&65535):_ed;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm&&sv===_ed)m[i]=o;return o;};`;
|
|
4375
4479
|
}
|
|
4376
4480
|
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
4377
4481
|
ecmaVersion: "latest",
|
|
@@ -4420,7 +4524,7 @@ function isAstAlreadySalted(ast) {
|
|
|
4420
4524
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
4421
4525
|
return ast.body.some((stmt) => {
|
|
4422
4526
|
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
4423
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
4527
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uP") || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression")
|
|
4424
4528
|
)) {
|
|
4425
4529
|
return true;
|
|
4426
4530
|
}
|
|
@@ -4451,7 +4555,8 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4451
4555
|
encryptedStringsCount: 0,
|
|
4452
4556
|
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
4453
4557
|
vaultVarName: "",
|
|
4454
|
-
decryptFnName: ""
|
|
4558
|
+
decryptFnName: "",
|
|
4559
|
+
shaderBuffersCount: 0
|
|
4455
4560
|
};
|
|
4456
4561
|
}
|
|
4457
4562
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
@@ -4464,154 +4569,239 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4464
4569
|
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
4465
4570
|
const targetsToReplace = [];
|
|
4466
4571
|
const encryptedPayloads = [];
|
|
4572
|
+
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
4573
|
+
const shaderPayloads = [];
|
|
4574
|
+
const shaderTargets = [];
|
|
4575
|
+
function processSaltedCandidate(val, node, parent, ancestors) {
|
|
4576
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4577
|
+
return;
|
|
4578
|
+
}
|
|
4579
|
+
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4580
|
+
return;
|
|
4581
|
+
}
|
|
4582
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4583
|
+
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
let isHotExempt = false;
|
|
4588
|
+
if (hotExemptNodes) {
|
|
4589
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4590
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
4591
|
+
isHotExempt = true;
|
|
4592
|
+
break;
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
if (isShaderPayload(
|
|
4597
|
+
val,
|
|
4598
|
+
node,
|
|
4599
|
+
parent,
|
|
4600
|
+
ancestors,
|
|
4601
|
+
seed,
|
|
4602
|
+
isHotExempt,
|
|
4603
|
+
customReserved
|
|
4604
|
+
)) {
|
|
4605
|
+
let idx = shaderToIndex.get(val);
|
|
4606
|
+
if (idx === void 0) {
|
|
4607
|
+
idx = shaderPayloads.length;
|
|
4608
|
+
shaderToIndex.set(val, idx);
|
|
4609
|
+
shaderPayloads.push(val);
|
|
4610
|
+
}
|
|
4611
|
+
shaderTargets.push({ node, parent, idx });
|
|
4612
|
+
return;
|
|
4613
|
+
}
|
|
4614
|
+
if (isHotExempt) {
|
|
4615
|
+
return;
|
|
4616
|
+
}
|
|
4617
|
+
if (!shouldEncryptString(
|
|
4618
|
+
val,
|
|
4619
|
+
minLen,
|
|
4620
|
+
parent,
|
|
4621
|
+
activeDirectives,
|
|
4622
|
+
customReserved
|
|
4623
|
+
)) {
|
|
4624
|
+
return;
|
|
4625
|
+
}
|
|
4626
|
+
const callSiteIdx = targetsToReplace.length;
|
|
4627
|
+
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
4628
|
+
seed >>> 0,
|
|
4629
|
+
callSiteIdx >>> 0,
|
|
4630
|
+
seed >>> 0
|
|
4631
|
+
);
|
|
4632
|
+
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4633
|
+
targetsToReplace.push({
|
|
4634
|
+
node,
|
|
4635
|
+
parent,
|
|
4636
|
+
callSiteIdx,
|
|
4637
|
+
localSalt,
|
|
4638
|
+
rawString: val
|
|
4639
|
+
});
|
|
4640
|
+
}
|
|
4467
4641
|
walk3.ancestor(ast, {
|
|
4468
4642
|
Literal(node, ancestors) {
|
|
4469
4643
|
if (typeof node.value !== "string") return;
|
|
4470
|
-
|
|
4471
|
-
if (activeDirectives.has(
|
|
4644
|
+
const val = node.value;
|
|
4645
|
+
if (activeDirectives.has(val)) return;
|
|
4472
4646
|
const parent = ancestors[ancestors.length - 2];
|
|
4473
4647
|
if (!parent) return;
|
|
4474
|
-
if (
|
|
4648
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
|
|
4475
4649
|
return;
|
|
4476
4650
|
}
|
|
4477
|
-
if (parent.type === "
|
|
4651
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
4478
4652
|
return;
|
|
4479
4653
|
}
|
|
4480
|
-
|
|
4481
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4482
|
-
return;
|
|
4483
|
-
}
|
|
4484
|
-
}
|
|
4485
|
-
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
|
|
4654
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
4486
4655
|
return;
|
|
4487
4656
|
}
|
|
4488
|
-
if (parent.type === "
|
|
4657
|
+
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
4489
4658
|
return;
|
|
4490
4659
|
}
|
|
4491
|
-
|
|
4660
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4661
|
+
},
|
|
4662
|
+
TemplateLiteral(node, ancestors) {
|
|
4663
|
+
if (!node.quasis || node.quasis.length !== 1) return;
|
|
4664
|
+
if (node.expressions && node.expressions.length !== 0) return;
|
|
4665
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
4666
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
4667
|
+
const parent = ancestors[ancestors.length - 2];
|
|
4668
|
+
if (!parent) return;
|
|
4669
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
4492
4670
|
return;
|
|
4493
4671
|
}
|
|
4494
|
-
if (
|
|
4495
|
-
|
|
4496
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
4497
|
-
return;
|
|
4498
|
-
}
|
|
4499
|
-
}
|
|
4672
|
+
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
4673
|
+
return;
|
|
4500
4674
|
}
|
|
4501
|
-
|
|
4502
|
-
if (isTailwindNoise(node.value)) return;
|
|
4503
|
-
if (isSvgPathString(node.value, parent)) return;
|
|
4504
|
-
const callSiteIdx = targetsToReplace.length;
|
|
4505
|
-
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
4506
|
-
seed >>> 0,
|
|
4507
|
-
callSiteIdx >>> 0,
|
|
4508
|
-
seed >>> 0
|
|
4509
|
-
);
|
|
4510
|
-
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4511
|
-
targetsToReplace.push({
|
|
4512
|
-
node,
|
|
4513
|
-
parent,
|
|
4514
|
-
callSiteIdx,
|
|
4515
|
-
localSalt,
|
|
4516
|
-
rawString: node.value
|
|
4517
|
-
});
|
|
4675
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4518
4676
|
}
|
|
4519
4677
|
});
|
|
4520
|
-
if (targetsToReplace.length === 0) {
|
|
4678
|
+
if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
|
|
4521
4679
|
return {
|
|
4522
4680
|
encryptedStringsCount: 0,
|
|
4523
4681
|
integrityToken: computeFnv1aHash("empty-salted", seed),
|
|
4524
4682
|
vaultVarName: "",
|
|
4525
|
-
decryptFnName: ""
|
|
4683
|
+
decryptFnName: "",
|
|
4684
|
+
shaderBuffersCount: 0
|
|
4526
4685
|
};
|
|
4527
4686
|
}
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4687
|
+
let vaultVarName = "";
|
|
4688
|
+
let decryptFnName = "";
|
|
4689
|
+
let integrityToken = computeFnv1aHash("empty-salted", seed);
|
|
4690
|
+
if (targetsToReplace.length > 0) {
|
|
4691
|
+
const wasmResult = injectWasmVault(ast, seed);
|
|
4692
|
+
const kdfFnName = wasmResult.kdfFnName;
|
|
4693
|
+
const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
|
|
4694
|
+
vaultVarName = `_uP${suffix}`;
|
|
4695
|
+
const cacheVarName = `_uCache${suffix}`;
|
|
4696
|
+
const dCacheVarName = `_uDc${suffix}`;
|
|
4697
|
+
decryptFnName = `_uD${suffix}`;
|
|
4698
|
+
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
4699
|
+
let expDelta = expectedDelta;
|
|
4700
|
+
if (shieldCoupled && expDelta === void 0) {
|
|
4701
|
+
const shield = generateRuntimeShield({
|
|
4702
|
+
seed,
|
|
4703
|
+
windowKeySymbol: sym,
|
|
4704
|
+
deterrentMode: deterrentMode ?? "passive",
|
|
4705
|
+
detectHeadless
|
|
4706
|
+
});
|
|
4707
|
+
expDelta = shield.expectedDelta ?? 0;
|
|
4708
|
+
}
|
|
4709
|
+
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
|
|
4710
|
+
const stateSym = `${sym}_s`;
|
|
4711
|
+
const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
|
|
4712
|
+
const flagSym = `${sym}_t`;
|
|
4713
|
+
const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
|
|
4714
|
+
const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
|
|
4715
|
+
const dkExpr = `['__','unp','eek_d','elta'].join('')`;
|
|
4716
|
+
let helperFnSnippet;
|
|
4717
|
+
if (!shieldCoupled) {
|
|
4718
|
+
helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=h|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm)${cacheVarName}[i]=o;return o;}`;
|
|
4719
|
+
} else {
|
|
4720
|
+
const edInit = buildRivestDeltaExpr(seed, (expDelta ?? 0) & 65535, "_ed");
|
|
4721
|
+
const hasWindowKey = Boolean(sym);
|
|
4722
|
+
const brDecl = hasWindowKey ? `var _br=typeof window<"u"||typeof document<"u"||typeof self<"u";` : "";
|
|
4723
|
+
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4724
|
+
helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};${edInit}` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(dv!==0)||${svCheck};if(!tm&&sv===_ed&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=((h|0)^_ed)|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm&&sv===_ed)${cacheVarName}[i]=o;return o;}`;
|
|
4725
|
+
}
|
|
4726
|
+
const parsedFn = acorn3.parse(helperFnSnippet, {
|
|
4727
|
+
ecmaVersion: "latest",
|
|
4728
|
+
sourceType: "script"
|
|
4543
4729
|
});
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=h|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm)${cacheVarName}[i]=o;return o;}`;
|
|
4556
|
-
} else {
|
|
4557
|
-
const edInit = buildRivestDeltaExpr(seed, (expDelta ?? 0) & 65535, "_ed");
|
|
4558
|
-
helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};${edInit}var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(dv!==0)||(sv!==void 0&&sv!==_ed);if(!tm&&sv===_ed&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=((h|0)^_ed)|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm&&sv===_ed)${cacheVarName}[i]=o;return o;}`;
|
|
4559
|
-
}
|
|
4560
|
-
const parsedFn = acorn3.parse(helperFnSnippet, {
|
|
4561
|
-
ecmaVersion: "latest",
|
|
4562
|
-
sourceType: "script"
|
|
4563
|
-
});
|
|
4564
|
-
const fnDeclAst = parsedFn.body[0];
|
|
4565
|
-
const selfHash = computeFnv1aHash(generateCompactJs(fnDeclAst)) | 0;
|
|
4566
|
-
const buildD = shieldCoupled ? selfHash ^ (expDelta ?? 0) & 65535 | 0 : selfHash | 0;
|
|
4567
|
-
for (const target of targetsToReplace) {
|
|
4568
|
-
const k = fallbackKdf(target.callSiteIdx, target.localSalt, buildD, seed);
|
|
4569
|
-
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
4570
|
-
const callExpr = {
|
|
4571
|
-
type: "CallExpression",
|
|
4572
|
-
callee: {
|
|
4573
|
-
type: "Identifier",
|
|
4574
|
-
name: decryptFnName
|
|
4575
|
-
},
|
|
4576
|
-
arguments: [
|
|
4577
|
-
{
|
|
4578
|
-
type: "Literal",
|
|
4579
|
-
value: target.callSiteIdx,
|
|
4580
|
-
raw: String(target.callSiteIdx)
|
|
4730
|
+
const fnDeclAst = parsedFn.body[0];
|
|
4731
|
+
const selfHash = computeFnv1aHash(generateCompactJs(fnDeclAst)) | 0;
|
|
4732
|
+
const buildD = shieldCoupled ? selfHash ^ (expDelta ?? 0) & 65535 | 0 : selfHash | 0;
|
|
4733
|
+
for (const target of targetsToReplace) {
|
|
4734
|
+
const k = fallbackKdf(target.callSiteIdx, target.localSalt, buildD, seed);
|
|
4735
|
+
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
4736
|
+
const callExpr = {
|
|
4737
|
+
type: "CallExpression",
|
|
4738
|
+
callee: {
|
|
4739
|
+
type: "Identifier",
|
|
4740
|
+
name: decryptFnName
|
|
4581
4741
|
},
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4742
|
+
arguments: [
|
|
4743
|
+
{
|
|
4744
|
+
type: "Literal",
|
|
4745
|
+
value: target.callSiteIdx,
|
|
4746
|
+
raw: String(target.callSiteIdx)
|
|
4747
|
+
},
|
|
4748
|
+
{
|
|
4749
|
+
type: "Literal",
|
|
4750
|
+
value: target.localSalt,
|
|
4751
|
+
raw: String(target.localSalt)
|
|
4752
|
+
}
|
|
4753
|
+
],
|
|
4754
|
+
optional: false
|
|
4755
|
+
};
|
|
4756
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4757
|
+
}
|
|
4758
|
+
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
4759
|
+
integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
4760
|
+
const varsSnippet = `var ${vaultVarName}=${serializedTable};var ${cacheVarName}=[];var ${dCacheVarName};`;
|
|
4761
|
+
const parsedVars = acorn3.parse(varsSnippet, {
|
|
4762
|
+
ecmaVersion: "latest",
|
|
4763
|
+
sourceType: "script"
|
|
4764
|
+
});
|
|
4765
|
+
const insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
4766
|
+
ast.body.splice(insertIdx, 0, ...parsedVars.body, fnDeclAst);
|
|
4591
4767
|
}
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4768
|
+
if (shaderPayloads.length > 0) {
|
|
4769
|
+
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
4770
|
+
for (const target of shaderTargets) {
|
|
4771
|
+
const callExpr = {
|
|
4772
|
+
type: "CallExpression",
|
|
4773
|
+
callee: {
|
|
4774
|
+
type: "Identifier",
|
|
4775
|
+
name: shaderVarName
|
|
4776
|
+
},
|
|
4777
|
+
arguments: [
|
|
4778
|
+
{
|
|
4779
|
+
type: "Literal",
|
|
4780
|
+
value: target.idx,
|
|
4781
|
+
raw: String(target.idx)
|
|
4782
|
+
}
|
|
4783
|
+
],
|
|
4784
|
+
optional: false
|
|
4785
|
+
};
|
|
4786
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4787
|
+
}
|
|
4788
|
+
const shaderHelperStmt = createShaderVaultAst(
|
|
4789
|
+
shaderVarName,
|
|
4790
|
+
shaderPayloads,
|
|
4791
|
+
seed
|
|
4792
|
+
);
|
|
4793
|
+
const shaderInsertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
4794
|
+
ast.body.splice(shaderInsertIdx, 0, shaderHelperStmt);
|
|
4795
|
+
if (targetsToReplace.length === 0) {
|
|
4796
|
+
integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
|
|
4607
4797
|
}
|
|
4608
4798
|
}
|
|
4609
|
-
ast.body.splice(insertIdx, 0, ...parsedVars.body, fnDeclAst);
|
|
4610
4799
|
return {
|
|
4611
4800
|
encryptedStringsCount: targetsToReplace.length,
|
|
4612
4801
|
integrityToken,
|
|
4613
4802
|
vaultVarName,
|
|
4614
|
-
decryptFnName
|
|
4803
|
+
decryptFnName,
|
|
4804
|
+
shaderBuffersCount: shaderPayloads.length
|
|
4615
4805
|
};
|
|
4616
4806
|
}
|
|
4617
4807
|
|
|
@@ -4814,7 +5004,44 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 26544
|
|
|
4814
5004
|
}
|
|
4815
5005
|
return true;
|
|
4816
5006
|
}
|
|
4817
|
-
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|
|
|
5007
|
+
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|@builtin|@location|@workgroup_size|\bstruct\s+[A-Za-z_]\w*\s*\{|\b[iub]?vec[234][fhiu]?\b|\bmat[234](?:x[234])?[fhi]?\b|\buniform\b|\bvar<(?:uniform|storage)|\bgl_(?:Position|FragColor|FragCoord|VertexID|InstanceID)\b|\bfn\s+main\b|\bvoid\s+main\s*\(|\bprecision\s+(?:lowp|mediump|highp)\s+float\b/;
|
|
5008
|
+
function isInsideLoopOrSerialized(ancestors) {
|
|
5009
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5010
|
+
const anc = ancestors[i];
|
|
5011
|
+
if (LOOP_NODE_TYPES.has(anc.type) || Boolean(anc._unpeekSerialized)) {
|
|
5012
|
+
return true;
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
return false;
|
|
5016
|
+
}
|
|
5017
|
+
function isShaderPayload(val, node, parent, ancestors, seed, isHotExempt, customReserved) {
|
|
5018
|
+
if (isInsideLoopOrSerialized(ancestors)) return false;
|
|
5019
|
+
if (parent?.type === "Property" && parent.key === node && !parent.computed) return false;
|
|
5020
|
+
if (isReservedProp(val, customReserved)) return false;
|
|
5021
|
+
if (isTailwindNoise(val)) return false;
|
|
5022
|
+
if (isSvgPathString(val, parent)) return false;
|
|
5023
|
+
if (isAdversaryDecoy(val, seed)) return false;
|
|
5024
|
+
if (val.startsWith("HOT_")) return false;
|
|
5025
|
+
const matchesSig = SHADER_SIG_RE.test(val);
|
|
5026
|
+
if (!matchesSig) {
|
|
5027
|
+
if (val.length < 256) return false;
|
|
5028
|
+
if (isHotExempt && isUiClassName(val, parent)) return false;
|
|
5029
|
+
}
|
|
5030
|
+
return true;
|
|
5031
|
+
}
|
|
5032
|
+
function findVaultInsertIndex(ast, activeDirectives = DIRECTIVE_STRINGS) {
|
|
5033
|
+
let insertIdx = 0;
|
|
5034
|
+
while (insertIdx < ast.body.length) {
|
|
5035
|
+
const stmt = ast.body[insertIdx];
|
|
5036
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
5037
|
+
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
5038
|
+
insertIdx++;
|
|
5039
|
+
} else {
|
|
5040
|
+
break;
|
|
5041
|
+
}
|
|
5042
|
+
}
|
|
5043
|
+
return insertIdx;
|
|
5044
|
+
}
|
|
4818
5045
|
function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
|
|
4819
5046
|
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
4820
5047
|
if (isReservedProp(val, customReserved)) return false;
|
|
@@ -5002,6 +5229,96 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5002
5229
|
if (node.value) c(node.value, st);
|
|
5003
5230
|
}
|
|
5004
5231
|
};
|
|
5232
|
+
function processVaultCandidate(val, node, parent, ancestors) {
|
|
5233
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5234
|
+
return;
|
|
5235
|
+
}
|
|
5236
|
+
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
5237
|
+
return;
|
|
5238
|
+
}
|
|
5239
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5240
|
+
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5241
|
+
return;
|
|
5242
|
+
}
|
|
5243
|
+
}
|
|
5244
|
+
let isHotExempt = false;
|
|
5245
|
+
if (hotExemptNodes) {
|
|
5246
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5247
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
5248
|
+
isHotExempt = true;
|
|
5249
|
+
break;
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
if (isShaderPayload(
|
|
5254
|
+
val,
|
|
5255
|
+
node,
|
|
5256
|
+
parent,
|
|
5257
|
+
ancestors,
|
|
5258
|
+
seed,
|
|
5259
|
+
isHotExempt,
|
|
5260
|
+
customReserved
|
|
5261
|
+
)) {
|
|
5262
|
+
let idx2 = shaderToIndex.get(val);
|
|
5263
|
+
if (idx2 === void 0) {
|
|
5264
|
+
idx2 = shaderPayloads.length;
|
|
5265
|
+
shaderToIndex.set(val, idx2);
|
|
5266
|
+
shaderPayloads.push(val);
|
|
5267
|
+
}
|
|
5268
|
+
targetsToReplace.push({
|
|
5269
|
+
type: "shader",
|
|
5270
|
+
node,
|
|
5271
|
+
parent,
|
|
5272
|
+
idx: idx2,
|
|
5273
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
5274
|
+
});
|
|
5275
|
+
return;
|
|
5276
|
+
}
|
|
5277
|
+
if (isHotExempt) {
|
|
5278
|
+
if (isEligibleHotLiteral(
|
|
5279
|
+
val,
|
|
5280
|
+
node,
|
|
5281
|
+
parent,
|
|
5282
|
+
ancestors,
|
|
5283
|
+
minLen,
|
|
5284
|
+
seed,
|
|
5285
|
+
customReserved,
|
|
5286
|
+
activeDirectives,
|
|
5287
|
+
semanticPatterns,
|
|
5288
|
+
excludeUi
|
|
5289
|
+
)) {
|
|
5290
|
+
hotTargetsToReplace.push({
|
|
5291
|
+
node,
|
|
5292
|
+
parent,
|
|
5293
|
+
val,
|
|
5294
|
+
idx: hotTargetsToReplace.length
|
|
5295
|
+
});
|
|
5296
|
+
}
|
|
5297
|
+
return;
|
|
5298
|
+
}
|
|
5299
|
+
if (!shouldEncryptString(
|
|
5300
|
+
val,
|
|
5301
|
+
minLen,
|
|
5302
|
+
parent,
|
|
5303
|
+
activeDirectives,
|
|
5304
|
+
customReserved
|
|
5305
|
+
)) {
|
|
5306
|
+
return;
|
|
5307
|
+
}
|
|
5308
|
+
let idx = stringToIndex.get(val);
|
|
5309
|
+
if (idx === void 0) {
|
|
5310
|
+
idx = uniqueStrings.length;
|
|
5311
|
+
stringToIndex.set(val, idx);
|
|
5312
|
+
uniqueStrings.push(val);
|
|
5313
|
+
}
|
|
5314
|
+
targetsToReplace.push({
|
|
5315
|
+
type: "string",
|
|
5316
|
+
node,
|
|
5317
|
+
parent,
|
|
5318
|
+
idx,
|
|
5319
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
5320
|
+
});
|
|
5321
|
+
}
|
|
5005
5322
|
walk4.ancestor(
|
|
5006
5323
|
ast,
|
|
5007
5324
|
{
|
|
@@ -5009,28 +5326,8 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5009
5326
|
if (typeof node.value !== "string") return;
|
|
5010
5327
|
const val = node.value;
|
|
5011
5328
|
if (activeDirectives.has(val)) return;
|
|
5012
|
-
let isHotExempt = false;
|
|
5013
|
-
if (hotExemptNodes) {
|
|
5014
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5015
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
5016
|
-
isHotExempt = true;
|
|
5017
|
-
break;
|
|
5018
|
-
}
|
|
5019
|
-
}
|
|
5020
|
-
}
|
|
5021
5329
|
const parent = ancestors[ancestors.length - 2];
|
|
5022
5330
|
if (!parent) return;
|
|
5023
|
-
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5024
|
-
return;
|
|
5025
|
-
}
|
|
5026
|
-
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
5027
|
-
return;
|
|
5028
|
-
}
|
|
5029
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5030
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5031
|
-
return;
|
|
5032
|
-
}
|
|
5033
|
-
}
|
|
5034
5331
|
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
5035
5332
|
if (parent.source === node) return;
|
|
5036
5333
|
}
|
|
@@ -5040,154 +5337,22 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5040
5337
|
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
5041
5338
|
return;
|
|
5042
5339
|
}
|
|
5043
|
-
|
|
5044
|
-
if (isEligibleHotLiteral(
|
|
5045
|
-
val,
|
|
5046
|
-
node,
|
|
5047
|
-
parent,
|
|
5048
|
-
ancestors,
|
|
5049
|
-
minLen,
|
|
5050
|
-
seed,
|
|
5051
|
-
customReserved,
|
|
5052
|
-
activeDirectives,
|
|
5053
|
-
semanticPatterns,
|
|
5054
|
-
excludeUi
|
|
5055
|
-
)) {
|
|
5056
|
-
hotTargetsToReplace.push({
|
|
5057
|
-
node,
|
|
5058
|
-
parent,
|
|
5059
|
-
val,
|
|
5060
|
-
idx: hotTargetsToReplace.length
|
|
5061
|
-
});
|
|
5062
|
-
}
|
|
5063
|
-
return;
|
|
5064
|
-
}
|
|
5065
|
-
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
5066
|
-
if (isReservedProp(val, customReserved)) {
|
|
5067
|
-
return;
|
|
5068
|
-
}
|
|
5069
|
-
}
|
|
5070
|
-
if (isReservedProp(val, customReserved)) return;
|
|
5071
|
-
if (isTailwindNoise(val)) return;
|
|
5072
|
-
if (isSvgPathString(val, parent)) return;
|
|
5073
|
-
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
5074
|
-
if (isShader) {
|
|
5075
|
-
let idx = shaderToIndex.get(val);
|
|
5076
|
-
if (idx === void 0) {
|
|
5077
|
-
idx = shaderPayloads.length;
|
|
5078
|
-
shaderToIndex.set(val, idx);
|
|
5079
|
-
shaderPayloads.push(val);
|
|
5080
|
-
}
|
|
5081
|
-
targetsToReplace.push({
|
|
5082
|
-
type: "shader",
|
|
5083
|
-
node,
|
|
5084
|
-
parent,
|
|
5085
|
-
idx,
|
|
5086
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5087
|
-
});
|
|
5088
|
-
} else {
|
|
5089
|
-
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
5090
|
-
let idx = stringToIndex.get(val);
|
|
5091
|
-
if (idx === void 0) {
|
|
5092
|
-
idx = uniqueStrings.length;
|
|
5093
|
-
stringToIndex.set(val, idx);
|
|
5094
|
-
uniqueStrings.push(val);
|
|
5095
|
-
}
|
|
5096
|
-
targetsToReplace.push({
|
|
5097
|
-
type: "string",
|
|
5098
|
-
node,
|
|
5099
|
-
parent,
|
|
5100
|
-
idx,
|
|
5101
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5102
|
-
});
|
|
5103
|
-
}
|
|
5340
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
5104
5341
|
},
|
|
5105
5342
|
TemplateLiteral(node, _state, ancestors) {
|
|
5106
5343
|
if (!node.quasis || node.quasis.length !== 1) return;
|
|
5107
5344
|
if (node.expressions && node.expressions.length !== 0) return;
|
|
5108
5345
|
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5109
5346
|
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5110
|
-
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5111
|
-
return;
|
|
5112
|
-
}
|
|
5113
|
-
let isHotExempt = false;
|
|
5114
|
-
if (hotExemptNodes) {
|
|
5115
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5116
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
5117
|
-
isHotExempt = true;
|
|
5118
|
-
break;
|
|
5119
|
-
}
|
|
5120
|
-
}
|
|
5121
|
-
}
|
|
5122
5347
|
const parent = ancestors[ancestors.length - 2];
|
|
5123
5348
|
if (!parent) return;
|
|
5124
|
-
if (
|
|
5349
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
5125
5350
|
return;
|
|
5126
5351
|
}
|
|
5127
|
-
if (parent.type === "
|
|
5352
|
+
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
5128
5353
|
return;
|
|
5129
5354
|
}
|
|
5130
|
-
|
|
5131
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5132
|
-
return;
|
|
5133
|
-
}
|
|
5134
|
-
}
|
|
5135
|
-
if (isHotExempt) {
|
|
5136
|
-
if (isEligibleHotLiteral(
|
|
5137
|
-
val,
|
|
5138
|
-
node,
|
|
5139
|
-
parent,
|
|
5140
|
-
ancestors,
|
|
5141
|
-
minLen,
|
|
5142
|
-
seed,
|
|
5143
|
-
customReserved,
|
|
5144
|
-
activeDirectives,
|
|
5145
|
-
semanticPatterns,
|
|
5146
|
-
excludeUi
|
|
5147
|
-
)) {
|
|
5148
|
-
hotTargetsToReplace.push({
|
|
5149
|
-
node,
|
|
5150
|
-
parent,
|
|
5151
|
-
val,
|
|
5152
|
-
idx: hotTargetsToReplace.length
|
|
5153
|
-
});
|
|
5154
|
-
}
|
|
5155
|
-
return;
|
|
5156
|
-
}
|
|
5157
|
-
if (isReservedProp(val, customReserved)) return;
|
|
5158
|
-
if (isTailwindNoise(val)) return;
|
|
5159
|
-
if (isSvgPathString(val, parent)) return;
|
|
5160
|
-
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
5161
|
-
if (isShader) {
|
|
5162
|
-
let idx = shaderToIndex.get(val);
|
|
5163
|
-
if (idx === void 0) {
|
|
5164
|
-
idx = shaderPayloads.length;
|
|
5165
|
-
shaderToIndex.set(val, idx);
|
|
5166
|
-
shaderPayloads.push(val);
|
|
5167
|
-
}
|
|
5168
|
-
targetsToReplace.push({
|
|
5169
|
-
type: "shader",
|
|
5170
|
-
node,
|
|
5171
|
-
parent,
|
|
5172
|
-
idx,
|
|
5173
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5174
|
-
});
|
|
5175
|
-
} else {
|
|
5176
|
-
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
5177
|
-
let idx = stringToIndex.get(val);
|
|
5178
|
-
if (idx === void 0) {
|
|
5179
|
-
idx = uniqueStrings.length;
|
|
5180
|
-
stringToIndex.set(val, idx);
|
|
5181
|
-
uniqueStrings.push(val);
|
|
5182
|
-
}
|
|
5183
|
-
targetsToReplace.push({
|
|
5184
|
-
type: "string",
|
|
5185
|
-
node,
|
|
5186
|
-
parent,
|
|
5187
|
-
idx,
|
|
5188
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5189
|
-
});
|
|
5190
|
-
}
|
|
5355
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
5191
5356
|
}
|
|
5192
5357
|
},
|
|
5193
5358
|
customWalkBase
|
|
@@ -5231,16 +5396,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5231
5396
|
delete node.quasis;
|
|
5232
5397
|
delete node.expressions;
|
|
5233
5398
|
}
|
|
5234
|
-
let insertIdx =
|
|
5235
|
-
while (insertIdx < ast.body.length) {
|
|
5236
|
-
const stmt = ast.body[insertIdx];
|
|
5237
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
5238
|
-
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
5239
|
-
insertIdx++;
|
|
5240
|
-
} else {
|
|
5241
|
-
break;
|
|
5242
|
-
}
|
|
5243
|
-
}
|
|
5399
|
+
let insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
5244
5400
|
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
5245
5401
|
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
5246
5402
|
while (fragCount > 2 && Math.floor(uniqueStrings.length / fragCount) < 4) {
|
|
@@ -6461,6 +6617,19 @@ function extractParamNames(paramNode, out = []) {
|
|
|
6461
6617
|
}
|
|
6462
6618
|
return out;
|
|
6463
6619
|
}
|
|
6620
|
+
function makeSafeNumericParam(name) {
|
|
6621
|
+
return {
|
|
6622
|
+
type: "ConditionalExpression",
|
|
6623
|
+
test: {
|
|
6624
|
+
type: "BinaryExpression",
|
|
6625
|
+
operator: "===",
|
|
6626
|
+
left: makeUnary("typeof", { type: "Identifier", name }),
|
|
6627
|
+
right: makeLiteral("number")
|
|
6628
|
+
},
|
|
6629
|
+
consequent: makeBinary("|", { type: "Identifier", name }, makeLiteral(0)),
|
|
6630
|
+
alternate: makeLiteral(0)
|
|
6631
|
+
};
|
|
6632
|
+
}
|
|
6464
6633
|
function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpts) {
|
|
6465
6634
|
const candidates = [];
|
|
6466
6635
|
const seenNames = /* @__PURE__ */ new Set();
|
|
@@ -6468,7 +6637,7 @@ function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpt
|
|
|
6468
6637
|
for (const name of names) {
|
|
6469
6638
|
if (name && name !== "arguments" && name !== "eval" && !seenNames.has(name)) {
|
|
6470
6639
|
seenNames.add(name);
|
|
6471
|
-
candidates.push(
|
|
6640
|
+
candidates.push(makeSafeNumericParam(name));
|
|
6472
6641
|
}
|
|
6473
6642
|
}
|
|
6474
6643
|
if (ctxOpts?.aliasIdentA && ctxOpts?.aliasIdentB) {
|
|
@@ -6515,10 +6684,18 @@ function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpt
|
|
|
6515
6684
|
}
|
|
6516
6685
|
return [candidates[0], candidates[1], candidates[2], candidates[3]];
|
|
6517
6686
|
}
|
|
6687
|
+
var QNR_RESIDUE_FAMILIES = [
|
|
6688
|
+
{ add: 1, mask: 3, target: 3 },
|
|
6689
|
+
{ add: 3, mask: 7, target: 6 },
|
|
6690
|
+
{ add: 5, mask: 7, target: 3 },
|
|
6691
|
+
{ add: 7, mask: 15, target: 13 }
|
|
6692
|
+
];
|
|
6518
6693
|
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false, ctxOpts) {
|
|
6519
6694
|
const domain = ctxOpts?.returnDomain ?? "object";
|
|
6520
6695
|
const [x1, x2, x3, x4] = buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn, ctxOpts);
|
|
6521
6696
|
const mba4 = buildMba4Ast(seed, fnIndex, x1, x2, x3, x4);
|
|
6697
|
+
const qnrFamilyIdx = ((seed ^ Math.imul(fnIndex + 1, 2654435761)) >>> 0) % QNR_RESIDUE_FAMILIES.length;
|
|
6698
|
+
const qnrFamily = QNR_RESIDUE_FAMILIES[qnrFamilyIdx];
|
|
6522
6699
|
let qnrLeft;
|
|
6523
6700
|
let zRefForDecoy;
|
|
6524
6701
|
if (ctxOpts?.scratchVarIdent) {
|
|
@@ -6546,11 +6723,29 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6546
6723
|
right: buildSboxMixAst(ctxOpts.sboxIdent, ctxOpts.scratchVarIdent)
|
|
6547
6724
|
});
|
|
6548
6725
|
}
|
|
6726
|
+
if (ctxOpts.aliasIdentA) {
|
|
6727
|
+
const aliasSlot = fnIndex + (seed & 3) & 3;
|
|
6728
|
+
const aliasMem = makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(aliasSlot));
|
|
6729
|
+
seqExprs.push({
|
|
6730
|
+
type: "AssignmentExpression",
|
|
6731
|
+
operator: "=",
|
|
6732
|
+
left: cloneNode(aliasMem),
|
|
6733
|
+
right: makeBinary(
|
|
6734
|
+
"|",
|
|
6735
|
+
makeBinary(
|
|
6736
|
+
"^",
|
|
6737
|
+
cloneNode(aliasMem),
|
|
6738
|
+
makeBinary("&", cloneNode(scratchId), makeLiteral(0))
|
|
6739
|
+
),
|
|
6740
|
+
makeLiteral(0)
|
|
6741
|
+
)
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6549
6744
|
seqExprs.push(
|
|
6550
6745
|
makeBinary(
|
|
6551
6746
|
"&",
|
|
6552
|
-
makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(
|
|
6553
|
-
makeLiteral(
|
|
6747
|
+
makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(qnrFamily.add)),
|
|
6748
|
+
makeLiteral(qnrFamily.mask)
|
|
6554
6749
|
)
|
|
6555
6750
|
);
|
|
6556
6751
|
qnrLeft = {
|
|
@@ -6562,8 +6757,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6562
6757
|
const zExpr = buildRivestPermAst(seed, fnIndex, mba4);
|
|
6563
6758
|
qnrLeft = makeBinary(
|
|
6564
6759
|
"&",
|
|
6565
|
-
makeBinary("+", makeImul(cloneNode(zExpr), cloneNode(zExpr)), makeLiteral(
|
|
6566
|
-
makeLiteral(
|
|
6760
|
+
makeBinary("+", makeImul(cloneNode(zExpr), cloneNode(zExpr)), makeLiteral(qnrFamily.add)),
|
|
6761
|
+
makeLiteral(qnrFamily.mask)
|
|
6567
6762
|
);
|
|
6568
6763
|
zRefForDecoy = zExpr;
|
|
6569
6764
|
}
|
|
@@ -6580,7 +6775,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6580
6775
|
type: "BinaryExpression",
|
|
6581
6776
|
operator: "===",
|
|
6582
6777
|
left: qnrLeft,
|
|
6583
|
-
right: makeLiteral(
|
|
6778
|
+
right: makeLiteral(qnrFamily.target)
|
|
6584
6779
|
},
|
|
6585
6780
|
consequent,
|
|
6586
6781
|
alternate: null
|
|
@@ -6703,6 +6898,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
6703
6898
|
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
6704
6899
|
if (!coldFunctionNodes.has(node)) return;
|
|
6705
6900
|
if (hotExemptNodes?.has(node) || node._unpeekSerialized) return;
|
|
6901
|
+
if (node._unpeekVirtualized === true) return;
|
|
6706
6902
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
6707
6903
|
const paramNames = [];
|
|
6708
6904
|
for (const p of node.params || []) {
|
|
@@ -6919,34 +7115,41 @@ function generateOpcodeMap(seed, count = OPCODE_COUNT) {
|
|
|
6919
7115
|
}
|
|
6920
7116
|
return pool.slice(0, count);
|
|
6921
7117
|
}
|
|
6922
|
-
function
|
|
7118
|
+
function computeHandlerDelta(op) {
|
|
7119
|
+
const delta = (op + 1) * 7 & 31;
|
|
7120
|
+
return delta === 0 ? 7 : delta;
|
|
7121
|
+
}
|
|
7122
|
+
function makeHandlerMbaOffsetExpr(seed, op, deltaOp) {
|
|
6923
7123
|
const variant = Math.abs(mixOpSeed(seed, op * 11 + 3)) % 4;
|
|
6924
7124
|
const c1 = mixOpSeed(seed, op * 11 + 5);
|
|
6925
7125
|
const c2 = mixOpSeed(seed, op * 11 + 7);
|
|
6926
7126
|
if (variant === 0) {
|
|
6927
|
-
const cSum = c1 + c2 | 0;
|
|
7127
|
+
const cSum = c1 + c2 - deltaOp | 0;
|
|
6928
7128
|
return `(((((($f.ac|${c1})+($f.ac&${c1}))|0)|((($f.p^${c2})+(($f.p&${c2})<<1))|0))+((((($f.ac|${c1})+($f.ac&${c1}))|0)&((($f.p^${c2})+(($f.p&${c2})<<1))|0))))-(((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)|${cSum})+((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)&${cSum})))|0))|0`;
|
|
6929
7129
|
}
|
|
6930
7130
|
if (variant === 1) {
|
|
6931
|
-
const cSum = c1 + c2 | 0;
|
|
7131
|
+
const cSum = c1 + c2 + deltaOp | 0;
|
|
6932
7132
|
return `((((($f.ac|$f.p)<<1)-($f.ac^$f.p))+${cSum})-((($f.ac^${c1})+(($f.ac&${c1})<<1))+(($f.p|${c2})+($f.p&${c2}))))|0`;
|
|
6933
7133
|
}
|
|
6934
7134
|
if (variant === 2) {
|
|
6935
|
-
const
|
|
6936
|
-
return `(((~$f.ac|${c1})+(~$f.ac&${c1}))+(($f.ac|${c2})+(
|
|
7135
|
+
const cFold2 = 1 + deltaOp - c1 - c2 | 0;
|
|
7136
|
+
return `(((~$f.ac|${c1})+(~$f.ac&${c1}))+(($f.ac|$f.p)-(~$f.ac&$f.p))+(($f.p&${c2})+(~$f.p&${c2}))+${cFold2})|0`;
|
|
6937
7137
|
}
|
|
6938
|
-
|
|
7138
|
+
const cFold = c1 - deltaOp | 0;
|
|
7139
|
+
return `((((($f.ac|$f.p)-(~$f.ac&$f.p))|${c1})+((($f.ac|$f.p)-(~$f.ac&$f.p))&${c1}))-(((($f.ac&${c2})+($f.ac&~${c2}))^${cFold})+(((($f.ac&${c2})+($f.ac&~${c2}))&${cFold})<<1)))|0`;
|
|
6939
7140
|
}
|
|
6940
7141
|
function wrapHandlerWithMba(seed, op, coreBody, isTerminal = false) {
|
|
6941
|
-
const
|
|
7142
|
+
const deltaOp = computeHandlerDelta(op);
|
|
7143
|
+
const zExpr = makeHandlerMbaOffsetExpr(seed, op, deltaOp);
|
|
6942
7144
|
const shape = Math.abs(mixOpSeed(seed, op * 17 + 1)) % 3;
|
|
6943
7145
|
const zVar = shape === 0 ? "$z0" : shape === 1 ? "$m0" : "$k0";
|
|
6944
7146
|
const tail = isTerminal ? "return void 0;" : shape === 0 ? "return $step($f);" : shape === 1 ? "var $nx=$step($f);return $nx;" : "return $f.d?void 0:$step($f);";
|
|
6945
|
-
const
|
|
7147
|
+
const balancedOffset = `(${zVar}-${deltaOp})`;
|
|
7148
|
+
const adjustedBody = coreBody.replace(/\$Z/g, balancedOffset);
|
|
6946
7149
|
if (coreBody.includes("$Z")) {
|
|
6947
7150
|
return `function($f){var ${zVar}=${zExpr};${adjustedBody}${tail}}`;
|
|
6948
7151
|
}
|
|
6949
|
-
return `function($f){var ${zVar}=${zExpr};$f.r=($f.r+${
|
|
7152
|
+
return `function($f){var ${zVar}=${zExpr};$f.r=($f.r+${balancedOffset})|0;${adjustedBody}${tail}}`;
|
|
6950
7153
|
}
|
|
6951
7154
|
function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowKeySymbol, expectedDelta) {
|
|
6952
7155
|
const opCount = opMap.length;
|
|
@@ -7015,17 +7218,22 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7015
7218
|
const spec = coreHandlers[op];
|
|
7016
7219
|
handlers[slotMap[op]] = wrapHandlerWithMba(seed, op, spec.body, Boolean(spec.terminal));
|
|
7017
7220
|
}
|
|
7018
|
-
const hasSym = Boolean(windowKeySymbol
|
|
7221
|
+
const hasSym = Boolean(windowKeySymbol);
|
|
7222
|
+
const hasExpDelta = Boolean(hasSym && expectedDelta !== void 0);
|
|
7019
7223
|
const symPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]` : "";
|
|
7020
7224
|
const symTamperPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_t`) ? `.${windowKeySymbol}_t` : `[${JSON.stringify(`${windowKeySymbol}_t`)}]` : "";
|
|
7021
|
-
const
|
|
7225
|
+
const symStatePropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_s`) ? `.${windowKeySymbol}_s` : `[${JSON.stringify(`${windowKeySymbol}_s`)}]` : "";
|
|
7226
|
+
const expD = hasExpDelta ? expectedDelta & 65535 : 0;
|
|
7022
7227
|
const seed32 = seed | 0;
|
|
7023
|
-
const
|
|
7024
|
-
const
|
|
7025
|
-
const
|
|
7026
|
-
const
|
|
7228
|
+
const seedU32 = seed >>> 0;
|
|
7229
|
+
const scopeKey = hasSym ? computeFnv1aHash(`${windowKeySymbol}:${hasExpDelta ? expD : ""}`, seed) >>> 0 : 0;
|
|
7230
|
+
const expDigest = hasExpDelta ? Math.imul(expD ^ seed32 | 0, 2654435761) ^ (expD << 16 | seed32 >>> 16) ^ 2246822507 | 0 : 0;
|
|
7231
|
+
const selfPrettyCheck = "$pp||/\\n/.test(Function.prototype.toString.call($vm))";
|
|
7232
|
+
const tamperCheckExpr = hasSym ? `var $bad=${selfPrettyCheck}||($G&&($G[$tk]===!0||$G${symTamperPropAccess}===!0||($G${symStatePropAccess}&&$G${symStatePropAccess}[0]===2))),$sv=$G?$G${symPropAccess}:void 0;if(!$bad){if($sv===void 0){if(typeof window>"u"&&typeof document>"u"&&typeof self>"u")$bad=!0;}else if(Array.isArray($sv)){if($sv[0]===2)$bad=!0;}${hasExpDelta ? `else if($sv!==($sv|0)){$bad=!0;}else{var $sh=(Math.imul(($sv^$S)|0,0x9e3779b1)^(($sv<<16)|($S>>>16))^0x85ebca6b)|0;if($sh!==$D)$bad=!0;}` : ""}}` : `var $bad=${selfPrettyCheck}||($G&&$G[$tk]===!0);`;
|
|
7233
|
+
const paramsList = hasExpDelta ? "$P,$A,$B,$C,$S,$D" : "$P,$A,$B,$C,$S";
|
|
7234
|
+
const factoryRaw = `(function $I(${paramsList}){var $G=typeof globalThis<"u"?globalThis:(typeof window<"u"?window:(typeof self<"u"?self:this));var $pp=/\\n/.test(Function.prototype.toString.call($I));var $rk=['__','unp','eek','_vm'].join('');var $rg=0,$rs=0;try{$rg=$G?($G[$rk]||($G[$rk]={})) : 0;$rs=$rg?($rg[${scopeKey}]||($rg[${scopeKey}]={})) : 0;if(!$pp&&$rs&&$rs[${seedU32}])return $rs[${seedU32}];}catch($e){}var $tk=['__','unp','eek','_ta','mpe','red'].join('');var $M=[],$ok=$A&255,$sk=$B&255,$vk=$C|0;for(var $j=0;$j<$P.length;$j+=2)$M[$P[$j]]=$P[$j+1];function $rd($f){var $p=$f.p++;var $x0=$f.st=(Math.imul($f.st^($p+1),0x45d9f3b)+(($f.ac|0x9e3779b9)+($f.ac&0x9e3779b9)))|0;var $w=$f.c[$p],$v=$w^(($x0>>>16)&0xffff);$f.st=($f.st^Math.imul($w+1,0x85ebca6b))|0;$f.ac=(Math.imul($f.ac^$v,0x27d4eb2d)^(($f.st>>>13)|($f.st<<19)))|0;return $v;}var $H=[${handlers.join(
|
|
7027
7235
|
","
|
|
7028
|
-
)}];function $step($f){if($f.d||$f.p>=$f.c.length)return void 0;var $o=$rd($f),$m=$M[$o^$ok];return $m!==void 0?$H[$m^$sk]:void 0;}function $x($f){var $fn=$step($f);while($fn!==void 0){try{$fn=$fn($f);}catch($err){if($f.e.length>0){var $ex=$f.e.pop();$f.r=$ex.r;$f.q[$f.r++]=$err;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;$fn=$step($f);}else{throw $err;}}}return $f.v;}
|
|
7236
|
+
)}];function $step($f){if($f.d||$f.p>=$f.c.length)return void 0;var $o=$rd($f),$m=$M[$o^$ok];return $m!==void 0?$H[$m^$sk]:void 0;}function $x($f){var $fn=$step($f);while($fn!==void 0){try{$fn=$fn($f);}catch($err){if($f.e.length>0){var $ex=$f.e.pop();$f.r=$ex.r;$f.q[$f.r++]=$err;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;$fn=$step($f);}else{throw $err;}}}return $f.v;}var $vm=function($c,$k,$s0,$t,$a,$u){${tamperCheckExpr}var $flt=$bad?(Math.imul($vk^$a,0x45d9f3b)|1):0;return $x({c:$c,k:$k,s:$s0,t:$t,u:$u||[],q:[],r:0,p:0,st:($vk^$a^$flt)|0,ac:($vk^($a<<5)^0x517cc1b7^$flt)|0,e:[],d:0,v:void 0});};try{if(!$pp&&$rs)$rs[${seedU32}]=$vm;}catch($e){}return $vm;})`;
|
|
7029
7237
|
const parsedFactory = acorn6.parse(factoryRaw, {
|
|
7030
7238
|
ecmaVersion: "latest",
|
|
7031
7239
|
sourceType: "script"
|
|
@@ -7034,7 +7242,7 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7034
7242
|
const argA = opMask & 255;
|
|
7035
7243
|
const argB = slotMask & 255;
|
|
7036
7244
|
const argC = vmKey | 0;
|
|
7037
|
-
return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${
|
|
7245
|
+
return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${hasExpDelta ? `,${expDigest}` : ""});`;
|
|
7038
7246
|
}
|
|
7039
7247
|
function walkWithParent(node, parent, visitor) {
|
|
7040
7248
|
if (!node || typeof node !== "object") return;
|
|
@@ -7244,6 +7452,33 @@ function prepareLoweredFunction(fnNode, enclosingBindings) {
|
|
|
7244
7452
|
}
|
|
7245
7453
|
return { loweredFn: clone, wrapperParams, paramPassExprs };
|
|
7246
7454
|
}
|
|
7455
|
+
function definitelyTerminates(stmt) {
|
|
7456
|
+
if (!stmt) return false;
|
|
7457
|
+
switch (stmt.type) {
|
|
7458
|
+
case "ReturnStatement":
|
|
7459
|
+
case "ThrowStatement":
|
|
7460
|
+
return true;
|
|
7461
|
+
case "BlockStatement": {
|
|
7462
|
+
const stmts = stmt.body || [];
|
|
7463
|
+
for (const s of stmts) {
|
|
7464
|
+
if (definitelyTerminates(s)) return true;
|
|
7465
|
+
}
|
|
7466
|
+
return false;
|
|
7467
|
+
}
|
|
7468
|
+
case "IfStatement":
|
|
7469
|
+
return Boolean(
|
|
7470
|
+
stmt.alternate && definitelyTerminates(stmt.consequent) && definitelyTerminates(stmt.alternate)
|
|
7471
|
+
);
|
|
7472
|
+
case "TryStatement": {
|
|
7473
|
+
if (stmt.finalizer && definitelyTerminates(stmt.finalizer)) return true;
|
|
7474
|
+
if (!definitelyTerminates(stmt.block)) return false;
|
|
7475
|
+
if (stmt.handler && !definitelyTerminates(stmt.handler.body)) return false;
|
|
7476
|
+
return true;
|
|
7477
|
+
}
|
|
7478
|
+
default:
|
|
7479
|
+
return false;
|
|
7480
|
+
}
|
|
7481
|
+
}
|
|
7247
7482
|
function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
7248
7483
|
const bytecode = [];
|
|
7249
7484
|
const consts = [];
|
|
@@ -7959,10 +8194,15 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
|
7959
8194
|
const jzPos = emitJumpPlaceholder(OP_JZ);
|
|
7960
8195
|
if (!compileStmt(stmt.consequent, false)) return false;
|
|
7961
8196
|
if (stmt.alternate) {
|
|
7962
|
-
|
|
8197
|
+
let jmpPos = -1;
|
|
8198
|
+
if (!definitelyTerminates(stmt.consequent)) {
|
|
8199
|
+
jmpPos = emitJumpPlaceholder(OP_JMP);
|
|
8200
|
+
}
|
|
7963
8201
|
patchJump(jzPos, bytecode.length);
|
|
7964
8202
|
if (!compileStmt(stmt.alternate, false)) return false;
|
|
7965
|
-
|
|
8203
|
+
if (jmpPos !== -1) {
|
|
8204
|
+
patchJump(jmpPos, bytecode.length);
|
|
8205
|
+
}
|
|
7966
8206
|
} else {
|
|
7967
8207
|
patchJump(jzPos, bytecode.length);
|
|
7968
8208
|
}
|
|
@@ -8232,14 +8472,19 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
|
8232
8472
|
return false;
|
|
8233
8473
|
}
|
|
8234
8474
|
}
|
|
8475
|
+
let endsWithTermination = false;
|
|
8235
8476
|
if (fnNode.body.type === "BlockStatement") {
|
|
8236
8477
|
if (!compileStmt(fnNode.body, true)) return null;
|
|
8478
|
+
endsWithTermination = definitelyTerminates(fnNode.body);
|
|
8237
8479
|
} else {
|
|
8238
8480
|
if (!compileExpr(fnNode.body, true)) return null;
|
|
8239
8481
|
emit(OP_RET);
|
|
8482
|
+
endsWithTermination = true;
|
|
8483
|
+
}
|
|
8484
|
+
if (!endsWithTermination) {
|
|
8485
|
+
emit(OP_LDC, addConst(void 0));
|
|
8486
|
+
emit(OP_RET);
|
|
8240
8487
|
}
|
|
8241
|
-
emit(OP_LDC, addConst(void 0));
|
|
8242
|
-
emit(OP_RET);
|
|
8243
8488
|
return { bytecode, consts, localCount, stateSlots, accSlots, upvalues };
|
|
8244
8489
|
}
|
|
8245
8490
|
function findInjectedVmHelperName(ast) {
|
|
@@ -8258,6 +8503,80 @@ function findInjectedVmHelperName(ast) {
|
|
|
8258
8503
|
}
|
|
8259
8504
|
return null;
|
|
8260
8505
|
}
|
|
8506
|
+
var PRIORITY_HANDLER_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?)$/i;
|
|
8507
|
+
var PRIORITY_CALL_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?|createServerReference|fetch)$/i;
|
|
8508
|
+
function getVmCandidateName(fn, ancestors) {
|
|
8509
|
+
if (fn.id?.type === "Identifier" && typeof fn.id.name === "string") {
|
|
8510
|
+
return fn.id.name;
|
|
8511
|
+
}
|
|
8512
|
+
const parent = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
8513
|
+
if (!parent) return "";
|
|
8514
|
+
if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
8515
|
+
return parent.id.name;
|
|
8516
|
+
}
|
|
8517
|
+
if (parent.type === "Property") {
|
|
8518
|
+
if (parent.key?.type === "Identifier") return parent.key.name;
|
|
8519
|
+
if (parent.key?.type === "Literal" && typeof parent.key.value === "string") {
|
|
8520
|
+
return parent.key.value;
|
|
8521
|
+
}
|
|
8522
|
+
}
|
|
8523
|
+
if (parent.type === "MethodDefinition" && parent.key?.type === "Identifier") {
|
|
8524
|
+
return parent.key.name;
|
|
8525
|
+
}
|
|
8526
|
+
if (parent.type === "AssignmentExpression") {
|
|
8527
|
+
if (parent.left?.type === "Identifier") return parent.left.name;
|
|
8528
|
+
if (parent.left?.type === "MemberExpression" && !parent.left.computed && parent.left.property?.type === "Identifier") {
|
|
8529
|
+
return parent.left.property.name;
|
|
8530
|
+
}
|
|
8531
|
+
}
|
|
8532
|
+
return "";
|
|
8533
|
+
}
|
|
8534
|
+
function bodyHasPrioritySignal(fnNode) {
|
|
8535
|
+
let matched = false;
|
|
8536
|
+
walkWithParent(fnNode.body, fnNode, (n, parent) => {
|
|
8537
|
+
if (matched) return false;
|
|
8538
|
+
if (n !== fnNode && FUNCTION_NODE_TYPES2.has(n.type)) return false;
|
|
8539
|
+
if (n.type === "CallExpression") {
|
|
8540
|
+
const callee = n.callee;
|
|
8541
|
+
if (callee?.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.name)) {
|
|
8542
|
+
matched = true;
|
|
8543
|
+
return false;
|
|
8544
|
+
}
|
|
8545
|
+
if (callee?.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.property.name)) {
|
|
8546
|
+
matched = true;
|
|
8547
|
+
return false;
|
|
8548
|
+
}
|
|
8549
|
+
}
|
|
8550
|
+
if (n.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(n.name)) {
|
|
8551
|
+
if (parent && parent.type === "MemberExpression" && !parent.computed && parent.property === n) {
|
|
8552
|
+
return;
|
|
8553
|
+
}
|
|
8554
|
+
if (parent && parent.type === "Property" && !parent.computed && parent.key === n && !parent.shorthand) {
|
|
8555
|
+
return;
|
|
8556
|
+
}
|
|
8557
|
+
matched = true;
|
|
8558
|
+
return false;
|
|
8559
|
+
}
|
|
8560
|
+
});
|
|
8561
|
+
return matched;
|
|
8562
|
+
}
|
|
8563
|
+
function scoreVmCandidate(fn, ancestors, criticalSet) {
|
|
8564
|
+
let score = 0;
|
|
8565
|
+
if (criticalSet?.has(fn)) {
|
|
8566
|
+
score += 1e3;
|
|
8567
|
+
}
|
|
8568
|
+
const candName = getVmCandidateName(fn, ancestors);
|
|
8569
|
+
if (candName && PRIORITY_HANDLER_NAME_RE.test(candName) || bodyHasPrioritySignal(fn)) {
|
|
8570
|
+
score += 500;
|
|
8571
|
+
}
|
|
8572
|
+
if (fn.body?.type === "BlockStatement" && Array.isArray(fn.body.body)) {
|
|
8573
|
+
const stmtCount = fn.body.body.length;
|
|
8574
|
+
if (stmtCount >= 2) {
|
|
8575
|
+
score += Math.min(200, 10 + (stmtCount - 2) * 15);
|
|
8576
|
+
}
|
|
8577
|
+
}
|
|
8578
|
+
return score;
|
|
8579
|
+
}
|
|
8261
8580
|
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769, windowKeySymbol, expectedDelta, extraOpts) {
|
|
8262
8581
|
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
8263
8582
|
const vmHelperName = `_uVm${suffix}`;
|
|
@@ -8376,10 +8695,11 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8376
8695
|
}
|
|
8377
8696
|
}
|
|
8378
8697
|
});
|
|
8379
|
-
const candidates =
|
|
8380
|
-
...
|
|
8381
|
-
|
|
8382
|
-
|
|
8698
|
+
const candidates = rawCandidates.map((c, idx) => ({
|
|
8699
|
+
...c,
|
|
8700
|
+
score: scoreVmCandidate(c.fn, c.ancestors, criticalSet),
|
|
8701
|
+
idx
|
|
8702
|
+
})).sort((a, b) => b.score !== a.score ? b.score - a.score : a.idx - b.idx);
|
|
8383
8703
|
let virtualizedCount = 0;
|
|
8384
8704
|
for (const { fn, ancestors } of candidates) {
|
|
8385
8705
|
if (virtualizedCount >= maxFunctions) break;
|
|
@@ -8543,6 +8863,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8543
8863
|
} else {
|
|
8544
8864
|
fn.body = callExpr;
|
|
8545
8865
|
}
|
|
8866
|
+
fn._unpeekVirtualized = true;
|
|
8546
8867
|
virtualizedCount++;
|
|
8547
8868
|
}
|
|
8548
8869
|
if (virtualizedCount > 0) {
|
|
@@ -8898,6 +9219,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
8898
9219
|
);
|
|
8899
9220
|
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
8900
9221
|
integrityToken = saltedRes.integrityToken;
|
|
9222
|
+
shaderBuffersCount = saltedRes.shaderBuffersCount ?? 0;
|
|
8901
9223
|
} else {
|
|
8902
9224
|
const vaultRes = applyStringVault(
|
|
8903
9225
|
ast,
|
|
@@ -9116,6 +9438,44 @@ function readOriginalSourceMapForFile(filePath, relPath, vaultDir, deferVaultWri
|
|
|
9116
9438
|
}
|
|
9117
9439
|
return void 0;
|
|
9118
9440
|
}
|
|
9441
|
+
function countPreExistingEvalCalls(code) {
|
|
9442
|
+
const hits = [];
|
|
9443
|
+
let ast;
|
|
9444
|
+
try {
|
|
9445
|
+
ast = acorn7.parse(code, {
|
|
9446
|
+
ecmaVersion: "latest",
|
|
9447
|
+
sourceType: "module",
|
|
9448
|
+
allowReturnOutsideFunction: true
|
|
9449
|
+
});
|
|
9450
|
+
} catch {
|
|
9451
|
+
try {
|
|
9452
|
+
ast = acorn7.parse(code, {
|
|
9453
|
+
ecmaVersion: "latest",
|
|
9454
|
+
sourceType: "script",
|
|
9455
|
+
allowReturnOutsideFunction: true
|
|
9456
|
+
});
|
|
9457
|
+
} catch {
|
|
9458
|
+
return hits;
|
|
9459
|
+
}
|
|
9460
|
+
}
|
|
9461
|
+
walkSimple(ast, {
|
|
9462
|
+
CallExpression(node) {
|
|
9463
|
+
if (node.callee.type === "Identifier") {
|
|
9464
|
+
if (node.callee.name === "eval") {
|
|
9465
|
+
hits.push("eval(...)");
|
|
9466
|
+
} else if (node.callee.name === "Function") {
|
|
9467
|
+
hits.push("Function(...)");
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
},
|
|
9471
|
+
NewExpression(node) {
|
|
9472
|
+
if (node.callee.type === "Identifier" && node.callee.name === "Function") {
|
|
9473
|
+
hits.push("new Function(...)");
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
});
|
|
9477
|
+
return hits;
|
|
9478
|
+
}
|
|
9119
9479
|
async function protectProject(options = {}) {
|
|
9120
9480
|
const startTime = performance.now();
|
|
9121
9481
|
const cwd = path5.resolve(options.cwd ?? process.cwd());
|
|
@@ -9168,6 +9528,19 @@ async function protectProject(options = {}) {
|
|
|
9168
9528
|
const allProtBufs = [];
|
|
9169
9529
|
const stagedFiles = [];
|
|
9170
9530
|
const pendingVaultMaps = [];
|
|
9531
|
+
const preExistingEvalFiles = {};
|
|
9532
|
+
let alreadyProtectedCount = 0;
|
|
9533
|
+
const manifestPath = path5.join(vaultResult.vaultDir, "manifest.json");
|
|
9534
|
+
let existingManifest;
|
|
9535
|
+
if (!dryRun && fs6.existsSync(manifestPath)) {
|
|
9536
|
+
try {
|
|
9537
|
+
const parsed = JSON.parse(fs6.readFileSync(manifestPath, "utf8"));
|
|
9538
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
9539
|
+
existingManifest = parsed;
|
|
9540
|
+
}
|
|
9541
|
+
} catch {
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9171
9544
|
let originalGzipBytes = 0;
|
|
9172
9545
|
let protectedGzipBytes = 0;
|
|
9173
9546
|
let gzipDeltaPercent = 0;
|
|
@@ -9188,6 +9561,7 @@ async function protectProject(options = {}) {
|
|
|
9188
9561
|
originalBytes += origBuf.byteLength;
|
|
9189
9562
|
allOrigBufs.push(origBuf);
|
|
9190
9563
|
const relPath = allRelPaths[i];
|
|
9564
|
+
const preExistingHits = countPreExistingEvalCalls(codeToTransform);
|
|
9191
9565
|
const isEntry = isEntryChunk(relPath, i, allRelPaths, manifestEntries, isWorkerTarget);
|
|
9192
9566
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
9193
9567
|
const fileSeed = computeFnv1aHash(`${relPath}:${i}`, seed);
|
|
@@ -9217,6 +9591,13 @@ async function protectProject(options = {}) {
|
|
|
9217
9591
|
file: relPath
|
|
9218
9592
|
});
|
|
9219
9593
|
} else if (result.skippedReason === "already-protected") {
|
|
9594
|
+
alreadyProtectedCount++;
|
|
9595
|
+
const prevHits = existingManifest?.preExistingEvalFiles?.[relPath];
|
|
9596
|
+
if (Array.isArray(prevHits) && prevHits.length > 0) {
|
|
9597
|
+
preExistingEvalFiles[relPath] = prevHits;
|
|
9598
|
+
} else if (preExistingHits.length > 0) {
|
|
9599
|
+
preExistingEvalFiles[relPath] = preExistingHits;
|
|
9600
|
+
}
|
|
9220
9601
|
diagnostics.push({
|
|
9221
9602
|
code: "ALREADY_PROTECTED",
|
|
9222
9603
|
severity: "info",
|
|
@@ -9230,6 +9611,8 @@ async function protectProject(options = {}) {
|
|
|
9230
9611
|
message: `File "${relPath}" is empty.`,
|
|
9231
9612
|
file: relPath
|
|
9232
9613
|
});
|
|
9614
|
+
} else if (preExistingHits.length > 0) {
|
|
9615
|
+
preExistingEvalFiles[relPath] = preExistingHits;
|
|
9233
9616
|
}
|
|
9234
9617
|
let finalCode = result.code;
|
|
9235
9618
|
let preambleLineOffset = 0;
|
|
@@ -9334,6 +9717,34 @@ async function protectProject(options = {}) {
|
|
|
9334
9717
|
for (const { tmpPath, finalPath } of stagedFiles) {
|
|
9335
9718
|
fs6.renameSync(tmpPath, finalPath);
|
|
9336
9719
|
}
|
|
9720
|
+
const relVault = path5.relative(cwd, vaultResult.vaultDir);
|
|
9721
|
+
const isSafeVaultDir = relVault === "" || !relVault.startsWith("..") && !path5.isAbsolute(relVault);
|
|
9722
|
+
if (isSafeVaultDir) {
|
|
9723
|
+
const relOutDir = path5.relative(cwd, outDir).replace(/\\/g, "/") || ".";
|
|
9724
|
+
const manifestPayload = processedFiles > 0 && alreadyProtectedCount === processedFiles && existingManifest ? {
|
|
9725
|
+
version: 1,
|
|
9726
|
+
outDir: existingManifest.outDir ?? relOutDir,
|
|
9727
|
+
originalGzipBytes: existingManifest.originalGzipBytes ?? originalGzipBytes,
|
|
9728
|
+
protectedGzipBytes: existingManifest.protectedGzipBytes ?? protectedGzipBytes,
|
|
9729
|
+
gzipDeltaPercent: existingManifest.gzipDeltaPercent ?? gzipDeltaPercent,
|
|
9730
|
+
preExistingEvalFiles: {
|
|
9731
|
+
...existingManifest.preExistingEvalFiles ?? {},
|
|
9732
|
+
...preExistingEvalFiles
|
|
9733
|
+
}
|
|
9734
|
+
} : {
|
|
9735
|
+
version: 1,
|
|
9736
|
+
outDir: relOutDir,
|
|
9737
|
+
originalGzipBytes,
|
|
9738
|
+
protectedGzipBytes,
|
|
9739
|
+
gzipDeltaPercent,
|
|
9740
|
+
preExistingEvalFiles
|
|
9741
|
+
};
|
|
9742
|
+
try {
|
|
9743
|
+
fs6.mkdirSync(vaultResult.vaultDir, { recursive: true });
|
|
9744
|
+
fs6.writeFileSync(manifestPath, JSON.stringify(manifestPayload, null, 2), "utf8");
|
|
9745
|
+
} catch {
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9337
9748
|
}
|
|
9338
9749
|
} catch (error) {
|
|
9339
9750
|
for (const { tmpPath } of stagedFiles) {
|
|
@@ -9347,6 +9758,7 @@ async function protectProject(options = {}) {
|
|
|
9347
9758
|
throw error;
|
|
9348
9759
|
}
|
|
9349
9760
|
const elapsedMs = Math.max(1, Math.round(performance.now() - startTime));
|
|
9761
|
+
const resolvedTier = options.tier ?? (effectiveProfile === "strict" || aggressive ? "Tier 3" : effectiveProfile === "minimal" ? "Tier 1" : config.tier ?? "Tier 2");
|
|
9350
9762
|
return {
|
|
9351
9763
|
framework,
|
|
9352
9764
|
outDir,
|
|
@@ -9363,7 +9775,7 @@ async function protectProject(options = {}) {
|
|
|
9363
9775
|
totalMangledSymbols,
|
|
9364
9776
|
elapsedMs,
|
|
9365
9777
|
seed,
|
|
9366
|
-
tier:
|
|
9778
|
+
tier: resolvedTier,
|
|
9367
9779
|
aggressive,
|
|
9368
9780
|
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
|
|
9369
9781
|
dryRun,
|
|
@@ -9377,8 +9789,8 @@ async function protectProject(options = {}) {
|
|
|
9377
9789
|
// src/core/check.ts
|
|
9378
9790
|
import fs7 from "fs";
|
|
9379
9791
|
import path6 from "path";
|
|
9380
|
-
import * as
|
|
9381
|
-
import { simple as
|
|
9792
|
+
import * as acorn8 from "acorn";
|
|
9793
|
+
import { simple as walkSimple2 } from "acorn-walk";
|
|
9382
9794
|
function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
9383
9795
|
if (hasNextServerSegment(currentDir, rootOutDir)) {
|
|
9384
9796
|
return;
|
|
@@ -9415,43 +9827,113 @@ function hasIgnoreEntry(filePath, ignoreEntry) {
|
|
|
9415
9827
|
return false;
|
|
9416
9828
|
}
|
|
9417
9829
|
}
|
|
9830
|
+
function isEs5GlobalThisIdiom(args) {
|
|
9831
|
+
if (args.length !== 1) return false;
|
|
9832
|
+
const arg = args[0];
|
|
9833
|
+
if (arg.type === "Literal" && typeof arg.value === "string") {
|
|
9834
|
+
const trimmed = arg.value.trim().replace(/;+$/, "").trim();
|
|
9835
|
+
return trimmed === "return this";
|
|
9836
|
+
}
|
|
9837
|
+
return false;
|
|
9838
|
+
}
|
|
9839
|
+
function isNodeModulesSource(sourcePath) {
|
|
9840
|
+
if (!sourcePath) return false;
|
|
9841
|
+
const normalized = sourcePath.replace(/\\/g, "/").toLowerCase();
|
|
9842
|
+
return /(?:^|\/)node_modules\//.test(normalized);
|
|
9843
|
+
}
|
|
9844
|
+
function mapHasOnlyNodeModulesSources(map) {
|
|
9845
|
+
if (!map) return false;
|
|
9846
|
+
const flat = Array.isArray(map.sections) ? flattenSourceMapSections(map) : map;
|
|
9847
|
+
const sources = Array.isArray(flat.sources) ? flat.sources : [];
|
|
9848
|
+
if (sources.length === 0) return false;
|
|
9849
|
+
const root = flat.sourceRoot;
|
|
9850
|
+
return sources.every((src) => {
|
|
9851
|
+
const combined = root && src && !src.startsWith(root) ? `${root.replace(/\/$/, "")}/${src.replace(/^\//, "")}` : src;
|
|
9852
|
+
return isNodeModulesSource(combined);
|
|
9853
|
+
});
|
|
9854
|
+
}
|
|
9855
|
+
function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
9856
|
+
if (!map) return false;
|
|
9857
|
+
const pos = resolvePosition(map, hit.line, hit.column);
|
|
9858
|
+
if (pos.source) {
|
|
9859
|
+
return isNodeModulesSource(pos.source);
|
|
9860
|
+
}
|
|
9861
|
+
if (hit.calleeLine !== hit.line || hit.calleeColumn !== hit.column) {
|
|
9862
|
+
const calleePos = resolvePosition(map, hit.calleeLine, hit.calleeColumn);
|
|
9863
|
+
if (calleePos.source) {
|
|
9864
|
+
return isNodeModulesSource(calleePos.source);
|
|
9865
|
+
}
|
|
9866
|
+
}
|
|
9867
|
+
return allSourcesNodeModules;
|
|
9868
|
+
}
|
|
9418
9869
|
function findEvalOrFunctionCalls(code) {
|
|
9419
9870
|
const hits = [];
|
|
9420
9871
|
let ast;
|
|
9421
9872
|
try {
|
|
9422
|
-
ast =
|
|
9873
|
+
ast = acorn8.parse(code, {
|
|
9423
9874
|
ecmaVersion: "latest",
|
|
9424
9875
|
sourceType: "module",
|
|
9425
|
-
allowReturnOutsideFunction: true
|
|
9876
|
+
allowReturnOutsideFunction: true,
|
|
9877
|
+
locations: true
|
|
9426
9878
|
});
|
|
9427
9879
|
} catch {
|
|
9428
9880
|
try {
|
|
9429
|
-
ast =
|
|
9881
|
+
ast = acorn8.parse(code, {
|
|
9430
9882
|
ecmaVersion: "latest",
|
|
9431
9883
|
sourceType: "script",
|
|
9432
|
-
allowReturnOutsideFunction: true
|
|
9884
|
+
allowReturnOutsideFunction: true,
|
|
9885
|
+
locations: true
|
|
9433
9886
|
});
|
|
9434
9887
|
} catch {
|
|
9435
9888
|
return hits;
|
|
9436
9889
|
}
|
|
9437
9890
|
}
|
|
9438
|
-
|
|
9891
|
+
walkSimple2(ast, {
|
|
9439
9892
|
CallExpression(node) {
|
|
9440
9893
|
if (node.callee.type === "Identifier") {
|
|
9894
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
9895
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
9896
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
9897
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
9441
9898
|
if (node.callee.name === "eval") {
|
|
9442
|
-
hits.push(
|
|
9899
|
+
hits.push({
|
|
9900
|
+
kind: "eval(...)",
|
|
9901
|
+
line,
|
|
9902
|
+
column,
|
|
9903
|
+
calleeLine,
|
|
9904
|
+
calleeColumn,
|
|
9905
|
+
vendorIdiom: false
|
|
9906
|
+
});
|
|
9443
9907
|
} else if (node.callee.name === "Function") {
|
|
9444
|
-
hits.push(
|
|
9908
|
+
hits.push({
|
|
9909
|
+
kind: "Function(...)",
|
|
9910
|
+
line,
|
|
9911
|
+
column,
|
|
9912
|
+
calleeLine,
|
|
9913
|
+
calleeColumn,
|
|
9914
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
9915
|
+
});
|
|
9445
9916
|
}
|
|
9446
9917
|
}
|
|
9447
9918
|
},
|
|
9448
9919
|
NewExpression(node) {
|
|
9449
9920
|
if (node.callee.type === "Identifier" && node.callee.name === "Function") {
|
|
9450
|
-
|
|
9921
|
+
const line = node.loc ? node.loc.start.line : 1;
|
|
9922
|
+
const column = node.loc ? node.loc.start.column + 1 : 1;
|
|
9923
|
+
const calleeLine = node.callee.loc ? node.callee.loc.start.line : line;
|
|
9924
|
+
const calleeColumn = node.callee.loc ? node.callee.loc.start.column + 1 : column;
|
|
9925
|
+
hits.push({
|
|
9926
|
+
kind: "new Function(...)",
|
|
9927
|
+
line,
|
|
9928
|
+
column,
|
|
9929
|
+
calleeLine,
|
|
9930
|
+
calleeColumn,
|
|
9931
|
+
vendorIdiom: isEs5GlobalThisIdiom(node.arguments)
|
|
9932
|
+
});
|
|
9451
9933
|
}
|
|
9452
9934
|
}
|
|
9453
9935
|
});
|
|
9454
|
-
return
|
|
9936
|
+
return hits;
|
|
9455
9937
|
}
|
|
9456
9938
|
async function checkProject(options = {}) {
|
|
9457
9939
|
const cwd = path6.resolve(options.cwd ?? process.cwd());
|
|
@@ -9477,9 +9959,21 @@ async function checkProject(options = {}) {
|
|
|
9477
9959
|
});
|
|
9478
9960
|
}
|
|
9479
9961
|
const vaultDir = path6.resolve(cwd, privateMapsDir);
|
|
9962
|
+
const manifestPath = path6.join(vaultDir, "manifest.json");
|
|
9963
|
+
let manifest;
|
|
9964
|
+
if (fs7.existsSync(manifestPath)) {
|
|
9965
|
+
try {
|
|
9966
|
+
const parsed = JSON.parse(fs7.readFileSync(manifestPath, "utf8"));
|
|
9967
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
9968
|
+
manifest = parsed;
|
|
9969
|
+
}
|
|
9970
|
+
} catch {
|
|
9971
|
+
}
|
|
9972
|
+
}
|
|
9480
9973
|
const clientFiles = scanClientBundles(resolvedOutDir, config);
|
|
9481
9974
|
for (const filePath of clientFiles) {
|
|
9482
9975
|
const rel = path6.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
|
|
9976
|
+
const relFromManifest = typeof manifest?.outDir === "string" ? path6.relative(path6.resolve(cwd, manifest.outDir), filePath).replace(/\\/g, "/") : void 0;
|
|
9483
9977
|
let content;
|
|
9484
9978
|
try {
|
|
9485
9979
|
content = fs7.readFileSync(filePath, "utf8");
|
|
@@ -9497,14 +9991,19 @@ async function checkProject(options = {}) {
|
|
|
9497
9991
|
}
|
|
9498
9992
|
const jsDebugId = extractDebugId(content);
|
|
9499
9993
|
const decodedRel = safeDecodeURIComponent(rel);
|
|
9994
|
+
const decodedManifestRel = relFromManifest ? safeDecodeURIComponent(relFromManifest) : void 0;
|
|
9500
9995
|
const mapCandidates = [
|
|
9501
9996
|
path6.join(vaultDir, `${rel}.map`),
|
|
9502
|
-
...decodedRel !== rel ? [path6.join(vaultDir, `${decodedRel}.map`)] : []
|
|
9997
|
+
...decodedRel !== rel ? [path6.join(vaultDir, `${decodedRel}.map`)] : [],
|
|
9998
|
+
...relFromManifest && relFromManifest !== rel ? [path6.join(vaultDir, `${relFromManifest}.map`)] : [],
|
|
9999
|
+
...decodedManifestRel && decodedManifestRel !== relFromManifest ? [path6.join(vaultDir, `${decodedManifestRel}.map`)] : []
|
|
9503
10000
|
];
|
|
9504
10001
|
const vaultedMapPath = mapCandidates.find((p) => fs7.existsSync(p));
|
|
10002
|
+
let vaultedMap;
|
|
9505
10003
|
if (vaultedMapPath) {
|
|
9506
10004
|
try {
|
|
9507
10005
|
const mapJson = JSON.parse(fs7.readFileSync(vaultedMapPath, "utf8"));
|
|
10006
|
+
vaultedMap = mapJson;
|
|
9508
10007
|
const rawMapDebugId = typeof mapJson.debugId === "string" ? mapJson.debugId : typeof mapJson.debug_id === "string" ? mapJson.debug_id : void 0;
|
|
9509
10008
|
if (jsDebugId && rawMapDebugId && jsDebugId !== rawMapDebugId) {
|
|
9510
10009
|
violations.push({
|
|
@@ -9540,16 +10039,64 @@ async function checkProject(options = {}) {
|
|
|
9540
10039
|
}
|
|
9541
10040
|
const evalHits = findEvalOrFunctionCalls(content);
|
|
9542
10041
|
if (evalHits.length > 0) {
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
10042
|
+
if (!requireZeroEval) {
|
|
10043
|
+
const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
|
|
10044
|
+
warnings.push({
|
|
10045
|
+
rule: "eval-csp",
|
|
10046
|
+
severity: "warning",
|
|
10047
|
+
message: `Dynamic code evaluation (${kinds.join(", ")}) detected in "${rel}".`,
|
|
10048
|
+
file: rel
|
|
10049
|
+
});
|
|
9551
10050
|
} else {
|
|
9552
|
-
|
|
10051
|
+
const allNodeModules = mapHasOnlyNodeModulesSources(vaultedMap);
|
|
10052
|
+
const baselineList = manifest?.preExistingEvalFiles?.[rel] ?? (relFromManifest ? manifest?.preExistingEvalFiles?.[relFromManifest] : void 0);
|
|
10053
|
+
const remainingBaseline = /* @__PURE__ */ new Map();
|
|
10054
|
+
if (Array.isArray(baselineList)) {
|
|
10055
|
+
for (const entry of baselineList) {
|
|
10056
|
+
remainingBaseline.set(entry, (remainingBaseline.get(entry) ?? 0) + 1);
|
|
10057
|
+
}
|
|
10058
|
+
}
|
|
10059
|
+
const warningHits = [];
|
|
10060
|
+
const unattributedHits = [];
|
|
10061
|
+
for (const hit of evalHits) {
|
|
10062
|
+
if (hit.vendorIdiom || isHitFromNodeModules(hit, vaultedMap, allNodeModules)) {
|
|
10063
|
+
warningHits.push(hit);
|
|
10064
|
+
const rem = remainingBaseline.get(hit.kind) ?? 0;
|
|
10065
|
+
if (rem > 0) {
|
|
10066
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
10067
|
+
}
|
|
10068
|
+
} else {
|
|
10069
|
+
unattributedHits.push(hit);
|
|
10070
|
+
}
|
|
10071
|
+
}
|
|
10072
|
+
const errorHits = [];
|
|
10073
|
+
for (const hit of unattributedHits) {
|
|
10074
|
+
const rem = remainingBaseline.get(hit.kind) ?? 0;
|
|
10075
|
+
if (rem > 0) {
|
|
10076
|
+
remainingBaseline.set(hit.kind, rem - 1);
|
|
10077
|
+
warningHits.push(hit);
|
|
10078
|
+
} else {
|
|
10079
|
+
errorHits.push(hit);
|
|
10080
|
+
}
|
|
10081
|
+
}
|
|
10082
|
+
if (warningHits.length > 0) {
|
|
10083
|
+
const warningKinds = Array.from(new Set(warningHits.map((h) => h.kind)));
|
|
10084
|
+
warnings.push({
|
|
10085
|
+
rule: "eval-csp",
|
|
10086
|
+
severity: "warning",
|
|
10087
|
+
message: `Pre-existing or vendor dynamic code evaluation (${warningKinds.join(", ")}) detected in "${rel}".`,
|
|
10088
|
+
file: rel
|
|
10089
|
+
});
|
|
10090
|
+
}
|
|
10091
|
+
if (errorHits.length > 0) {
|
|
10092
|
+
const errorKinds = Array.from(new Set(errorHits.map((h) => h.kind)));
|
|
10093
|
+
violations.push({
|
|
10094
|
+
rule: "eval-csp",
|
|
10095
|
+
severity: "error",
|
|
10096
|
+
message: `Dynamic code evaluation (${errorKinds.join(", ")}) detected in "${rel}".`,
|
|
10097
|
+
file: rel
|
|
10098
|
+
});
|
|
10099
|
+
}
|
|
9553
10100
|
}
|
|
9554
10101
|
}
|
|
9555
10102
|
}
|
|
@@ -9596,18 +10143,20 @@ async function checkProject(options = {}) {
|
|
|
9596
10143
|
message: `.dockerignore is missing "${ignoreEntry}". Private source maps may leak into Docker images.`
|
|
9597
10144
|
});
|
|
9598
10145
|
}
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
10146
|
+
if (manifest && typeof manifest.gzipDeltaPercent === "number" && manifest.gzipDeltaPercent > maxGzipDelta) {
|
|
10147
|
+
const isTinyBundleBaseline = options.maxGzipDelta === void 0 && typeof manifest.originalGzipBytes === "number" && manifest.originalGzipBytes < 16384;
|
|
10148
|
+
if (isTinyBundleBaseline) {
|
|
10149
|
+
warnings.push({
|
|
10150
|
+
rule: "gzip-budget",
|
|
10151
|
+
severity: "warning",
|
|
10152
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds default ${maxGzipDelta}% threshold on small bundle (${manifest.originalGzipBytes} B original gzip).`
|
|
10153
|
+
});
|
|
10154
|
+
} else {
|
|
10155
|
+
violations.push({
|
|
10156
|
+
rule: "gzip-budget",
|
|
10157
|
+
severity: "error",
|
|
10158
|
+
message: `Bundle Gzip delta (${manifest.gzipDeltaPercent}%) exceeds maxGzipDelta (${maxGzipDelta}%).`
|
|
10159
|
+
});
|
|
9611
10160
|
}
|
|
9612
10161
|
}
|
|
9613
10162
|
return {
|
|
@@ -9620,7 +10169,7 @@ async function checkProject(options = {}) {
|
|
|
9620
10169
|
}
|
|
9621
10170
|
|
|
9622
10171
|
// src/cli/index.ts
|
|
9623
|
-
var VERSION = "4.0.
|
|
10172
|
+
var VERSION = "4.0.1";
|
|
9624
10173
|
var cachedPackageVersion;
|
|
9625
10174
|
function getPackageVersion() {
|
|
9626
10175
|
if (cachedPackageVersion !== void 0) {
|