unpeek 4.1.0 → 4.3.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.
- package/README.md +7 -7
- package/README.tr.md +7 -7
- 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.d.cts +3 -2
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-Q4DFRMAV.cjs → chunk-4IRIMLT3.cjs} +16 -16
- package/dist/{chunk-AD6UFBPA.cjs → chunk-4XSFPX2Z.cjs} +367 -8
- package/dist/{chunk-WYW5UOBE.cjs → chunk-7F75S3GQ.cjs} +60 -36
- package/dist/{chunk-HV47WJIR.js → chunk-EASD7C2B.js} +3 -3
- package/dist/{chunk-STTUFUDC.js → chunk-GKWTP4Z5.js} +30 -6
- package/dist/{chunk-VLL4THTG.cjs → chunk-OR5M3SN2.cjs} +2432 -636
- package/dist/{chunk-32GLSJAW.js → chunk-RDP4MTHK.js} +359 -0
- package/dist/{chunk-6KLUNEKE.js → chunk-RM3V7KJA.js} +2298 -502
- package/dist/{chunk-FLZ4FSP5.cjs → chunk-SBRU7GSX.cjs} +8 -8
- package/dist/{chunk-TOUYQ4N5.js → chunk-XEYMZUP5.js} +2 -2
- package/dist/cli/index.js +2781 -469
- package/dist/index.cjs +169 -29
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +151 -11
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/dist/{types-BZqvBhBI.d.ts → types-BDpFfokR.d.ts} +2 -1
- package/dist/{types-E4ugA4Oz.d.cts → types-WIoud53X.d.cts} +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk7F75S3GQcjs = require('./chunk-7F75S3GQ.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -16,14 +16,16 @@ var _chunkURPPSTHZcjs = require('./chunk-URPPSTHZ.cjs');
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunk4XSFPX2Zcjs = require('./chunk-4XSFPX2Z.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _chunkOR5M3SN2cjs = require('./chunk-OR5M3SN2.cjs');
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
|
|
@@ -98,7 +100,7 @@ export default withUnpeek(nextConfig);
|
|
|
98
100
|
function initProject(cwd = process.cwd(), options = {}) {
|
|
99
101
|
const dryRun = typeof options === "boolean" ? options : _nullishCoalesce(options.dryRun, () => ( false));
|
|
100
102
|
const rootDir = _path2.default.resolve(cwd);
|
|
101
|
-
const { framework } =
|
|
103
|
+
const { framework } = _chunk4XSFPX2Zcjs.detectTargetFramework.call(void 0, rootDir);
|
|
102
104
|
const pkgPath = _path2.default.join(rootDir, "package.json");
|
|
103
105
|
let updatedPackageJson = false;
|
|
104
106
|
let updatedGitignore = false;
|
|
@@ -131,7 +133,7 @@ function initProject(cwd = process.cwd(), options = {}) {
|
|
|
131
133
|
const rawNext = _nullishCoalesce(_optionalChain([deps, 'optionalAccess', _ => _.next]), () => ( _optionalChain([devDeps, 'optionalAccess', _2 => _2.next])));
|
|
132
134
|
nextVersion = typeof rawNext === "string" ? rawNext : void 0;
|
|
133
135
|
}
|
|
134
|
-
if (framework === "nextjs" &&
|
|
136
|
+
if (framework === "nextjs" && _chunk7F75S3GQcjs.isNext16OrAbove.call(void 0, nextVersion)) {
|
|
135
137
|
isNext16 = true;
|
|
136
138
|
const configRes = wireNextConfig(rootDir, dryRun);
|
|
137
139
|
updatedNextConfig = configRes.updated;
|
|
@@ -204,7 +206,7 @@ function initProject(cwd = process.cwd(), options = {}) {
|
|
|
204
206
|
var _acorn = require('acorn'); var acorn = _interopRequireWildcard(_acorn);
|
|
205
207
|
var _acornwalk = require('acorn-walk');
|
|
206
208
|
function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
207
|
-
if (
|
|
209
|
+
if (_chunk4XSFPX2Zcjs.hasNextServerSegment.call(void 0, currentDir, rootOutDir)) {
|
|
208
210
|
return;
|
|
209
211
|
}
|
|
210
212
|
let entries;
|
|
@@ -219,7 +221,7 @@ function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
|
219
221
|
if (entry.name === "node_modules" || entry.name === ".unpeek-maps") {
|
|
220
222
|
continue;
|
|
221
223
|
}
|
|
222
|
-
if (
|
|
224
|
+
if (_chunk4XSFPX2Zcjs.hasNextServerSegment.call(void 0, fullPath, rootOutDir)) {
|
|
223
225
|
continue;
|
|
224
226
|
}
|
|
225
227
|
walkPublicMaps(fullPath, rootOutDir, found);
|
|
@@ -255,7 +257,7 @@ function isNodeModulesSource(sourcePath) {
|
|
|
255
257
|
}
|
|
256
258
|
function mapHasOnlyNodeModulesSources(map) {
|
|
257
259
|
if (!map) return false;
|
|
258
|
-
const flat = Array.isArray(map.sections) ?
|
|
260
|
+
const flat = Array.isArray(map.sections) ? _chunkOR5M3SN2cjs.flattenSourceMapSections.call(void 0, map) : map;
|
|
259
261
|
const sources = Array.isArray(flat.sources) ? flat.sources : [];
|
|
260
262
|
if (sources.length === 0) return false;
|
|
261
263
|
const root = flat.sourceRoot;
|
|
@@ -266,23 +268,25 @@ function mapHasOnlyNodeModulesSources(map) {
|
|
|
266
268
|
}
|
|
267
269
|
function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
268
270
|
if (!map) return false;
|
|
269
|
-
const pos =
|
|
271
|
+
const pos = _chunkOR5M3SN2cjs.resolvePosition.call(void 0, map, hit.line, hit.column);
|
|
270
272
|
if (pos.source) {
|
|
271
273
|
return isNodeModulesSource(pos.source);
|
|
272
274
|
}
|
|
273
275
|
if (hit.calleeLine !== hit.line || hit.calleeColumn !== hit.column) {
|
|
274
|
-
const calleePos =
|
|
276
|
+
const calleePos = _chunkOR5M3SN2cjs.resolvePosition.call(void 0, map, hit.calleeLine, hit.calleeColumn);
|
|
275
277
|
if (calleePos.source) {
|
|
276
278
|
return isNodeModulesSource(calleePos.source);
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
return allSourcesNodeModules;
|
|
280
282
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
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 (e3) {
|
|
292
296
|
try {
|
|
293
|
-
|
|
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 (e4) {
|
|
300
|
-
return
|
|
304
|
+
return null;
|
|
301
305
|
}
|
|
302
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" || _optionalChain([init, 'access', _3 => _3.callee, 'access', _4 => _4.id, 'optionalAccess', _5 => _5.name]) !== "f" || init.callee.params.length !== 1 || init.arguments.length !== 1 || _optionalChain([init, 'access', _6 => _6.arguments, 'access', _7 => _7[0], 'optionalAccess', _8 => _8.type]) !== "ArrayExpression") {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
const first = _optionalChain([init, 'access', _9 => _9.callee, 'access', _10 => _10.body, 'optionalAccess', _11 => _11.body, 'optionalAccess', _12 => _12[0]]);
|
|
316
|
+
return _optionalChain([first, 'optionalAccess', _13 => _13.type]) === "VariableDeclaration" && first.declarations.some(
|
|
317
|
+
(d) => d.id.type === "Identifier" && d.id.name === "h" && _optionalChain([d, 'access', _14 => _14.init, 'optionalAccess', _15 => _15.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 = _chunkOR5M3SN2cjs.classifyPlaintextSecret.call(void 0, value);
|
|
349
|
+
if (match) {
|
|
350
|
+
pushHit(match.category, value, node);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
_acornwalk.recursive.call(void 0, 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 (_chunkOR5M3SN2cjs.hasRegexSecretRun.call(void 0, node.regex.pattern)) {
|
|
404
|
+
pushHit("regex-secret", node.regex.pattern, node);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
TemplateElement(node) {
|
|
409
|
+
const val = _nullishCoalesce(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;
|
|
418
|
+
}
|
|
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
|
_acornwalk.simple.call(void 0, ast, {
|
|
304
429
|
CallExpression(node) {
|
|
305
430
|
if (node.callee.type === "Identifier") {
|
|
@@ -350,9 +475,9 @@ function findEvalOrFunctionCalls(code) {
|
|
|
350
475
|
async function checkProject(options = {}) {
|
|
351
476
|
const cwd = _path2.default.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
352
477
|
const config = await _chunkBQ2O6HM5cjs.loadUnpeekConfig.call(void 0, cwd);
|
|
353
|
-
const { outDir } =
|
|
478
|
+
const { outDir } = _chunk4XSFPX2Zcjs.detectTargetFramework.call(void 0, cwd, options.outDir, config);
|
|
354
479
|
const resolvedOutDir = _path2.default.resolve(outDir);
|
|
355
|
-
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access',
|
|
480
|
+
const privateMapsDir = _nullishCoalesce(_nullishCoalesce(options.privateMapsDir, () => ( _optionalChain([config, 'access', _16 => _16.sourcemaps, 'optionalAccess', _17 => _17.vaultDir]))), () => ( ".unpeek-maps"));
|
|
356
481
|
const maxGzipDelta = _nullishCoalesce(options.maxGzipDelta, () => ( 15));
|
|
357
482
|
const requireZeroEval = Boolean(options.requireZeroEval || options.strictCsp);
|
|
358
483
|
const violations = [];
|
|
@@ -382,18 +507,18 @@ async function checkProject(options = {}) {
|
|
|
382
507
|
} catch (e5) {
|
|
383
508
|
}
|
|
384
509
|
}
|
|
385
|
-
const clientFiles =
|
|
510
|
+
const clientFiles = _chunk4XSFPX2Zcjs.scanClientBundles.call(void 0, resolvedOutDir, config);
|
|
386
511
|
for (const filePath of clientFiles) {
|
|
387
512
|
const rel = _path2.default.relative(resolvedOutDir, filePath).replace(/\\/g, "/");
|
|
388
|
-
const relFromManifest = typeof _optionalChain([manifest, 'optionalAccess',
|
|
513
|
+
const relFromManifest = typeof _optionalChain([manifest, 'optionalAccess', _18 => _18.outDir]) === "string" ? _path2.default.relative(_path2.default.resolve(cwd, manifest.outDir), filePath).replace(/\\/g, "/") : void 0;
|
|
389
514
|
let content;
|
|
390
515
|
try {
|
|
391
516
|
content = _fs2.default.readFileSync(filePath, "utf8");
|
|
392
517
|
} catch (e6) {
|
|
393
518
|
continue;
|
|
394
519
|
}
|
|
395
|
-
|
|
396
|
-
if (
|
|
520
|
+
_chunk4XSFPX2Zcjs.SOURCE_MAP_COMMENT_REGEX.lastIndex = 0;
|
|
521
|
+
if (_chunk4XSFPX2Zcjs.SOURCE_MAP_COMMENT_REGEX.test(content)) {
|
|
397
522
|
violations.push({
|
|
398
523
|
rule: "sourcemap-comment",
|
|
399
524
|
severity: "error",
|
|
@@ -401,9 +526,9 @@ async function checkProject(options = {}) {
|
|
|
401
526
|
file: rel
|
|
402
527
|
});
|
|
403
528
|
}
|
|
404
|
-
const jsDebugId =
|
|
405
|
-
const decodedRel =
|
|
406
|
-
const decodedManifestRel = relFromManifest ?
|
|
529
|
+
const jsDebugId = _chunk4XSFPX2Zcjs.extractDebugId.call(void 0, content);
|
|
530
|
+
const decodedRel = _chunkOR5M3SN2cjs.safeDecodeURIComponent.call(void 0, rel);
|
|
531
|
+
const decodedManifestRel = relFromManifest ? _chunkOR5M3SN2cjs.safeDecodeURIComponent.call(void 0, relFromManifest) : void 0;
|
|
407
532
|
const mapCandidates = [
|
|
408
533
|
_path2.default.join(vaultDir, `${rel}.map`),
|
|
409
534
|
...decodedRel !== rel ? [_path2.default.join(vaultDir, `${decodedRel}.map`)] : [],
|
|
@@ -449,7 +574,8 @@ async function checkProject(options = {}) {
|
|
|
449
574
|
file: rel
|
|
450
575
|
});
|
|
451
576
|
}
|
|
452
|
-
const
|
|
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)));
|
|
@@ -461,7 +587,7 @@ async function checkProject(options = {}) {
|
|
|
461
587
|
});
|
|
462
588
|
} else {
|
|
463
589
|
const allNodeModules = mapHasOnlyNodeModulesSources(vaultedMap);
|
|
464
|
-
const baselineList = _nullishCoalesce(_optionalChain([manifest, 'optionalAccess',
|
|
590
|
+
const baselineList = _nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _19 => _19.preExistingEvalFiles, 'optionalAccess', _20 => _20[rel]]), () => ( (relFromManifest ? _optionalChain([manifest, 'optionalAccess', _21 => _21.preExistingEvalFiles, 'optionalAccess', _22 => _22[relFromManifest]]) : void 0)));
|
|
465
591
|
const remainingBaseline = /* @__PURE__ */ new Map();
|
|
466
592
|
if (Array.isArray(baselineList)) {
|
|
467
593
|
for (const entry of baselineList) {
|
|
@@ -511,10 +637,24 @@ 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.default.relative(cwd, vaultDir).replace(/\\/g, "/");
|
|
516
656
|
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
517
|
-
const roots =
|
|
657
|
+
const roots = _chunk4XSFPX2Zcjs.findMonorepoRoots.call(void 0, cwd);
|
|
518
658
|
let foundGitignore = false;
|
|
519
659
|
let gitignoreProtected = false;
|
|
520
660
|
let foundDockerignore = false;
|
|
@@ -590,4 +730,4 @@ async function checkProject(options = {}) {
|
|
|
590
730
|
|
|
591
731
|
|
|
592
732
|
|
|
593
|
-
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkBQ2O6HM5cjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkBQ2O6HM5cjs.loadUnpeekConfig; exports.protectProject =
|
|
733
|
+
exports.PRESETS = _chunkURPPSTHZcjs.PRESETS; exports.UnpeekError = _chunkL6BOM5VScjs.UnpeekError; exports.checkProject = checkProject; exports.defineConfig = _chunkBQ2O6HM5cjs.defineConfig; exports.initProject = initProject; exports.isUnpeekError = _chunkL6BOM5VScjs.isUnpeekError; exports.loadUnpeekConfig = _chunkBQ2O6HM5cjs.loadUnpeekConfig; exports.protectProject = _chunk7F75S3GQcjs.protectProject; exports.symbolicateStackTrace = _chunkOR5M3SN2cjs.symbolicateStackTrace; exports.transformJavaScript = _chunkOR5M3SN2cjs.transformJavaScript;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-BFAZrfjQ.cjs';
|
|
2
2
|
export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-Bo4S_VVM.cjs';
|
|
3
|
-
import { S as SymbolicateOptions, b as SymbolicateResult, I as InitOptions, c as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, d as CheckResult } from './types-
|
|
4
|
-
export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-
|
|
3
|
+
import { S as SymbolicateOptions, b as SymbolicateResult, I as InitOptions, c as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, d as CheckResult } from './types-WIoud53X.cjs';
|
|
4
|
+
export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-WIoud53X.cjs';
|
|
5
5
|
|
|
6
6
|
declare function symbolicateStackTrace(options: SymbolicateOptions): Promise<SymbolicateResult>;
|
|
7
7
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { B as BaseProtectionOptions, C as ConfigTarget, D as DeterrentMode, F as FilterConfig, H as HotPathConfig, M as ManglerConfig, N as NextConfigOptions, P as PRESETS, b as PatternInput, c as SemanticAnchorsConfig, S as ShieldConfig, d as ShieldOptionsConfig, a as ShieldPayload, e as SourcemapsConfig, U as UnpeekConfig, f as UnpeekFramework, g as UnpeekPluginOptions, h as UnpeekProfile, V as VaultConfig, i as ViteConfigOptions, j as defineConfig, l as loadUnpeekConfig } from './config-BFAZrfjQ.js';
|
|
2
2
|
export { H as HotPathReport, S as ScrubberOptions, T as TransformOptions, a as TransformResult, b as TransformSkippedReason, U as UnpeekError, c as UnpeekErrorCode, i as isUnpeekError, t as transformJavaScript } from './index-CKdYVt_L.js';
|
|
3
|
-
import { S as SymbolicateOptions, b as SymbolicateResult, I as InitOptions, c as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, d as CheckResult } from './types-
|
|
4
|
-
export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-
|
|
3
|
+
import { S as SymbolicateOptions, b as SymbolicateResult, I as InitOptions, c as InitResult, a as ProtectOptions, P as ProtectSummary, C as CheckOptions, d as CheckResult } from './types-BDpFfokR.js';
|
|
4
|
+
export { e as CheckViolation, f as SourceMapVaultResult, g as SymbolicateFrame, U as UnpeekDiagnostic, h as UnpeekDiagnosticSeverity } from './types-BDpFfokR.js';
|
|
5
5
|
|
|
6
6
|
declare function symbolicateStackTrace(options: SymbolicateOptions): Promise<SymbolicateResult>;
|
|
7
7
|
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isNext16OrAbove,
|
|
3
3
|
protectProject
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GKWTP4Z5.js";
|
|
5
5
|
import {
|
|
6
6
|
defineConfig,
|
|
7
7
|
loadUnpeekConfig
|
|
@@ -16,14 +16,16 @@ import {
|
|
|
16
16
|
findMonorepoRoots,
|
|
17
17
|
hasNextServerSegment,
|
|
18
18
|
scanClientBundles
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-RDP4MTHK.js";
|
|
20
20
|
import {
|
|
21
|
+
classifyPlaintextSecret,
|
|
21
22
|
flattenSourceMapSections,
|
|
23
|
+
hasRegexSecretRun,
|
|
22
24
|
resolvePosition,
|
|
23
25
|
safeDecodeURIComponent,
|
|
24
26
|
symbolicateStackTrace,
|
|
25
27
|
transformJavaScript
|
|
26
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-RM3V7KJA.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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
304
|
+
return null;
|
|
301
305
|
}
|
|
302
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;
|
|
418
|
+
}
|
|
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
|
|
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
|
|
10
|
-
require('../chunk-
|
|
11
|
-
require('../chunk-
|
|
9
|
+
var _chunk4IRIMLT3cjs = require('../chunk-4IRIMLT3.cjs');
|
|
10
|
+
require('../chunk-4XSFPX2Z.cjs');
|
|
11
|
+
require('../chunk-OR5M3SN2.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 =
|
|
21
|
+
exports.default = _chunk4IRIMLT3cjs.unplugin_default; exports.esbuildPlugin = _chunk4IRIMLT3cjs.esbuildPlugin; exports.rollupPlugin = _chunk4IRIMLT3cjs.rollupPlugin; exports.rspackPlugin = _chunk4IRIMLT3cjs.rspackPlugin; exports.unpeekPlugin = _chunk4IRIMLT3cjs.unpeekPlugin; exports.vitePlugin = _chunk4IRIMLT3cjs.vitePlugin; exports.webpackPlugin = _chunk4IRIMLT3cjs.webpackPlugin;
|
package/dist/plugins/unplugin.js
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
unplugin_default,
|
|
7
7
|
vitePlugin,
|
|
8
8
|
webpackPlugin
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-XEYMZUP5.js";
|
|
10
|
+
import "../chunk-RDP4MTHK.js";
|
|
11
|
+
import "../chunk-RM3V7KJA.js";
|
|
12
12
|
import "../chunk-LA6J3BT3.js";
|
|
13
13
|
export {
|
|
14
14
|
unplugin_default as default,
|
|
@@ -75,9 +75,10 @@ interface CheckOptions {
|
|
|
75
75
|
maxGzipDelta?: number;
|
|
76
76
|
requireZeroEval?: boolean;
|
|
77
77
|
strictCsp?: boolean;
|
|
78
|
+
failOnPlaintextSecrets?: boolean;
|
|
78
79
|
}
|
|
79
80
|
interface CheckViolation {
|
|
80
|
-
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';
|
|
81
82
|
severity: 'error' | 'warning';
|
|
82
83
|
message: string;
|
|
83
84
|
file?: string;
|
|
@@ -75,9 +75,10 @@ interface CheckOptions {
|
|
|
75
75
|
maxGzipDelta?: number;
|
|
76
76
|
requireZeroEval?: boolean;
|
|
77
77
|
strictCsp?: boolean;
|
|
78
|
+
failOnPlaintextSecrets?: boolean;
|
|
78
79
|
}
|
|
79
80
|
interface CheckViolation {
|
|
80
|
-
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';
|
|
81
82
|
severity: 'error' | 'warning';
|
|
82
83
|
message: string;
|
|
83
84
|
file?: string;
|