@profullstack/threatcrush 0.13.28 → 0.13.30
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/dist/daemon.js +27 -4
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -12612,7 +12612,9 @@ var CODE_RULES = [
|
|
|
12612
12612
|
cwe: "CWE-532",
|
|
12613
12613
|
severity: "critical",
|
|
12614
12614
|
languages: ["javascript", "typescript"],
|
|
12615
|
-
|
|
12615
|
+
// One variable (`process.env.X`, `process.env?.X`, `process.env['X']`) is not
|
|
12616
|
+
// the environment.
|
|
12617
|
+
pattern: /\bJSON\.stringify\s*\(\s*\{?[^)]*\bprocess\.env\b(?!\s*(?:\.|\?\.|\[))/,
|
|
12616
12618
|
guard: false
|
|
12617
12619
|
},
|
|
12618
12620
|
{
|
|
@@ -12659,8 +12661,11 @@ var CODE_RULES = [
|
|
|
12659
12661
|
// escalates when nearby evidence shows that input can choose the download.
|
|
12660
12662
|
guard: false,
|
|
12661
12663
|
// Installer instructions printed by the script do not execute. Matching
|
|
12662
|
-
// them made a script report its own documentation as a network pipeline
|
|
12663
|
-
|
|
12664
|
+
// them made a script report its own documentation as a network pipeline,
|
|
12665
|
+
// including the usual `-h | --help) echo "Usage: curl … | sh"; exit ;;` case
|
|
12666
|
+
// branch, which a start-of-line guard missed. Only the quoted text is
|
|
12667
|
+
// discounted, so `echo "see docs"; curl … | sh` still reports.
|
|
12668
|
+
displayStringGuard: true,
|
|
12664
12669
|
// The same instructions written as a `cat <<USAGE` help block.
|
|
12665
12670
|
displayedHeredocGuard: true
|
|
12666
12671
|
},
|
|
@@ -13370,6 +13375,23 @@ function insideDisplayedHeredoc(lines, index) {
|
|
|
13370
13375
|
const opener = open.opener.replace(/\s[12]?>&2\b/g, " ");
|
|
13371
13376
|
return /^\s*cat\b/.test(opener) && !/>/.test(opener) && !/\|/.test(opener);
|
|
13372
13377
|
}
|
|
13378
|
+
var DISPLAY_STRING = /(\b(?:echo|printf|say|info|warn|error)\s+(?:-[A-Za-z]+\s+)*)((?:"(?:[^"\\\n]|\\.)*"|'[^'\n]*')(?:\s+(?:"(?:[^"\\\n]|\\.)*"|'[^'\n]*'))*)(?=\s*(?:$|;|&&|\|\||[12]?>&2|>\s*\/dev\/(?:stderr|tty)\b|\)|#))/g;
|
|
13379
|
+
function stripDisplayedStrings(line) {
|
|
13380
|
+
return line.replace(
|
|
13381
|
+
DISPLAY_STRING,
|
|
13382
|
+
(whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
|
|
13383
|
+
);
|
|
13384
|
+
}
|
|
13385
|
+
var MINIFIED_LINE = 1e3;
|
|
13386
|
+
var MINIFIED_REACH = 200;
|
|
13387
|
+
function minifiedWindow(line, pattern) {
|
|
13388
|
+
const match = new RegExp(pattern.source, pattern.flags.replace("g", "")).exec(line);
|
|
13389
|
+
if (!match) return line;
|
|
13390
|
+
return line.slice(
|
|
13391
|
+
Math.max(0, match.index - MINIFIED_REACH),
|
|
13392
|
+
match.index + match[0].length + MINIFIED_REACH
|
|
13393
|
+
);
|
|
13394
|
+
}
|
|
13373
13395
|
function evaluateRule(rule, ctx) {
|
|
13374
13396
|
if (rule.languages && !rule.languages.includes(ctx.language)) return null;
|
|
13375
13397
|
const line = ctx.lines[ctx.index] ?? "";
|
|
@@ -13378,10 +13400,11 @@ function evaluateRule(rule, ctx) {
|
|
|
13378
13400
|
if (rule.fileRequires && !rule.fileRequires.test(fileTextOf(ctx.lines))) return null;
|
|
13379
13401
|
const back = rule.guardBack ?? 8;
|
|
13380
13402
|
const forward = rule.guardForward ?? 0;
|
|
13381
|
-
const context = windowText(ctx.lines, ctx.index, back, forward, ctx.prose);
|
|
13403
|
+
const context = line.length > MINIFIED_LINE ? minifiedWindow(line, rule.pattern) : windowText(ctx.lines, ctx.index, back, forward, ctx.prose);
|
|
13382
13404
|
if (rule.requires && !rule.requires.test(context)) return null;
|
|
13383
13405
|
if (rule.lineGuard?.test(line)) return null;
|
|
13384
13406
|
if (rule.displayedHeredocGuard && insideDisplayedHeredoc(ctx.lines, ctx.index)) return null;
|
|
13407
|
+
if (rule.displayStringGuard && !rule.pattern.test(stripDisplayedStrings(line))) return null;
|
|
13385
13408
|
if (rule.enclosingCallGuard) {
|
|
13386
13409
|
const callees = enclosingCallees(ctx.lines, ctx.index, back);
|
|
13387
13410
|
if (callees.some((callee) => rule.enclosingCallGuard.test(callee))) return null;
|