unpeek 1.6.2 → 1.7.2

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.
Files changed (45) hide show
  1. package/dist/ast/index.cjs +262 -85
  2. package/dist/ast/index.cjs.map +1 -1
  3. package/dist/ast/index.js +262 -85
  4. package/dist/ast/index.js.map +1 -1
  5. package/dist/browser.cjs +262 -85
  6. package/dist/browser.cjs.map +1 -1
  7. package/dist/browser.js +262 -85
  8. package/dist/browser.js.map +1 -1
  9. package/dist/bundler/unplugin.cjs +262 -85
  10. package/dist/bundler/unplugin.cjs.map +1 -1
  11. package/dist/bundler/unplugin.js +262 -85
  12. package/dist/bundler/unplugin.js.map +1 -1
  13. package/dist/cli/index.cjs +263 -86
  14. package/dist/cli/index.cjs.map +1 -1
  15. package/dist/cli/index.js +263 -86
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cli/protect.cjs +262 -85
  18. package/dist/cli/protect.cjs.map +1 -1
  19. package/dist/cli/protect.js +262 -85
  20. package/dist/cli/protect.js.map +1 -1
  21. package/dist/esbuild.cjs +262 -85
  22. package/dist/esbuild.cjs.map +1 -1
  23. package/dist/esbuild.js +262 -85
  24. package/dist/esbuild.js.map +1 -1
  25. package/dist/index.cjs +263 -86
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.js +263 -86
  28. package/dist/index.js.map +1 -1
  29. package/dist/rollup.cjs +262 -85
  30. package/dist/rollup.cjs.map +1 -1
  31. package/dist/rollup.js +262 -85
  32. package/dist/rollup.js.map +1 -1
  33. package/dist/runtime/index.cjs +2 -15
  34. package/dist/runtime/index.cjs.map +1 -1
  35. package/dist/runtime/index.js +2 -15
  36. package/dist/runtime/index.js.map +1 -1
  37. package/dist/vite.cjs +262 -85
  38. package/dist/vite.cjs.map +1 -1
  39. package/dist/vite.js +262 -85
  40. package/dist/vite.js.map +1 -1
  41. package/dist/webpack.cjs +262 -85
  42. package/dist/webpack.cjs.map +1 -1
  43. package/dist/webpack.js +262 -85
  44. package/dist/webpack.js.map +1 -1
  45. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -558,27 +558,25 @@ var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
558
558
  "use asm"
559
559
  ]);
560
560
  var HELPER_TEMPLATE = acorn2.parse(
561
- `var _ = [].map(function f(a) {
562
- var s = "";
563
- for (var j = 0; j < a.length; j++) {
564
- s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ ((a._u || /\\n/.test(f) * 14) | ((j & 1) * 0))) & 30) | 1));
565
- }
566
- return s;
567
- });`,
561
+ `var _ = (function f(a){return a.map(function(s){var o="";for(var j=0;j<s.length;j++)o+=String.fromCharCode(s.charCodeAt(j)^(((0^((a._u||/\\n/.test(f)*14)|((j&1)*0)))&30)|1));return o;});})([]);`,
568
562
  { ecmaVersion: "latest", sourceType: "script" }
569
563
  ).body[0];
570
564
  function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
571
565
  const node = structuredClone(HELPER_TEMPLATE);
572
566
  node.declarations[0].id.name = cacheVarName;
573
- node.declarations[0].init.callee.object.elements = encryptedPayloads.map(
567
+ node.declarations[0].init.arguments[0].elements = encryptedPayloads.map(
574
568
  (str) => ({
575
569
  type: "Literal",
576
570
  value: str,
577
571
  raw: JSON.stringify(str)
578
572
  })
579
573
  );
580
- const fn = node.declarations[0].init.arguments[0];
581
- const binaryXor = fn.body.body[1].body.body[0].expression.right.arguments[0];
574
+ const outerFn = node.declarations[0].init.callee;
575
+ const returnStmt = outerFn.body.body[0];
576
+ const innerFn = returnStmt.argument.arguments[0];
577
+ const forStmt = innerFn.body.body[1];
578
+ const expr = forStmt.body.type === "BlockStatement" ? forStmt.body.body[0].expression : forStmt.body.expression;
579
+ const binaryXor = expr.right.arguments[0];
582
580
  const innerLeft = binaryXor.right.left.left;
583
581
  innerLeft.left.value = mask;
584
582
  innerLeft.left.raw = String(mask);
@@ -616,44 +614,58 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
616
614
  };
617
615
  }
618
616
  const mask = seed >>> 0 & 30 | 3;
619
- const step = (seed >>> 5 & 7) * 2 + 3;
617
+ const step = 1;
620
618
  const stringToIndex = /* @__PURE__ */ new Map();
621
619
  const encryptedPayloads = [];
622
620
  const targetsToReplace = [];
623
- walk2.ancestor(ast, {
624
- Literal(node, _state, ancestors) {
625
- if (typeof node.value !== "string") return;
626
- const val = node.value;
627
- if (val.length < minStringLength) return;
628
- if (DIRECTIVE_STRINGS.has(val)) return;
629
- if (hotExemptNodes) {
630
- for (let i = ancestors.length - 2; i >= 0; i--) {
631
- if (hotExemptNodes.has(ancestors[i])) {
632
- return;
621
+ const customWalkBase = {
622
+ ...walk2.base,
623
+ Property(node, st, c) {
624
+ c(node.key, st);
625
+ if (node.value) c(node.value, st);
626
+ }
627
+ };
628
+ walk2.ancestor(
629
+ ast,
630
+ {
631
+ Literal(node, _state, ancestors) {
632
+ if (typeof node.value !== "string") return;
633
+ const val = node.value;
634
+ if (val.length < minStringLength) return;
635
+ if (DIRECTIVE_STRINGS.has(val)) return;
636
+ if (hotExemptNodes) {
637
+ for (let i = ancestors.length - 2; i >= 0; i--) {
638
+ if (hotExemptNodes.has(ancestors[i])) {
639
+ return;
640
+ }
633
641
  }
634
642
  }
643
+ const parent = ancestors[ancestors.length - 2];
644
+ if (!parent) return;
645
+ if (parent.type === "ExpressionStatement" && parent.directive) return;
646
+ if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
647
+ if (parent.source === node) return;
648
+ }
649
+ if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
650
+ return;
651
+ }
652
+ if (parent.type === "Property" && parent.key === node) {
653
+ parent.computed = true;
654
+ }
655
+ if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
656
+ return;
657
+ }
658
+ let idx = stringToIndex.get(val);
659
+ if (idx === void 0) {
660
+ idx = encryptedPayloads.length;
661
+ stringToIndex.set(val, idx);
662
+ encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
663
+ }
664
+ targetsToReplace.push({ node, parent });
635
665
  }
636
- const parent = ancestors[ancestors.length - 2];
637
- if (!parent) return;
638
- if (parent.type === "ExpressionStatement" && parent.directive) return;
639
- if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
640
- if (parent.source === node) return;
641
- }
642
- if ((parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
643
- return;
644
- }
645
- if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
646
- return;
647
- }
648
- let idx = stringToIndex.get(val);
649
- if (idx === void 0) {
650
- idx = encryptedPayloads.length;
651
- stringToIndex.set(val, idx);
652
- encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
653
- }
654
- targetsToReplace.push({ node });
655
- }
656
- });
666
+ },
667
+ customWalkBase
668
+ );
657
669
  if (targetsToReplace.length === 0 || encryptedPayloads.length === 0) {
658
670
  return {
659
671
  encryptedStringsCount: 0,
@@ -664,7 +676,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
664
676
  const integrityToken = computeFnv1aHash(serializedTable, seed);
665
677
  const suffix = computeFnv1aHash(`vault:${seed}`, integrityToken).toString(36);
666
678
  const cacheVarName = `_uC${suffix}`;
667
- for (const { node } of targetsToReplace) {
679
+ for (const { node, parent } of targetsToReplace) {
680
+ if (parent?.type === "Property" && parent.key === node) {
681
+ parent.computed = true;
682
+ }
668
683
  const idx = stringToIndex.get(node.value);
669
684
  node.type = "MemberExpression";
670
685
  node.object = {
@@ -1129,10 +1144,174 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1129
1144
 
1130
1145
  // src/ast/cold-flow-guard.ts
1131
1146
  import * as walk4 from "acorn-walk";
1132
- function createOpaqueGuardStatement(seed, fnIndex) {
1133
- const a = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) & 65535;
1134
- const b = (a ^ 4951) & 65535;
1135
- const wrongVal = (a ^ b) & 7 ^ 5;
1147
+ function createDecoyConsequent(fnIndex) {
1148
+ const model = Math.abs(fnIndex) % 3;
1149
+ if (model === 0) {
1150
+ return {
1151
+ type: "BlockStatement",
1152
+ body: [
1153
+ {
1154
+ type: "ReturnStatement",
1155
+ argument: {
1156
+ type: "ObjectExpression",
1157
+ properties: [
1158
+ {
1159
+ type: "Property",
1160
+ key: { type: "Identifier", name: "endpoint" },
1161
+ value: {
1162
+ type: "Literal",
1163
+ value: "/api/v2/auth/admin-bypass",
1164
+ raw: '"/api/v2/auth/admin-bypass"'
1165
+ },
1166
+ kind: "init",
1167
+ computed: false,
1168
+ method: false,
1169
+ shorthand: false
1170
+ },
1171
+ {
1172
+ type: "Property",
1173
+ key: { type: "Identifier", name: "superadmin_token" },
1174
+ value: { type: "Literal", value: 1, raw: "1" },
1175
+ kind: "init",
1176
+ computed: false,
1177
+ method: false,
1178
+ shorthand: false
1179
+ },
1180
+ {
1181
+ type: "Property",
1182
+ key: { type: "Identifier", name: "elevate" },
1183
+ value: { type: "Literal", value: 1, raw: "1" },
1184
+ kind: "init",
1185
+ computed: false,
1186
+ method: false,
1187
+ shorthand: false
1188
+ }
1189
+ ]
1190
+ }
1191
+ }
1192
+ ]
1193
+ };
1194
+ }
1195
+ if (model === 1) {
1196
+ return {
1197
+ type: "BlockStatement",
1198
+ body: [
1199
+ {
1200
+ type: "ReturnStatement",
1201
+ argument: {
1202
+ type: "ObjectExpression",
1203
+ properties: [
1204
+ {
1205
+ type: "Property",
1206
+ key: { type: "Identifier", name: "endpoint" },
1207
+ value: {
1208
+ type: "Literal",
1209
+ value: "/api/v2/auth/verify-master",
1210
+ raw: '"/api/v2/auth/verify-master"'
1211
+ },
1212
+ kind: "init",
1213
+ computed: false,
1214
+ method: false,
1215
+ shorthand: false
1216
+ },
1217
+ {
1218
+ type: "Property",
1219
+ key: { type: "Identifier", name: "_verifyMasterToken" },
1220
+ value: { type: "Literal", value: true, raw: "true" },
1221
+ kind: "init",
1222
+ computed: false,
1223
+ method: false,
1224
+ shorthand: false
1225
+ },
1226
+ {
1227
+ type: "Property",
1228
+ key: { type: "Identifier", name: "_bypassToken" },
1229
+ value: {
1230
+ type: "Literal",
1231
+ value: "mock_jwt_bypass_signature",
1232
+ raw: '"mock_jwt_bypass_signature"'
1233
+ },
1234
+ kind: "init",
1235
+ computed: false,
1236
+ method: false,
1237
+ shorthand: false
1238
+ },
1239
+ {
1240
+ type: "Property",
1241
+ key: { type: "Identifier", name: "authorized" },
1242
+ value: { type: "Literal", value: true, raw: "true" },
1243
+ kind: "init",
1244
+ computed: false,
1245
+ method: false,
1246
+ shorthand: false
1247
+ }
1248
+ ]
1249
+ }
1250
+ }
1251
+ ]
1252
+ };
1253
+ }
1254
+ return {
1255
+ type: "BlockStatement",
1256
+ body: [
1257
+ {
1258
+ type: "ReturnStatement",
1259
+ argument: {
1260
+ type: "ObjectExpression",
1261
+ properties: [
1262
+ {
1263
+ type: "Property",
1264
+ key: { type: "Identifier", name: "endpoint" },
1265
+ value: {
1266
+ type: "Literal",
1267
+ value: "/api/v2/auth/debug-telemetry",
1268
+ raw: '"/api/v2/auth/debug-telemetry"'
1269
+ },
1270
+ kind: "init",
1271
+ computed: false,
1272
+ method: false,
1273
+ shorthand: false
1274
+ },
1275
+ {
1276
+ type: "Property",
1277
+ key: { type: "Identifier", name: "debug_supervisor_override" },
1278
+ value: { type: "Literal", value: true, raw: "true" },
1279
+ kind: "init",
1280
+ computed: false,
1281
+ method: false,
1282
+ shorthand: false
1283
+ },
1284
+ {
1285
+ type: "Property",
1286
+ key: { type: "Identifier", name: "_bypassToken" },
1287
+ value: {
1288
+ type: "Literal",
1289
+ value: "superadmin_token",
1290
+ raw: '"superadmin_token"'
1291
+ },
1292
+ kind: "init",
1293
+ computed: false,
1294
+ method: false,
1295
+ shorthand: false
1296
+ },
1297
+ {
1298
+ type: "Property",
1299
+ key: { type: "Identifier", name: "mfa_bypassed" },
1300
+ value: { type: "Literal", value: true, raw: "true" },
1301
+ kind: "init",
1302
+ computed: false,
1303
+ method: false,
1304
+ shorthand: false
1305
+ }
1306
+ ]
1307
+ }
1308
+ }
1309
+ ]
1310
+ };
1311
+ }
1312
+ function createSotaMbaPredicate(seed, fnIndex = 0) {
1313
+ const x = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) | 0;
1314
+ const y = x ^ 1515870810 | 0;
1136
1315
  return {
1137
1316
  type: "IfStatement",
1138
1317
  test: {
@@ -1140,46 +1319,57 @@ function createOpaqueGuardStatement(seed, fnIndex) {
1140
1319
  operator: "===",
1141
1320
  left: {
1142
1321
  type: "BinaryExpression",
1143
- operator: "&",
1322
+ operator: "|",
1144
1323
  left: {
1145
1324
  type: "BinaryExpression",
1146
1325
  operator: "^",
1147
- left: { type: "Literal", value: a, raw: String(a) },
1148
- right: {
1326
+ left: {
1149
1327
  type: "BinaryExpression",
1150
- operator: "|",
1151
- left: { type: "Literal", value: b, raw: String(b) },
1328
+ operator: "+",
1329
+ left: {
1330
+ type: "BinaryExpression",
1331
+ operator: "|",
1332
+ left: { type: "Literal", value: x, raw: String(x) },
1333
+ right: { type: "Literal", value: y, raw: String(y) }
1334
+ },
1152
1335
  right: {
1153
- type: "UnaryExpression",
1154
- operator: "!",
1155
- prefix: true,
1156
- argument: { type: "Identifier", name: "String" }
1336
+ type: "BinaryExpression",
1337
+ operator: "&",
1338
+ left: { type: "Literal", value: x, raw: String(x) },
1339
+ right: { type: "Literal", value: y, raw: String(y) }
1157
1340
  }
1341
+ },
1342
+ right: {
1343
+ type: "BinaryExpression",
1344
+ operator: "+",
1345
+ left: { type: "Literal", value: x, raw: String(x) },
1346
+ right: { type: "Literal", value: y, raw: String(y) }
1158
1347
  }
1159
1348
  },
1160
- right: { type: "Literal", value: 7, raw: "7" }
1349
+ right: {
1350
+ type: "UnaryExpression",
1351
+ operator: "!",
1352
+ prefix: true,
1353
+ argument: { type: "Identifier", name: "String" }
1354
+ }
1161
1355
  },
1162
- right: { type: "Literal", value: wrongVal, raw: String(wrongVal) }
1163
- },
1164
- consequent: {
1165
- type: "ExpressionStatement",
1166
- expression: {
1167
- type: "UnaryExpression",
1168
- operator: "void",
1169
- prefix: true,
1170
- argument: { type: "Literal", value: 0, raw: "0" }
1171
- }
1356
+ right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
1172
1357
  },
1358
+ consequent: createDecoyConsequent(fnIndex),
1173
1359
  alternate: null
1174
1360
  };
1175
1361
  }
1176
- function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769) {
1362
+ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
1177
1363
  let guardedCount = 0;
1178
1364
  function maybeInjectGuard(node) {
1179
1365
  if (!coldFunctionNodes.has(node)) return;
1180
1366
  if (!node.body || node.body.type !== "BlockStatement") return;
1367
+ const guardStmt = createSotaMbaPredicate(seed, 0);
1181
1368
  guardedCount++;
1182
- const guardStmt = createOpaqueGuardStatement(seed, guardedCount);
1369
+ if (hotExemptNodes) {
1370
+ hotExemptNodes.add(guardStmt);
1371
+ hotExemptNodes.add(guardStmt.consequent);
1372
+ }
1183
1373
  let insertIdx = 0;
1184
1374
  while (insertIdx < node.body.body.length && node.body.body[insertIdx].type === "ExpressionStatement" && node.body.body[insertIdx].directive) {
1185
1375
  insertIdx++;
@@ -1215,25 +1405,12 @@ function deriveIntegrityFnName(seed) {
1215
1405
  const hash = computeIntegrityHash(`unpeek:fn:${seed}`, seed);
1216
1406
  return `_u$${hash.toString(36)}`;
1217
1407
  }
1218
- function deriveLocalVar(label, seed) {
1219
- const hash = computeIntegrityHash(`unpeek:var:${label}:${seed}`, seed) & 1048575;
1220
- return `_${label}${hash.toString(36)}`;
1221
- }
1222
1408
  function createDeterrentSnippet(config) {
1223
1409
  const seed = config.seed >>> 0;
1224
- const expectedToken = (config.expectedIntegrityHash ?? seed) >>> 0;
1225
1410
  const deterrentMode = config.deterrentMode ?? "passive";
1226
1411
  const fnName = deriveIntegrityFnName(seed);
1227
- const strVar = deriveLocalVar("s", seed);
1228
- const tamperVar = deriveLocalVar("t", seed);
1229
- const noopVar = deriveLocalVar("n", seed);
1230
- const methodsVar = deriveLocalVar("m", seed);
1231
- const idxVar = deriveLocalVar("i", seed);
1232
- const errVar = deriveLocalVar("e", seed);
1233
- const tokenBit = expectedToken & 1;
1234
- const gradualConsoleSilence = deterrentMode === "gradual" ? `if(typeof console!=='undefined'){var ${noopVar}=function(){},${methodsVar}=['log','debug','info','table','dir'];for(var ${idxVar}=0;${idxVar}<${methodsVar}.length;${idxVar}++){try{console[${methodsVar}[${idxVar}]]=${noopVar};}catch(${errVar}){}}}` : "";
1235
- const tamperDispatch = `if(window.dispatchEvent&&typeof CustomEvent!=='undefined'){try{window.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(${errVar}){}}`;
1236
- return `(function ${fnName}(){if(typeof window!=='undefined'){try{var ${strVar}=Function.prototype.toString,${tamperVar}=${strVar}.call(${strVar}).indexOf('[native code]')<${tokenBit - 1}||/[\\r\\n]/.test(${strVar}.call(${fnName}));if(${tamperVar}){window.__unpeek_tampered=!0;${tamperDispatch}${gradualConsoleSilence}String.prototype._u=14;}}catch(${errVar}){}}})();`;
1412
+ const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=f=>0;" : "";
1413
+ return `(function ${fnName}(w){if(w){try{(w.queueMicrotask||w.requestIdleCallback||(f=>f()))(function f(a){var s=Function.prototype.toString,n=w.navigator||0,t=s.call(s).indexOf('[native code]')<0||/\\n/.test(s.call(${fnName}))||n.webdriver||/HeadlessChrome/.test(n.userAgent);if(t){w.__unpeek_tampered=!0,w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0,String.prototype._u=14;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}});}catch(e){}}})(typeof window!=='undefined'&&window);`;
1237
1414
  }
1238
1415
 
1239
1416
  // src/runtime/index.ts
@@ -1298,7 +1475,7 @@ function transformJavaScript(code, options = {}) {
1298
1475
  coldFunctionNodes,
1299
1476
  hotExemptNodes
1300
1477
  } = analyzeAstHotPaths(ast);
1301
- applyColdFlowGuard(ast, coldFunctionNodes, seed);
1478
+ applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
1302
1479
  const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
1303
1480
  const { encryptedStringsCount, integrityToken } = applyStringVault(
1304
1481
  ast,
@@ -1810,7 +1987,7 @@ ${finalCode}`;
1810
1987
 
1811
1988
  // src/cli/index.ts
1812
1989
  import fs5 from "fs";
1813
- var VERSION = "1.6.2";
1990
+ var VERSION = "1.7.2";
1814
1991
  function getPackageVersion() {
1815
1992
  try {
1816
1993
  const pkgUrl = new URL("../../package.json", import.meta.url);