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.cjs CHANGED
@@ -615,27 +615,25 @@ var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
615
615
  "use asm"
616
616
  ]);
617
617
  var HELPER_TEMPLATE = acorn2.parse(
618
- `var _ = [].map(function f(a) {
619
- var s = "";
620
- for (var j = 0; j < a.length; j++) {
621
- s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ ((a._u || /\\n/.test(f) * 14) | ((j & 1) * 0))) & 30) | 1));
622
- }
623
- return s;
624
- });`,
618
+ `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;});})([]);`,
625
619
  { ecmaVersion: "latest", sourceType: "script" }
626
620
  ).body[0];
627
621
  function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
628
622
  const node = structuredClone(HELPER_TEMPLATE);
629
623
  node.declarations[0].id.name = cacheVarName;
630
- node.declarations[0].init.callee.object.elements = encryptedPayloads.map(
624
+ node.declarations[0].init.arguments[0].elements = encryptedPayloads.map(
631
625
  (str) => ({
632
626
  type: "Literal",
633
627
  value: str,
634
628
  raw: JSON.stringify(str)
635
629
  })
636
630
  );
637
- const fn = node.declarations[0].init.arguments[0];
638
- const binaryXor = fn.body.body[1].body.body[0].expression.right.arguments[0];
631
+ const outerFn = node.declarations[0].init.callee;
632
+ const returnStmt = outerFn.body.body[0];
633
+ const innerFn = returnStmt.argument.arguments[0];
634
+ const forStmt = innerFn.body.body[1];
635
+ const expr = forStmt.body.type === "BlockStatement" ? forStmt.body.body[0].expression : forStmt.body.expression;
636
+ const binaryXor = expr.right.arguments[0];
639
637
  const innerLeft = binaryXor.right.left.left;
640
638
  innerLeft.left.value = mask;
641
639
  innerLeft.left.raw = String(mask);
@@ -673,44 +671,58 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
673
671
  };
674
672
  }
675
673
  const mask = seed >>> 0 & 30 | 3;
676
- const step = (seed >>> 5 & 7) * 2 + 3;
674
+ const step = 1;
677
675
  const stringToIndex = /* @__PURE__ */ new Map();
678
676
  const encryptedPayloads = [];
679
677
  const targetsToReplace = [];
680
- walk2.ancestor(ast, {
681
- Literal(node, _state, ancestors) {
682
- if (typeof node.value !== "string") return;
683
- const val = node.value;
684
- if (val.length < minStringLength) return;
685
- if (DIRECTIVE_STRINGS.has(val)) return;
686
- if (hotExemptNodes) {
687
- for (let i = ancestors.length - 2; i >= 0; i--) {
688
- if (hotExemptNodes.has(ancestors[i])) {
689
- return;
678
+ const customWalkBase = {
679
+ ...walk2.base,
680
+ Property(node, st, c) {
681
+ c(node.key, st);
682
+ if (node.value) c(node.value, st);
683
+ }
684
+ };
685
+ walk2.ancestor(
686
+ ast,
687
+ {
688
+ Literal(node, _state, ancestors) {
689
+ if (typeof node.value !== "string") return;
690
+ const val = node.value;
691
+ if (val.length < minStringLength) return;
692
+ if (DIRECTIVE_STRINGS.has(val)) return;
693
+ if (hotExemptNodes) {
694
+ for (let i = ancestors.length - 2; i >= 0; i--) {
695
+ if (hotExemptNodes.has(ancestors[i])) {
696
+ return;
697
+ }
690
698
  }
691
699
  }
700
+ const parent = ancestors[ancestors.length - 2];
701
+ if (!parent) return;
702
+ if (parent.type === "ExpressionStatement" && parent.directive) return;
703
+ if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
704
+ if (parent.source === node) return;
705
+ }
706
+ if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
707
+ return;
708
+ }
709
+ if (parent.type === "Property" && parent.key === node) {
710
+ parent.computed = true;
711
+ }
712
+ if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
713
+ return;
714
+ }
715
+ let idx = stringToIndex.get(val);
716
+ if (idx === void 0) {
717
+ idx = encryptedPayloads.length;
718
+ stringToIndex.set(val, idx);
719
+ encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
720
+ }
721
+ targetsToReplace.push({ node, parent });
692
722
  }
693
- const parent = ancestors[ancestors.length - 2];
694
- if (!parent) return;
695
- if (parent.type === "ExpressionStatement" && parent.directive) return;
696
- if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
697
- if (parent.source === node) return;
698
- }
699
- if ((parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
700
- return;
701
- }
702
- if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
703
- return;
704
- }
705
- let idx = stringToIndex.get(val);
706
- if (idx === void 0) {
707
- idx = encryptedPayloads.length;
708
- stringToIndex.set(val, idx);
709
- encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
710
- }
711
- targetsToReplace.push({ node });
712
- }
713
- });
723
+ },
724
+ customWalkBase
725
+ );
714
726
  if (targetsToReplace.length === 0 || encryptedPayloads.length === 0) {
715
727
  return {
716
728
  encryptedStringsCount: 0,
@@ -721,7 +733,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
721
733
  const integrityToken = computeFnv1aHash(serializedTable, seed);
722
734
  const suffix = computeFnv1aHash(`vault:${seed}`, integrityToken).toString(36);
723
735
  const cacheVarName = `_uC${suffix}`;
724
- for (const { node } of targetsToReplace) {
736
+ for (const { node, parent } of targetsToReplace) {
737
+ if (parent?.type === "Property" && parent.key === node) {
738
+ parent.computed = true;
739
+ }
725
740
  const idx = stringToIndex.get(node.value);
726
741
  node.type = "MemberExpression";
727
742
  node.object = {
@@ -1186,10 +1201,174 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1186
1201
 
1187
1202
  // src/ast/cold-flow-guard.ts
1188
1203
  var walk4 = __toESM(require("acorn-walk"), 1);
1189
- function createOpaqueGuardStatement(seed, fnIndex) {
1190
- const a = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) & 65535;
1191
- const b = (a ^ 4951) & 65535;
1192
- const wrongVal = (a ^ b) & 7 ^ 5;
1204
+ function createDecoyConsequent(fnIndex) {
1205
+ const model = Math.abs(fnIndex) % 3;
1206
+ if (model === 0) {
1207
+ return {
1208
+ type: "BlockStatement",
1209
+ body: [
1210
+ {
1211
+ type: "ReturnStatement",
1212
+ argument: {
1213
+ type: "ObjectExpression",
1214
+ properties: [
1215
+ {
1216
+ type: "Property",
1217
+ key: { type: "Identifier", name: "endpoint" },
1218
+ value: {
1219
+ type: "Literal",
1220
+ value: "/api/v2/auth/admin-bypass",
1221
+ raw: '"/api/v2/auth/admin-bypass"'
1222
+ },
1223
+ kind: "init",
1224
+ computed: false,
1225
+ method: false,
1226
+ shorthand: false
1227
+ },
1228
+ {
1229
+ type: "Property",
1230
+ key: { type: "Identifier", name: "superadmin_token" },
1231
+ value: { type: "Literal", value: 1, raw: "1" },
1232
+ kind: "init",
1233
+ computed: false,
1234
+ method: false,
1235
+ shorthand: false
1236
+ },
1237
+ {
1238
+ type: "Property",
1239
+ key: { type: "Identifier", name: "elevate" },
1240
+ value: { type: "Literal", value: 1, raw: "1" },
1241
+ kind: "init",
1242
+ computed: false,
1243
+ method: false,
1244
+ shorthand: false
1245
+ }
1246
+ ]
1247
+ }
1248
+ }
1249
+ ]
1250
+ };
1251
+ }
1252
+ if (model === 1) {
1253
+ return {
1254
+ type: "BlockStatement",
1255
+ body: [
1256
+ {
1257
+ type: "ReturnStatement",
1258
+ argument: {
1259
+ type: "ObjectExpression",
1260
+ properties: [
1261
+ {
1262
+ type: "Property",
1263
+ key: { type: "Identifier", name: "endpoint" },
1264
+ value: {
1265
+ type: "Literal",
1266
+ value: "/api/v2/auth/verify-master",
1267
+ raw: '"/api/v2/auth/verify-master"'
1268
+ },
1269
+ kind: "init",
1270
+ computed: false,
1271
+ method: false,
1272
+ shorthand: false
1273
+ },
1274
+ {
1275
+ type: "Property",
1276
+ key: { type: "Identifier", name: "_verifyMasterToken" },
1277
+ value: { type: "Literal", value: true, raw: "true" },
1278
+ kind: "init",
1279
+ computed: false,
1280
+ method: false,
1281
+ shorthand: false
1282
+ },
1283
+ {
1284
+ type: "Property",
1285
+ key: { type: "Identifier", name: "_bypassToken" },
1286
+ value: {
1287
+ type: "Literal",
1288
+ value: "mock_jwt_bypass_signature",
1289
+ raw: '"mock_jwt_bypass_signature"'
1290
+ },
1291
+ kind: "init",
1292
+ computed: false,
1293
+ method: false,
1294
+ shorthand: false
1295
+ },
1296
+ {
1297
+ type: "Property",
1298
+ key: { type: "Identifier", name: "authorized" },
1299
+ value: { type: "Literal", value: true, raw: "true" },
1300
+ kind: "init",
1301
+ computed: false,
1302
+ method: false,
1303
+ shorthand: false
1304
+ }
1305
+ ]
1306
+ }
1307
+ }
1308
+ ]
1309
+ };
1310
+ }
1311
+ return {
1312
+ type: "BlockStatement",
1313
+ body: [
1314
+ {
1315
+ type: "ReturnStatement",
1316
+ argument: {
1317
+ type: "ObjectExpression",
1318
+ properties: [
1319
+ {
1320
+ type: "Property",
1321
+ key: { type: "Identifier", name: "endpoint" },
1322
+ value: {
1323
+ type: "Literal",
1324
+ value: "/api/v2/auth/debug-telemetry",
1325
+ raw: '"/api/v2/auth/debug-telemetry"'
1326
+ },
1327
+ kind: "init",
1328
+ computed: false,
1329
+ method: false,
1330
+ shorthand: false
1331
+ },
1332
+ {
1333
+ type: "Property",
1334
+ key: { type: "Identifier", name: "debug_supervisor_override" },
1335
+ value: { type: "Literal", value: true, raw: "true" },
1336
+ kind: "init",
1337
+ computed: false,
1338
+ method: false,
1339
+ shorthand: false
1340
+ },
1341
+ {
1342
+ type: "Property",
1343
+ key: { type: "Identifier", name: "_bypassToken" },
1344
+ value: {
1345
+ type: "Literal",
1346
+ value: "superadmin_token",
1347
+ raw: '"superadmin_token"'
1348
+ },
1349
+ kind: "init",
1350
+ computed: false,
1351
+ method: false,
1352
+ shorthand: false
1353
+ },
1354
+ {
1355
+ type: "Property",
1356
+ key: { type: "Identifier", name: "mfa_bypassed" },
1357
+ value: { type: "Literal", value: true, raw: "true" },
1358
+ kind: "init",
1359
+ computed: false,
1360
+ method: false,
1361
+ shorthand: false
1362
+ }
1363
+ ]
1364
+ }
1365
+ }
1366
+ ]
1367
+ };
1368
+ }
1369
+ function createSotaMbaPredicate(seed, fnIndex = 0) {
1370
+ const x = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) | 0;
1371
+ const y = x ^ 1515870810 | 0;
1193
1372
  return {
1194
1373
  type: "IfStatement",
1195
1374
  test: {
@@ -1197,46 +1376,57 @@ function createOpaqueGuardStatement(seed, fnIndex) {
1197
1376
  operator: "===",
1198
1377
  left: {
1199
1378
  type: "BinaryExpression",
1200
- operator: "&",
1379
+ operator: "|",
1201
1380
  left: {
1202
1381
  type: "BinaryExpression",
1203
1382
  operator: "^",
1204
- left: { type: "Literal", value: a, raw: String(a) },
1205
- right: {
1383
+ left: {
1206
1384
  type: "BinaryExpression",
1207
- operator: "|",
1208
- left: { type: "Literal", value: b, raw: String(b) },
1385
+ operator: "+",
1386
+ left: {
1387
+ type: "BinaryExpression",
1388
+ operator: "|",
1389
+ left: { type: "Literal", value: x, raw: String(x) },
1390
+ right: { type: "Literal", value: y, raw: String(y) }
1391
+ },
1209
1392
  right: {
1210
- type: "UnaryExpression",
1211
- operator: "!",
1212
- prefix: true,
1213
- argument: { type: "Identifier", name: "String" }
1393
+ type: "BinaryExpression",
1394
+ operator: "&",
1395
+ left: { type: "Literal", value: x, raw: String(x) },
1396
+ right: { type: "Literal", value: y, raw: String(y) }
1214
1397
  }
1398
+ },
1399
+ right: {
1400
+ type: "BinaryExpression",
1401
+ operator: "+",
1402
+ left: { type: "Literal", value: x, raw: String(x) },
1403
+ right: { type: "Literal", value: y, raw: String(y) }
1215
1404
  }
1216
1405
  },
1217
- right: { type: "Literal", value: 7, raw: "7" }
1406
+ right: {
1407
+ type: "UnaryExpression",
1408
+ operator: "!",
1409
+ prefix: true,
1410
+ argument: { type: "Identifier", name: "String" }
1411
+ }
1218
1412
  },
1219
- right: { type: "Literal", value: wrongVal, raw: String(wrongVal) }
1220
- },
1221
- consequent: {
1222
- type: "ExpressionStatement",
1223
- expression: {
1224
- type: "UnaryExpression",
1225
- operator: "void",
1226
- prefix: true,
1227
- argument: { type: "Literal", value: 0, raw: "0" }
1228
- }
1413
+ right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
1229
1414
  },
1415
+ consequent: createDecoyConsequent(fnIndex),
1230
1416
  alternate: null
1231
1417
  };
1232
1418
  }
1233
- function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769) {
1419
+ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
1234
1420
  let guardedCount = 0;
1235
1421
  function maybeInjectGuard(node) {
1236
1422
  if (!coldFunctionNodes.has(node)) return;
1237
1423
  if (!node.body || node.body.type !== "BlockStatement") return;
1424
+ const guardStmt = createSotaMbaPredicate(seed, 0);
1238
1425
  guardedCount++;
1239
- const guardStmt = createOpaqueGuardStatement(seed, guardedCount);
1426
+ if (hotExemptNodes) {
1427
+ hotExemptNodes.add(guardStmt);
1428
+ hotExemptNodes.add(guardStmt.consequent);
1429
+ }
1240
1430
  let insertIdx = 0;
1241
1431
  while (insertIdx < node.body.body.length && node.body.body[insertIdx].type === "ExpressionStatement" && node.body.body[insertIdx].directive) {
1242
1432
  insertIdx++;
@@ -1272,25 +1462,12 @@ function deriveIntegrityFnName(seed) {
1272
1462
  const hash = computeIntegrityHash(`unpeek:fn:${seed}`, seed);
1273
1463
  return `_u$${hash.toString(36)}`;
1274
1464
  }
1275
- function deriveLocalVar(label, seed) {
1276
- const hash = computeIntegrityHash(`unpeek:var:${label}:${seed}`, seed) & 1048575;
1277
- return `_${label}${hash.toString(36)}`;
1278
- }
1279
1465
  function createDeterrentSnippet(config) {
1280
1466
  const seed = config.seed >>> 0;
1281
- const expectedToken = (config.expectedIntegrityHash ?? seed) >>> 0;
1282
1467
  const deterrentMode = config.deterrentMode ?? "passive";
1283
1468
  const fnName = deriveIntegrityFnName(seed);
1284
- const strVar = deriveLocalVar("s", seed);
1285
- const tamperVar = deriveLocalVar("t", seed);
1286
- const noopVar = deriveLocalVar("n", seed);
1287
- const methodsVar = deriveLocalVar("m", seed);
1288
- const idxVar = deriveLocalVar("i", seed);
1289
- const errVar = deriveLocalVar("e", seed);
1290
- const tokenBit = expectedToken & 1;
1291
- 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}){}}}` : "";
1292
- const tamperDispatch = `if(window.dispatchEvent&&typeof CustomEvent!=='undefined'){try{window.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(${errVar}){}}`;
1293
- 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}){}}})();`;
1469
+ const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=f=>0;" : "";
1470
+ 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);`;
1294
1471
  }
1295
1472
 
1296
1473
  // src/runtime/index.ts
@@ -1355,7 +1532,7 @@ function transformJavaScript(code, options = {}) {
1355
1532
  coldFunctionNodes,
1356
1533
  hotExemptNodes
1357
1534
  } = analyzeAstHotPaths(ast);
1358
- applyColdFlowGuard(ast, coldFunctionNodes, seed);
1535
+ applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
1359
1536
  const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
1360
1537
  const { encryptedStringsCount, integrityToken } = applyStringVault(
1361
1538
  ast,
@@ -1867,7 +2044,7 @@ ${finalCode}`;
1867
2044
 
1868
2045
  // src/cli/index.ts
1869
2046
  var import_node_fs5 = __toESM(require("fs"), 1);
1870
- var VERSION = "1.6.2";
2047
+ var VERSION = "1.7.2";
1871
2048
  function getPackageVersion() {
1872
2049
  try {
1873
2050
  const pkgUrl = new URL("../../package.json", importMetaUrl);