@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/index.js
CHANGED
|
@@ -26142,7 +26142,9 @@ var CODE_RULES = [
|
|
|
26142
26142
|
cwe: "CWE-532",
|
|
26143
26143
|
severity: "critical",
|
|
26144
26144
|
languages: ["javascript", "typescript"],
|
|
26145
|
-
|
|
26145
|
+
// One variable (`process.env.X`, `process.env?.X`, `process.env['X']`) is not
|
|
26146
|
+
// the environment.
|
|
26147
|
+
pattern: /\bJSON\.stringify\s*\(\s*\{?[^)]*\bprocess\.env\b(?!\s*(?:\.|\?\.|\[))/,
|
|
26146
26148
|
guard: false
|
|
26147
26149
|
},
|
|
26148
26150
|
{
|
|
@@ -26189,8 +26191,11 @@ var CODE_RULES = [
|
|
|
26189
26191
|
// escalates when nearby evidence shows that input can choose the download.
|
|
26190
26192
|
guard: false,
|
|
26191
26193
|
// Installer instructions printed by the script do not execute. Matching
|
|
26192
|
-
// them made a script report its own documentation as a network pipeline
|
|
26193
|
-
|
|
26194
|
+
// them made a script report its own documentation as a network pipeline,
|
|
26195
|
+
// including the usual `-h | --help) echo "Usage: curl … | sh"; exit ;;` case
|
|
26196
|
+
// branch, which a start-of-line guard missed. Only the quoted text is
|
|
26197
|
+
// discounted, so `echo "see docs"; curl … | sh` still reports.
|
|
26198
|
+
displayStringGuard: true,
|
|
26194
26199
|
// The same instructions written as a `cat <<USAGE` help block.
|
|
26195
26200
|
displayedHeredocGuard: true
|
|
26196
26201
|
},
|
|
@@ -26900,6 +26905,23 @@ function insideDisplayedHeredoc(lines, index) {
|
|
|
26900
26905
|
const opener = open.opener.replace(/\s[12]?>&2\b/g, " ");
|
|
26901
26906
|
return /^\s*cat\b/.test(opener) && !/>/.test(opener) && !/\|/.test(opener);
|
|
26902
26907
|
}
|
|
26908
|
+
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;
|
|
26909
|
+
function stripDisplayedStrings(line) {
|
|
26910
|
+
return line.replace(
|
|
26911
|
+
DISPLAY_STRING,
|
|
26912
|
+
(whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
|
|
26913
|
+
);
|
|
26914
|
+
}
|
|
26915
|
+
var MINIFIED_LINE = 1e3;
|
|
26916
|
+
var MINIFIED_REACH = 200;
|
|
26917
|
+
function minifiedWindow(line, pattern) {
|
|
26918
|
+
const match = new RegExp(pattern.source, pattern.flags.replace("g", "")).exec(line);
|
|
26919
|
+
if (!match) return line;
|
|
26920
|
+
return line.slice(
|
|
26921
|
+
Math.max(0, match.index - MINIFIED_REACH),
|
|
26922
|
+
match.index + match[0].length + MINIFIED_REACH
|
|
26923
|
+
);
|
|
26924
|
+
}
|
|
26903
26925
|
function evaluateRule(rule, ctx) {
|
|
26904
26926
|
if (rule.languages && !rule.languages.includes(ctx.language)) return null;
|
|
26905
26927
|
const line = ctx.lines[ctx.index] ?? "";
|
|
@@ -26908,10 +26930,11 @@ function evaluateRule(rule, ctx) {
|
|
|
26908
26930
|
if (rule.fileRequires && !rule.fileRequires.test(fileTextOf(ctx.lines))) return null;
|
|
26909
26931
|
const back = rule.guardBack ?? 8;
|
|
26910
26932
|
const forward = rule.guardForward ?? 0;
|
|
26911
|
-
const context = windowText(ctx.lines, ctx.index, back, forward, ctx.prose);
|
|
26933
|
+
const context = line.length > MINIFIED_LINE ? minifiedWindow(line, rule.pattern) : windowText(ctx.lines, ctx.index, back, forward, ctx.prose);
|
|
26912
26934
|
if (rule.requires && !rule.requires.test(context)) return null;
|
|
26913
26935
|
if (rule.lineGuard?.test(line)) return null;
|
|
26914
26936
|
if (rule.displayedHeredocGuard && insideDisplayedHeredoc(ctx.lines, ctx.index)) return null;
|
|
26937
|
+
if (rule.displayStringGuard && !rule.pattern.test(stripDisplayedStrings(line))) return null;
|
|
26915
26938
|
if (rule.enclosingCallGuard) {
|
|
26916
26939
|
const callees = enclosingCallees(ctx.lines, ctx.index, back);
|
|
26917
26940
|
if (callees.some((callee) => rule.enclosingCallGuard.test(callee))) return null;
|