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
@@ -805,27 +805,25 @@ var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
805
805
  "use asm"
806
806
  ]);
807
807
  var HELPER_TEMPLATE = acorn2.parse(
808
- `var _ = [].map(function f(a) {
809
- var s = "";
810
- for (var j = 0; j < a.length; j++) {
811
- s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ ((a._u || /\\n/.test(f) * 14) | ((j & 1) * 0))) & 30) | 1));
812
- }
813
- return s;
814
- });`,
808
+ `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;});})([]);`,
815
809
  { ecmaVersion: "latest", sourceType: "script" }
816
810
  ).body[0];
817
811
  function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
818
812
  const node = structuredClone(HELPER_TEMPLATE);
819
813
  node.declarations[0].id.name = cacheVarName;
820
- node.declarations[0].init.callee.object.elements = encryptedPayloads.map(
814
+ node.declarations[0].init.arguments[0].elements = encryptedPayloads.map(
821
815
  (str) => ({
822
816
  type: "Literal",
823
817
  value: str,
824
818
  raw: JSON.stringify(str)
825
819
  })
826
820
  );
827
- const fn = node.declarations[0].init.arguments[0];
828
- const binaryXor = fn.body.body[1].body.body[0].expression.right.arguments[0];
821
+ const outerFn = node.declarations[0].init.callee;
822
+ const returnStmt = outerFn.body.body[0];
823
+ const innerFn = returnStmt.argument.arguments[0];
824
+ const forStmt = innerFn.body.body[1];
825
+ const expr = forStmt.body.type === "BlockStatement" ? forStmt.body.body[0].expression : forStmt.body.expression;
826
+ const binaryXor = expr.right.arguments[0];
829
827
  const innerLeft = binaryXor.right.left.left;
830
828
  innerLeft.left.value = mask;
831
829
  innerLeft.left.raw = String(mask);
@@ -863,44 +861,58 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
863
861
  };
864
862
  }
865
863
  const mask = seed >>> 0 & 30 | 3;
866
- const step = (seed >>> 5 & 7) * 2 + 3;
864
+ const step = 1;
867
865
  const stringToIndex = /* @__PURE__ */ new Map();
868
866
  const encryptedPayloads = [];
869
867
  const targetsToReplace = [];
870
- walk2.ancestor(ast, {
871
- Literal(node, _state, ancestors) {
872
- if (typeof node.value !== "string") return;
873
- const val = node.value;
874
- if (val.length < minStringLength) return;
875
- if (DIRECTIVE_STRINGS.has(val)) return;
876
- if (hotExemptNodes) {
877
- for (let i = ancestors.length - 2; i >= 0; i--) {
878
- if (hotExemptNodes.has(ancestors[i])) {
879
- return;
868
+ const customWalkBase = {
869
+ ...walk2.base,
870
+ Property(node, st, c) {
871
+ c(node.key, st);
872
+ if (node.value) c(node.value, st);
873
+ }
874
+ };
875
+ walk2.ancestor(
876
+ ast,
877
+ {
878
+ Literal(node, _state, ancestors) {
879
+ if (typeof node.value !== "string") return;
880
+ const val = node.value;
881
+ if (val.length < minStringLength) return;
882
+ if (DIRECTIVE_STRINGS.has(val)) return;
883
+ if (hotExemptNodes) {
884
+ for (let i = ancestors.length - 2; i >= 0; i--) {
885
+ if (hotExemptNodes.has(ancestors[i])) {
886
+ return;
887
+ }
880
888
  }
881
889
  }
890
+ const parent = ancestors[ancestors.length - 2];
891
+ if (!parent) return;
892
+ if (parent.type === "ExpressionStatement" && parent.directive) return;
893
+ if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
894
+ if (parent.source === node) return;
895
+ }
896
+ if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
897
+ return;
898
+ }
899
+ if (parent.type === "Property" && parent.key === node) {
900
+ parent.computed = true;
901
+ }
902
+ if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
903
+ return;
904
+ }
905
+ let idx = stringToIndex.get(val);
906
+ if (idx === void 0) {
907
+ idx = encryptedPayloads.length;
908
+ stringToIndex.set(val, idx);
909
+ encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
910
+ }
911
+ targetsToReplace.push({ node, parent });
882
912
  }
883
- const parent = ancestors[ancestors.length - 2];
884
- if (!parent) return;
885
- if (parent.type === "ExpressionStatement" && parent.directive) return;
886
- if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
887
- if (parent.source === node) return;
888
- }
889
- if ((parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
890
- return;
891
- }
892
- if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
893
- return;
894
- }
895
- let idx = stringToIndex.get(val);
896
- if (idx === void 0) {
897
- idx = encryptedPayloads.length;
898
- stringToIndex.set(val, idx);
899
- encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
900
- }
901
- targetsToReplace.push({ node });
902
- }
903
- });
913
+ },
914
+ customWalkBase
915
+ );
904
916
  if (targetsToReplace.length === 0 || encryptedPayloads.length === 0) {
905
917
  return {
906
918
  encryptedStringsCount: 0,
@@ -911,7 +923,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
911
923
  const integrityToken = computeFnv1aHash(serializedTable, seed);
912
924
  const suffix = computeFnv1aHash(`vault:${seed}`, integrityToken).toString(36);
913
925
  const cacheVarName = `_uC${suffix}`;
914
- for (const { node } of targetsToReplace) {
926
+ for (const { node, parent } of targetsToReplace) {
927
+ if (parent?.type === "Property" && parent.key === node) {
928
+ parent.computed = true;
929
+ }
915
930
  const idx = stringToIndex.get(node.value);
916
931
  node.type = "MemberExpression";
917
932
  node.object = {
@@ -1376,10 +1391,174 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1376
1391
 
1377
1392
  // src/ast/cold-flow-guard.ts
1378
1393
  import * as walk4 from "acorn-walk";
1379
- function createOpaqueGuardStatement(seed, fnIndex) {
1380
- const a = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) & 65535;
1381
- const b = (a ^ 4951) & 65535;
1382
- const wrongVal = (a ^ b) & 7 ^ 5;
1394
+ function createDecoyConsequent(fnIndex) {
1395
+ const model = Math.abs(fnIndex) % 3;
1396
+ if (model === 0) {
1397
+ return {
1398
+ type: "BlockStatement",
1399
+ body: [
1400
+ {
1401
+ type: "ReturnStatement",
1402
+ argument: {
1403
+ type: "ObjectExpression",
1404
+ properties: [
1405
+ {
1406
+ type: "Property",
1407
+ key: { type: "Identifier", name: "endpoint" },
1408
+ value: {
1409
+ type: "Literal",
1410
+ value: "/api/v2/auth/admin-bypass",
1411
+ raw: '"/api/v2/auth/admin-bypass"'
1412
+ },
1413
+ kind: "init",
1414
+ computed: false,
1415
+ method: false,
1416
+ shorthand: false
1417
+ },
1418
+ {
1419
+ type: "Property",
1420
+ key: { type: "Identifier", name: "superadmin_token" },
1421
+ value: { type: "Literal", value: 1, raw: "1" },
1422
+ kind: "init",
1423
+ computed: false,
1424
+ method: false,
1425
+ shorthand: false
1426
+ },
1427
+ {
1428
+ type: "Property",
1429
+ key: { type: "Identifier", name: "elevate" },
1430
+ value: { type: "Literal", value: 1, raw: "1" },
1431
+ kind: "init",
1432
+ computed: false,
1433
+ method: false,
1434
+ shorthand: false
1435
+ }
1436
+ ]
1437
+ }
1438
+ }
1439
+ ]
1440
+ };
1441
+ }
1442
+ if (model === 1) {
1443
+ return {
1444
+ type: "BlockStatement",
1445
+ body: [
1446
+ {
1447
+ type: "ReturnStatement",
1448
+ argument: {
1449
+ type: "ObjectExpression",
1450
+ properties: [
1451
+ {
1452
+ type: "Property",
1453
+ key: { type: "Identifier", name: "endpoint" },
1454
+ value: {
1455
+ type: "Literal",
1456
+ value: "/api/v2/auth/verify-master",
1457
+ raw: '"/api/v2/auth/verify-master"'
1458
+ },
1459
+ kind: "init",
1460
+ computed: false,
1461
+ method: false,
1462
+ shorthand: false
1463
+ },
1464
+ {
1465
+ type: "Property",
1466
+ key: { type: "Identifier", name: "_verifyMasterToken" },
1467
+ value: { type: "Literal", value: true, raw: "true" },
1468
+ kind: "init",
1469
+ computed: false,
1470
+ method: false,
1471
+ shorthand: false
1472
+ },
1473
+ {
1474
+ type: "Property",
1475
+ key: { type: "Identifier", name: "_bypassToken" },
1476
+ value: {
1477
+ type: "Literal",
1478
+ value: "mock_jwt_bypass_signature",
1479
+ raw: '"mock_jwt_bypass_signature"'
1480
+ },
1481
+ kind: "init",
1482
+ computed: false,
1483
+ method: false,
1484
+ shorthand: false
1485
+ },
1486
+ {
1487
+ type: "Property",
1488
+ key: { type: "Identifier", name: "authorized" },
1489
+ value: { type: "Literal", value: true, raw: "true" },
1490
+ kind: "init",
1491
+ computed: false,
1492
+ method: false,
1493
+ shorthand: false
1494
+ }
1495
+ ]
1496
+ }
1497
+ }
1498
+ ]
1499
+ };
1500
+ }
1501
+ return {
1502
+ type: "BlockStatement",
1503
+ body: [
1504
+ {
1505
+ type: "ReturnStatement",
1506
+ argument: {
1507
+ type: "ObjectExpression",
1508
+ properties: [
1509
+ {
1510
+ type: "Property",
1511
+ key: { type: "Identifier", name: "endpoint" },
1512
+ value: {
1513
+ type: "Literal",
1514
+ value: "/api/v2/auth/debug-telemetry",
1515
+ raw: '"/api/v2/auth/debug-telemetry"'
1516
+ },
1517
+ kind: "init",
1518
+ computed: false,
1519
+ method: false,
1520
+ shorthand: false
1521
+ },
1522
+ {
1523
+ type: "Property",
1524
+ key: { type: "Identifier", name: "debug_supervisor_override" },
1525
+ value: { type: "Literal", value: true, raw: "true" },
1526
+ kind: "init",
1527
+ computed: false,
1528
+ method: false,
1529
+ shorthand: false
1530
+ },
1531
+ {
1532
+ type: "Property",
1533
+ key: { type: "Identifier", name: "_bypassToken" },
1534
+ value: {
1535
+ type: "Literal",
1536
+ value: "superadmin_token",
1537
+ raw: '"superadmin_token"'
1538
+ },
1539
+ kind: "init",
1540
+ computed: false,
1541
+ method: false,
1542
+ shorthand: false
1543
+ },
1544
+ {
1545
+ type: "Property",
1546
+ key: { type: "Identifier", name: "mfa_bypassed" },
1547
+ value: { type: "Literal", value: true, raw: "true" },
1548
+ kind: "init",
1549
+ computed: false,
1550
+ method: false,
1551
+ shorthand: false
1552
+ }
1553
+ ]
1554
+ }
1555
+ }
1556
+ ]
1557
+ };
1558
+ }
1559
+ function createSotaMbaPredicate(seed, fnIndex = 0) {
1560
+ const x = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) | 0;
1561
+ const y = x ^ 1515870810 | 0;
1383
1562
  return {
1384
1563
  type: "IfStatement",
1385
1564
  test: {
@@ -1387,46 +1566,57 @@ function createOpaqueGuardStatement(seed, fnIndex) {
1387
1566
  operator: "===",
1388
1567
  left: {
1389
1568
  type: "BinaryExpression",
1390
- operator: "&",
1569
+ operator: "|",
1391
1570
  left: {
1392
1571
  type: "BinaryExpression",
1393
1572
  operator: "^",
1394
- left: { type: "Literal", value: a, raw: String(a) },
1395
- right: {
1573
+ left: {
1396
1574
  type: "BinaryExpression",
1397
- operator: "|",
1398
- left: { type: "Literal", value: b, raw: String(b) },
1575
+ operator: "+",
1576
+ left: {
1577
+ type: "BinaryExpression",
1578
+ operator: "|",
1579
+ left: { type: "Literal", value: x, raw: String(x) },
1580
+ right: { type: "Literal", value: y, raw: String(y) }
1581
+ },
1399
1582
  right: {
1400
- type: "UnaryExpression",
1401
- operator: "!",
1402
- prefix: true,
1403
- argument: { type: "Identifier", name: "String" }
1583
+ type: "BinaryExpression",
1584
+ operator: "&",
1585
+ left: { type: "Literal", value: x, raw: String(x) },
1586
+ right: { type: "Literal", value: y, raw: String(y) }
1404
1587
  }
1588
+ },
1589
+ right: {
1590
+ type: "BinaryExpression",
1591
+ operator: "+",
1592
+ left: { type: "Literal", value: x, raw: String(x) },
1593
+ right: { type: "Literal", value: y, raw: String(y) }
1405
1594
  }
1406
1595
  },
1407
- right: { type: "Literal", value: 7, raw: "7" }
1596
+ right: {
1597
+ type: "UnaryExpression",
1598
+ operator: "!",
1599
+ prefix: true,
1600
+ argument: { type: "Identifier", name: "String" }
1601
+ }
1408
1602
  },
1409
- right: { type: "Literal", value: wrongVal, raw: String(wrongVal) }
1410
- },
1411
- consequent: {
1412
- type: "ExpressionStatement",
1413
- expression: {
1414
- type: "UnaryExpression",
1415
- operator: "void",
1416
- prefix: true,
1417
- argument: { type: "Literal", value: 0, raw: "0" }
1418
- }
1603
+ right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
1419
1604
  },
1605
+ consequent: createDecoyConsequent(fnIndex),
1420
1606
  alternate: null
1421
1607
  };
1422
1608
  }
1423
- function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769) {
1609
+ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
1424
1610
  let guardedCount = 0;
1425
1611
  function maybeInjectGuard(node) {
1426
1612
  if (!coldFunctionNodes.has(node)) return;
1427
1613
  if (!node.body || node.body.type !== "BlockStatement") return;
1614
+ const guardStmt = createSotaMbaPredicate(seed, 0);
1428
1615
  guardedCount++;
1429
- const guardStmt = createOpaqueGuardStatement(seed, guardedCount);
1616
+ if (hotExemptNodes) {
1617
+ hotExemptNodes.add(guardStmt);
1618
+ hotExemptNodes.add(guardStmt.consequent);
1619
+ }
1430
1620
  let insertIdx = 0;
1431
1621
  while (insertIdx < node.body.body.length && node.body.body[insertIdx].type === "ExpressionStatement" && node.body.body[insertIdx].directive) {
1432
1622
  insertIdx++;
@@ -1458,25 +1648,12 @@ function deriveIntegrityFnName(seed) {
1458
1648
  const hash = computeIntegrityHash(`unpeek:fn:${seed}`, seed);
1459
1649
  return `_u$${hash.toString(36)}`;
1460
1650
  }
1461
- function deriveLocalVar(label, seed) {
1462
- const hash = computeIntegrityHash(`unpeek:var:${label}:${seed}`, seed) & 1048575;
1463
- return `_${label}${hash.toString(36)}`;
1464
- }
1465
1651
  function createDeterrentSnippet(config) {
1466
1652
  const seed = config.seed >>> 0;
1467
- const expectedToken = (config.expectedIntegrityHash ?? seed) >>> 0;
1468
1653
  const deterrentMode = config.deterrentMode ?? "passive";
1469
1654
  const fnName = deriveIntegrityFnName(seed);
1470
- const strVar = deriveLocalVar("s", seed);
1471
- const tamperVar = deriveLocalVar("t", seed);
1472
- const noopVar = deriveLocalVar("n", seed);
1473
- const methodsVar = deriveLocalVar("m", seed);
1474
- const idxVar = deriveLocalVar("i", seed);
1475
- const errVar = deriveLocalVar("e", seed);
1476
- const tokenBit = expectedToken & 1;
1477
- 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}){}}}` : "";
1478
- const tamperDispatch = `if(window.dispatchEvent&&typeof CustomEvent!=='undefined'){try{window.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(${errVar}){}}`;
1479
- 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}){}}})();`;
1655
+ const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=f=>0;" : "";
1656
+ 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);`;
1480
1657
  }
1481
1658
 
1482
1659
  // src/runtime/index.ts
@@ -1541,7 +1718,7 @@ function transformJavaScript(code, options = {}) {
1541
1718
  coldFunctionNodes,
1542
1719
  hotExemptNodes
1543
1720
  } = analyzeAstHotPaths(ast);
1544
- applyColdFlowGuard(ast, coldFunctionNodes, seed);
1721
+ applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
1545
1722
  const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
1546
1723
  const { encryptedStringsCount, integrityToken } = applyStringVault(
1547
1724
  ast,