unpeek 4.0.1 → 4.2.0

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 (62) hide show
  1. package/README.md +21 -13
  2. package/README.tr.md +21 -13
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.d.cts +1 -1
  5. package/dist/adapters/esbuild.d.ts +1 -1
  6. package/dist/adapters/esbuild.js +3 -3
  7. package/dist/adapters/next/adapter.cjs +6 -6
  8. package/dist/adapters/next/adapter.d.cts +1 -1
  9. package/dist/adapters/next/adapter.d.ts +1 -1
  10. package/dist/adapters/next/adapter.js +5 -5
  11. package/dist/adapters/next/index.cjs +6 -6
  12. package/dist/adapters/next/index.js +5 -5
  13. package/dist/adapters/rollup.cjs +5 -5
  14. package/dist/adapters/rollup.d.cts +1 -1
  15. package/dist/adapters/rollup.d.ts +1 -1
  16. package/dist/adapters/rollup.js +3 -3
  17. package/dist/adapters/rspack.cjs +5 -5
  18. package/dist/adapters/rspack.d.cts +1 -1
  19. package/dist/adapters/rspack.d.ts +1 -1
  20. package/dist/adapters/rspack.js +3 -3
  21. package/dist/adapters/vite.cjs +5 -5
  22. package/dist/adapters/vite.d.cts +1 -1
  23. package/dist/adapters/vite.d.ts +1 -1
  24. package/dist/adapters/vite.js +3 -3
  25. package/dist/adapters/webpack.cjs +5 -5
  26. package/dist/adapters/webpack.d.cts +1 -1
  27. package/dist/adapters/webpack.d.ts +1 -1
  28. package/dist/adapters/webpack.js +3 -3
  29. package/dist/browser.cjs +2 -2
  30. package/dist/browser.d.cts +7 -6
  31. package/dist/browser.d.ts +7 -6
  32. package/dist/browser.js +1 -1
  33. package/dist/{chunk-TYL32LUK.js → chunk-32GLSJAW.js} +91 -569
  34. package/dist/{chunk-W77DAC3H.js → chunk-6EWFL4LQ.js} +16 -0
  35. package/dist/{chunk-3GDHYBVH.cjs → chunk-AD6UFBPA.cjs} +96 -574
  36. package/dist/{chunk-XYN5NYSD.js → chunk-APQOBFRO.js} +21 -15
  37. package/dist/{chunk-LGTXAAZH.js → chunk-BL2UXZGD.js} +3155 -481
  38. package/dist/{chunk-X6EETCO6.cjs → chunk-BQ2O6HM5.cjs} +16 -0
  39. package/dist/{chunk-4G2HCME5.js → chunk-GCWXTWTN.js} +30 -13
  40. package/dist/{chunk-4SOS3LRV.js → chunk-K77WRITN.js} +6 -6
  41. package/dist/{chunk-7ZEVJ4OR.cjs → chunk-KIAYVIC5.cjs} +40 -34
  42. package/dist/{chunk-M46SFJE7.cjs → chunk-MSECP2P4.cjs} +3351 -677
  43. package/dist/{chunk-NNAAPDUS.cjs → chunk-SJK45WAU.cjs} +8 -8
  44. package/dist/{chunk-OTA75YI6.cjs → chunk-UUJLTW7O.cjs} +53 -36
  45. package/dist/cli/index.js +2808 -528
  46. package/dist/{config-Y6JwVGwX.d.cts → config-BFAZrfjQ.d.cts} +2 -0
  47. package/dist/{config-Y6JwVGwX.d.ts → config-BFAZrfjQ.d.ts} +2 -0
  48. package/dist/config.cjs +2 -2
  49. package/dist/config.d.cts +1 -1
  50. package/dist/config.d.ts +1 -1
  51. package/dist/config.js +1 -1
  52. package/dist/{index-COVHErnx.d.cts → index-Bo4S_VVM.d.cts} +1 -1
  53. package/dist/{index-0O1WSfVP.d.ts → index-CKdYVt_L.d.ts} +1 -1
  54. package/dist/index.cjs +171 -31
  55. package/dist/index.d.cts +6 -6
  56. package/dist/index.d.ts +6 -6
  57. package/dist/index.js +156 -16
  58. package/dist/plugins/unplugin.cjs +4 -4
  59. package/dist/plugins/unplugin.js +3 -3
  60. package/dist/{types-CMtZnV8C.d.ts → types-BDpFfokR.d.ts} +6 -3
  61. package/dist/{types-D93PuOOl.d.cts → types-WIoud53X.d.cts} +6 -3
  62. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  isNext16OrAbove,
3
3
  protectProject
4
- } from "./chunk-XYN5NYSD.js";
4
+ } from "./chunk-APQOBFRO.js";
5
5
  import {
6
6
  defineConfig,
7
7
  loadUnpeekConfig
8
- } from "./chunk-W77DAC3H.js";
8
+ } from "./chunk-6EWFL4LQ.js";
9
9
  import {
10
10
  PRESETS
11
11
  } from "./chunk-EN6QVR6P.js";
@@ -14,16 +14,18 @@ import {
14
14
  detectTargetFramework,
15
15
  extractDebugId,
16
16
  findMonorepoRoots,
17
- flattenSourceMapSections,
18
17
  hasNextServerSegment,
18
+ scanClientBundles
19
+ } from "./chunk-32GLSJAW.js";
20
+ import {
21
+ classifyPlaintextSecret,
22
+ flattenSourceMapSections,
23
+ hasRegexSecretRun,
19
24
  resolvePosition,
20
25
  safeDecodeURIComponent,
21
- scanClientBundles,
22
- symbolicateStackTrace
23
- } from "./chunk-TYL32LUK.js";
24
- import {
26
+ symbolicateStackTrace,
25
27
  transformJavaScript
26
- } from "./chunk-LGTXAAZH.js";
28
+ } from "./chunk-BL2UXZGD.js";
27
29
  import {
28
30
  UnpeekError,
29
31
  isUnpeekError
@@ -202,7 +204,7 @@ function initProject(cwd = process.cwd(), options = {}) {
202
204
  import fs2 from "fs";
203
205
  import path2 from "path";
204
206
  import * as acorn from "acorn";
205
- import { simple as walkSimple } from "acorn-walk";
207
+ import { recursive as walkRecursive, simple as walkSimple } from "acorn-walk";
206
208
  function walkPublicMaps(currentDir, rootOutDir, found) {
207
209
  if (hasNextServerSegment(currentDir, rootOutDir)) {
208
210
  return;
@@ -278,11 +280,13 @@ function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
278
280
  }
279
281
  return allSourcesNodeModules;
280
282
  }
281
- function findEvalOrFunctionCalls(code) {
282
- const hits = [];
283
- let ast;
283
+ var MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE = 5;
284
+ var UNPEEK_VAULT_IDENT_PREFIXES = ["_uP", "_uC", "_uD", "_uS", "_uSb", "_uDec"];
285
+ var BINARY_DATA_URI_RE = /^data:(?:application\/(?:wasm|octet-stream|pdf|zip|gzip|(?:x-)?font-[a-z0-9-]+)|image\/|font\/|audio\/|video\/)/i;
286
+ var SECRET_LIMIT_REACHED = {};
287
+ function parseCheckAst(code) {
284
288
  try {
285
- ast = acorn.parse(code, {
289
+ return acorn.parse(code, {
286
290
  ecmaVersion: "latest",
287
291
  sourceType: "module",
288
292
  allowReturnOutsideFunction: true,
@@ -290,16 +294,137 @@ function findEvalOrFunctionCalls(code) {
290
294
  });
291
295
  } catch {
292
296
  try {
293
- ast = acorn.parse(code, {
297
+ return acorn.parse(code, {
294
298
  ecmaVersion: "latest",
295
299
  sourceType: "script",
296
300
  allowReturnOutsideFunction: true,
297
301
  locations: true
298
302
  });
299
303
  } catch {
300
- return hits;
304
+ return null;
305
+ }
306
+ }
307
+ }
308
+ function isUnpeekVaultIdentifier(name) {
309
+ return UNPEEK_VAULT_IDENT_PREFIXES.some((prefix) => name.startsWith(prefix));
310
+ }
311
+ function isUnpeekShaderVaultIife(init) {
312
+ if (!init || init.type !== "CallExpression" || init.callee.type !== "FunctionExpression" || init.callee.id?.name !== "f" || init.callee.params.length !== 1 || init.arguments.length !== 1 || init.arguments[0]?.type !== "ArrayExpression") {
313
+ return false;
314
+ }
315
+ const first = init.callee.body?.body?.[0];
316
+ return first?.type === "VariableDeclaration" && first.declarations.some(
317
+ (d) => d.id.type === "Identifier" && d.id.name === "h" && d.init?.type === "Literal" && d.init.value === 2166136261
318
+ );
319
+ }
320
+ function isSkippedBinaryPayload(value) {
321
+ return value.startsWith("AGFzbQE") || BINARY_DATA_URI_RE.test(value);
322
+ }
323
+ function redactSecretPreview(value) {
324
+ const singleLine = value.replace(/[\r\n\t]+/g, " ");
325
+ if (singleLine.length <= 10) {
326
+ return "[redacted]";
327
+ }
328
+ return `${singleLine.slice(0, 4)}...${singleLine.slice(-4)}`;
329
+ }
330
+ function findPlaintextSecrets(code, parsedAst) {
331
+ const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
332
+ if (!ast) {
333
+ return [];
334
+ }
335
+ const hits = [];
336
+ const pushHit = (category, rawValue, node) => {
337
+ hits.push({
338
+ category,
339
+ preview: redactSecretPreview(rawValue),
340
+ line: node.loc ? node.loc.start.line : 1
341
+ });
342
+ if (hits.length >= MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE) {
343
+ throw SECRET_LIMIT_REACHED;
344
+ }
345
+ };
346
+ const inspectString = (value, node) => {
347
+ if (!value || isSkippedBinaryPayload(value)) return;
348
+ const match = classifyPlaintextSecret(value);
349
+ if (match) {
350
+ pushHit(match.category, value, node);
351
+ }
352
+ };
353
+ try {
354
+ walkRecursive(ast, void 0, {
355
+ VariableDeclarator(node, state, c) {
356
+ if (node.id.type === "Identifier" && isUnpeekVaultIdentifier(node.id.name) || isUnpeekShaderVaultIife(node.init)) {
357
+ return;
358
+ }
359
+ c(node.id, state);
360
+ if (node.init) {
361
+ c(node.init, state);
362
+ }
363
+ },
364
+ FunctionDeclaration(node, state, c) {
365
+ if (node.id && isUnpeekVaultIdentifier(node.id.name)) {
366
+ return;
367
+ }
368
+ for (const param of node.params) {
369
+ c(param, state);
370
+ }
371
+ c(node.body, state);
372
+ },
373
+ ExpressionStatement(node, state, c) {
374
+ if (node.directive) {
375
+ return;
376
+ }
377
+ c(node.expression, state);
378
+ },
379
+ ImportDeclaration() {
380
+ },
381
+ ExportNamedDeclaration(node, state, c) {
382
+ if (node.declaration) {
383
+ c(node.declaration, state);
384
+ }
385
+ },
386
+ ExportAllDeclaration() {
387
+ },
388
+ ImportExpression(node, state, c) {
389
+ if (node.options) {
390
+ c(node.options, state);
391
+ }
392
+ },
393
+ ImportSpecifier() {
394
+ },
395
+ ExportSpecifier() {
396
+ },
397
+ ImportAttribute() {
398
+ },
399
+ Literal(node) {
400
+ if (typeof node.value === "string") {
401
+ inspectString(node.value, node);
402
+ } else if (node.regex && typeof node.regex.pattern === "string") {
403
+ if (hasRegexSecretRun(node.regex.pattern)) {
404
+ pushHit("regex-secret", node.regex.pattern, node);
405
+ }
406
+ }
407
+ },
408
+ TemplateElement(node) {
409
+ const val = node.value.cooked ?? node.value.raw;
410
+ if (typeof val === "string") {
411
+ inspectString(val, node);
412
+ }
413
+ }
414
+ });
415
+ } catch (err) {
416
+ if (err !== SECRET_LIMIT_REACHED) {
417
+ throw err;
301
418
  }
302
419
  }
420
+ return hits;
421
+ }
422
+ function findEvalOrFunctionCalls(code, parsedAst) {
423
+ const hits = [];
424
+ const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
425
+ if (!ast) {
426
+ return hits;
427
+ }
303
428
  walkSimple(ast, {
304
429
  CallExpression(node) {
305
430
  if (node.callee.type === "Identifier") {
@@ -449,7 +574,8 @@ async function checkProject(options = {}) {
449
574
  file: rel
450
575
  });
451
576
  }
452
- const evalHits = findEvalOrFunctionCalls(content);
577
+ const ast = parseCheckAst(content);
578
+ const evalHits = findEvalOrFunctionCalls(content, ast);
453
579
  if (evalHits.length > 0) {
454
580
  if (!requireZeroEval) {
455
581
  const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
@@ -511,6 +637,20 @@ async function checkProject(options = {}) {
511
637
  }
512
638
  }
513
639
  }
640
+ const secretHits = findPlaintextSecrets(content, ast);
641
+ if (secretHits.length > 0) {
642
+ const failOnSecrets = options.failOnPlaintextSecrets === true;
643
+ const targetBucket = failOnSecrets ? violations : warnings;
644
+ const severity = failOnSecrets ? "error" : "warning";
645
+ for (const hit of secretHits) {
646
+ targetBucket.push({
647
+ rule: "plaintext-secret",
648
+ severity,
649
+ message: `Plaintext secret (${hit.category}) "${hit.preview}" detected in "${rel}" at line ${hit.line}.`,
650
+ file: rel
651
+ });
652
+ }
653
+ }
514
654
  }
515
655
  const relVault = path2.relative(cwd, vaultDir).replace(/\\/g, "/");
516
656
  const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
@@ -6,9 +6,9 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkOTA75YI6cjs = require('../chunk-OTA75YI6.cjs');
10
- require('../chunk-3GDHYBVH.cjs');
11
- require('../chunk-M46SFJE7.cjs');
9
+ var _chunkUUJLTW7Ocjs = require('../chunk-UUJLTW7O.cjs');
10
+ require('../chunk-AD6UFBPA.cjs');
11
+ require('../chunk-MSECP2P4.cjs');
12
12
  require('../chunk-L6BOM5VS.cjs');
13
13
 
14
14
 
@@ -18,4 +18,4 @@ require('../chunk-L6BOM5VS.cjs');
18
18
 
19
19
 
20
20
 
21
- exports.default = _chunkOTA75YI6cjs.unplugin_default; exports.esbuildPlugin = _chunkOTA75YI6cjs.esbuildPlugin; exports.rollupPlugin = _chunkOTA75YI6cjs.rollupPlugin; exports.rspackPlugin = _chunkOTA75YI6cjs.rspackPlugin; exports.unpeekPlugin = _chunkOTA75YI6cjs.unpeekPlugin; exports.vitePlugin = _chunkOTA75YI6cjs.vitePlugin; exports.webpackPlugin = _chunkOTA75YI6cjs.webpackPlugin;
21
+ exports.default = _chunkUUJLTW7Ocjs.unplugin_default; exports.esbuildPlugin = _chunkUUJLTW7Ocjs.esbuildPlugin; exports.rollupPlugin = _chunkUUJLTW7Ocjs.rollupPlugin; exports.rspackPlugin = _chunkUUJLTW7Ocjs.rspackPlugin; exports.unpeekPlugin = _chunkUUJLTW7Ocjs.unpeekPlugin; exports.vitePlugin = _chunkUUJLTW7Ocjs.vitePlugin; exports.webpackPlugin = _chunkUUJLTW7Ocjs.webpackPlugin;
@@ -6,9 +6,9 @@ import {
6
6
  unplugin_default,
7
7
  vitePlugin,
8
8
  webpackPlugin
9
- } from "../chunk-4G2HCME5.js";
10
- import "../chunk-TYL32LUK.js";
11
- import "../chunk-LGTXAAZH.js";
9
+ } from "../chunk-GCWXTWTN.js";
10
+ import "../chunk-32GLSJAW.js";
11
+ import "../chunk-BL2UXZGD.js";
12
12
  import "../chunk-LA6J3BT3.js";
13
13
  export {
14
14
  unplugin_default as default,
@@ -1,4 +1,4 @@
1
- import { f as UnpeekFramework, h as UnpeekProfile, B as BaseProtectionOptions } from './config-Y6JwVGwX.js';
1
+ import { f as UnpeekFramework, D as DeterrentMode, h as UnpeekProfile, B as BaseProtectionOptions } from './config-BFAZrfjQ.js';
2
2
 
3
3
  interface ProtectOptions extends BaseProtectionOptions {
4
4
  /** Target project root directory (defaults to process.cwd()) */
@@ -48,6 +48,8 @@ interface ProtectSummary {
48
48
  seed?: number;
49
49
  tier?: 'Tier 1' | 'Tier 2' | 'Tier 3';
50
50
  aggressive?: boolean;
51
+ deterrentMode?: DeterrentMode;
52
+ detectHeadless?: boolean;
51
53
  dockerIgnoreMissing?: boolean;
52
54
  dryRun?: boolean;
53
55
  profile?: UnpeekProfile;
@@ -73,9 +75,10 @@ interface CheckOptions {
73
75
  maxGzipDelta?: number;
74
76
  requireZeroEval?: boolean;
75
77
  strictCsp?: boolean;
78
+ failOnPlaintextSecrets?: boolean;
76
79
  }
77
80
  interface CheckViolation {
78
- rule: 'public-map' | 'sourcemap-comment' | 'ignore-missing' | 'gzip-budget' | 'eval-csp' | 'debugid-mismatch';
81
+ rule: 'public-map' | 'sourcemap-comment' | 'ignore-missing' | 'gzip-budget' | 'eval-csp' | 'debugid-mismatch' | 'plaintext-secret';
79
82
  severity: 'error' | 'warning';
80
83
  message: string;
81
84
  file?: string;
@@ -109,4 +112,4 @@ interface SymbolicateResult {
109
112
  warnings: string[];
110
113
  }
111
114
 
112
- export type { CheckOptions as C, InitOptions as I, ProtectSummary as P, SymbolicateOptions as S, UnpeekDiagnostic as U, ProtectOptions as a, InitResult as b, CheckResult as c, SymbolicateResult as d, CheckViolation as e, SourceMapVaultResult as f, SymbolicateFrame as g, UnpeekDiagnosticSeverity as h };
115
+ export type { CheckOptions as C, InitOptions as I, ProtectSummary as P, SymbolicateOptions as S, UnpeekDiagnostic as U, ProtectOptions as a, SymbolicateResult as b, InitResult as c, CheckResult as d, CheckViolation as e, SourceMapVaultResult as f, SymbolicateFrame as g, UnpeekDiagnosticSeverity as h };
@@ -1,4 +1,4 @@
1
- import { f as UnpeekFramework, h as UnpeekProfile, B as BaseProtectionOptions } from './config-Y6JwVGwX.cjs';
1
+ import { f as UnpeekFramework, D as DeterrentMode, h as UnpeekProfile, B as BaseProtectionOptions } from './config-BFAZrfjQ.cjs';
2
2
 
3
3
  interface ProtectOptions extends BaseProtectionOptions {
4
4
  /** Target project root directory (defaults to process.cwd()) */
@@ -48,6 +48,8 @@ interface ProtectSummary {
48
48
  seed?: number;
49
49
  tier?: 'Tier 1' | 'Tier 2' | 'Tier 3';
50
50
  aggressive?: boolean;
51
+ deterrentMode?: DeterrentMode;
52
+ detectHeadless?: boolean;
51
53
  dockerIgnoreMissing?: boolean;
52
54
  dryRun?: boolean;
53
55
  profile?: UnpeekProfile;
@@ -73,9 +75,10 @@ interface CheckOptions {
73
75
  maxGzipDelta?: number;
74
76
  requireZeroEval?: boolean;
75
77
  strictCsp?: boolean;
78
+ failOnPlaintextSecrets?: boolean;
76
79
  }
77
80
  interface CheckViolation {
78
- rule: 'public-map' | 'sourcemap-comment' | 'ignore-missing' | 'gzip-budget' | 'eval-csp' | 'debugid-mismatch';
81
+ rule: 'public-map' | 'sourcemap-comment' | 'ignore-missing' | 'gzip-budget' | 'eval-csp' | 'debugid-mismatch' | 'plaintext-secret';
79
82
  severity: 'error' | 'warning';
80
83
  message: string;
81
84
  file?: string;
@@ -109,4 +112,4 @@ interface SymbolicateResult {
109
112
  warnings: string[];
110
113
  }
111
114
 
112
- export type { CheckOptions as C, InitOptions as I, ProtectSummary as P, SymbolicateOptions as S, UnpeekDiagnostic as U, ProtectOptions as a, InitResult as b, CheckResult as c, SymbolicateResult as d, CheckViolation as e, SourceMapVaultResult as f, SymbolicateFrame as g, UnpeekDiagnosticSeverity as h };
115
+ export type { CheckOptions as C, InitOptions as I, ProtectSummary as P, SymbolicateOptions as S, UnpeekDiagnostic as U, ProtectOptions as a, SymbolicateResult as b, InitResult as c, CheckResult as d, CheckViolation as e, SourceMapVaultResult as f, SymbolicateFrame as g, UnpeekDiagnosticSeverity as h };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unpeek",
3
- "version": "4.0.1",
3
+ "version": "4.2.0",
4
4
  "description": "Zero-config, call-graph-aware polymorphic AST obfuscation and passive runtime anti-tamper with <2% CPU overhead.",
5
5
  "type": "module",
6
6
  "license": "MIT",