@profullstack/threatcrush 0.11.8 → 0.11.9
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 +161 -1
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +161 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16165,6 +16165,7 @@ var SECRET_RULES = [
|
|
|
16165
16165
|
keywordShaped: true
|
|
16166
16166
|
}
|
|
16167
16167
|
];
|
|
16168
|
+
var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv])`;
|
|
16168
16169
|
var KNOWN_PLACEHOLDERS = [
|
|
16169
16170
|
// Deliberately NOT here: AWS's published documentation key/secret pair
|
|
16170
16171
|
// (`AKIAIOSFODNN7EXAMPLE`, `wJalrXUtnFEMI/…`). GitHub allow-lists them, and
|
|
@@ -16188,7 +16189,19 @@ var KNOWN_PLACEHOLDERS = [
|
|
|
16188
16189
|
//
|
|
16189
16190
|
// Both halves have to be metasyntactic. `root:hunter2@` is not exempt, since
|
|
16190
16191
|
// a real password beside a common username is the case this must not swallow.
|
|
16191
|
-
/:\/\/(?:user(?:name)?|admin|root|dbuser|myuser):(?:pass(?:word|wd)?|secret|dbpass|mypassword)@/i
|
|
16192
|
+
/:\/\/(?:user(?:name)?|admin|root|dbuser|myuser):(?:pass(?:word|wd)?|secret|dbpass|mypassword)@/i,
|
|
16193
|
+
// A DSN whose password slot is an interpolation the runtime substitutes:
|
|
16194
|
+
// `postgres://{{.user}}:{{.pass}}@{{.host}}/{{.name}}`. This is a stronger
|
|
16195
|
+
// claim than the metasyntactic pair above rather than a looser one — that
|
|
16196
|
+
// rule reads English words and infers intent, whereas `{{…}}`, `${…}` and
|
|
16197
|
+
// `%s` cannot appear in a credential at all, because the value that reaches
|
|
16198
|
+
// the driver is whatever the template engine puts there. A tool that builds
|
|
16199
|
+
// connection strings holds these by the hundred and none of them is a secret.
|
|
16200
|
+
//
|
|
16201
|
+
// Only the password slot decides it. The username is not a credential, so a
|
|
16202
|
+
// literal one beside a templated password leaks nothing, while the reverse —
|
|
16203
|
+
// `postgres://{{.user}}:hunter2@` — is a real password and stays reported.
|
|
16204
|
+
new RegExp(String.raw`://[^\s'"@/]*:${INTERPOLATION}@`)
|
|
16192
16205
|
];
|
|
16193
16206
|
function isKnownPlaceholder(text) {
|
|
16194
16207
|
return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
|
|
@@ -16456,6 +16469,144 @@ function isTestPath(relativePath) {
|
|
|
16456
16469
|
const p = relativePath.replace(/\\/g, "/");
|
|
16457
16470
|
return /(?:^|\/)(?:tests?|__tests__|__mocks__|spec|specs|fixtures?|mocks?|e2e|testdata|testutils?|harness)\//i.test(p) || /(?:^|\/)(?:test|conftest)_[^/]+$/i.test(p) || /[._-](?:test|spec)\.[a-z]+$/i.test(p) || /_test\.[a-z]+$/i.test(p);
|
|
16458
16471
|
}
|
|
16472
|
+
function rustCodeLines(lines) {
|
|
16473
|
+
const out = [];
|
|
16474
|
+
let commentDepth = 0;
|
|
16475
|
+
let str = null;
|
|
16476
|
+
for (const line of lines) {
|
|
16477
|
+
let code = "";
|
|
16478
|
+
let i = 0;
|
|
16479
|
+
while (i < line.length) {
|
|
16480
|
+
const c = line[i];
|
|
16481
|
+
const d = line[i + 1];
|
|
16482
|
+
if (commentDepth > 0) {
|
|
16483
|
+
if (c === "*" && d === "/") {
|
|
16484
|
+
commentDepth -= 1;
|
|
16485
|
+
code += " ";
|
|
16486
|
+
i += 2;
|
|
16487
|
+
continue;
|
|
16488
|
+
}
|
|
16489
|
+
if (c === "/" && d === "*") {
|
|
16490
|
+
commentDepth += 1;
|
|
16491
|
+
code += " ";
|
|
16492
|
+
i += 2;
|
|
16493
|
+
continue;
|
|
16494
|
+
}
|
|
16495
|
+
code += " ";
|
|
16496
|
+
i += 1;
|
|
16497
|
+
continue;
|
|
16498
|
+
}
|
|
16499
|
+
if (str) {
|
|
16500
|
+
if (str.raw) {
|
|
16501
|
+
if (c === '"') {
|
|
16502
|
+
let hashes = 0;
|
|
16503
|
+
while (line[i + 1 + hashes] === "#") hashes += 1;
|
|
16504
|
+
if (hashes >= str.hashes) {
|
|
16505
|
+
code += " ".repeat(1 + str.hashes);
|
|
16506
|
+
i += 1 + str.hashes;
|
|
16507
|
+
str = null;
|
|
16508
|
+
continue;
|
|
16509
|
+
}
|
|
16510
|
+
}
|
|
16511
|
+
code += " ";
|
|
16512
|
+
i += 1;
|
|
16513
|
+
continue;
|
|
16514
|
+
}
|
|
16515
|
+
if (c === "\\") {
|
|
16516
|
+
code += " ";
|
|
16517
|
+
i += 2;
|
|
16518
|
+
continue;
|
|
16519
|
+
}
|
|
16520
|
+
if (c === '"') {
|
|
16521
|
+
str = null;
|
|
16522
|
+
code += " ";
|
|
16523
|
+
i += 1;
|
|
16524
|
+
continue;
|
|
16525
|
+
}
|
|
16526
|
+
code += " ";
|
|
16527
|
+
i += 1;
|
|
16528
|
+
continue;
|
|
16529
|
+
}
|
|
16530
|
+
if (c === "/" && d === "/") {
|
|
16531
|
+
code += " ".repeat(line.length - i);
|
|
16532
|
+
break;
|
|
16533
|
+
}
|
|
16534
|
+
if (c === "/" && d === "*") {
|
|
16535
|
+
commentDepth = 1;
|
|
16536
|
+
code += " ";
|
|
16537
|
+
i += 2;
|
|
16538
|
+
continue;
|
|
16539
|
+
}
|
|
16540
|
+
if (i === 0 || !/[A-Za-z0-9_]/.test(line[i - 1])) {
|
|
16541
|
+
const raw = /^b?r(#*)"/.exec(line.slice(i));
|
|
16542
|
+
if (raw) {
|
|
16543
|
+
str = { raw: true, hashes: raw[1].length };
|
|
16544
|
+
code += " ".repeat(raw[0].length);
|
|
16545
|
+
i += raw[0].length;
|
|
16546
|
+
continue;
|
|
16547
|
+
}
|
|
16548
|
+
}
|
|
16549
|
+
if (c === '"') {
|
|
16550
|
+
str = { raw: false, hashes: 0 };
|
|
16551
|
+
code += " ";
|
|
16552
|
+
i += 1;
|
|
16553
|
+
continue;
|
|
16554
|
+
}
|
|
16555
|
+
if (c === "'") {
|
|
16556
|
+
const char = /^'(?:\\.|[^\\'])'/.exec(line.slice(i));
|
|
16557
|
+
if (char) {
|
|
16558
|
+
code += " ".repeat(char[0].length);
|
|
16559
|
+
i += char[0].length;
|
|
16560
|
+
continue;
|
|
16561
|
+
}
|
|
16562
|
+
code += c;
|
|
16563
|
+
i += 1;
|
|
16564
|
+
continue;
|
|
16565
|
+
}
|
|
16566
|
+
code += c;
|
|
16567
|
+
i += 1;
|
|
16568
|
+
}
|
|
16569
|
+
out.push(code);
|
|
16570
|
+
}
|
|
16571
|
+
return out;
|
|
16572
|
+
}
|
|
16573
|
+
var RUST_CFG_NOT_TEST = /\bnot\s*\(\s*test\s*\)/;
|
|
16574
|
+
var RUST_TEST_ITEM_ATTRIBUTE = /^\s*#\s*\[\s*(?:[A-Za-z_]\w*\s*::\s*)*(?:test|bench|rstest|proptest|quickcheck|test_case)\b/;
|
|
16575
|
+
function isRustTestAttribute(code) {
|
|
16576
|
+
if (RUST_CFG_NOT_TEST.test(code)) return false;
|
|
16577
|
+
if (/^\s*#\s*\[\s*cfg\s*\(/.test(code)) return /\btest\b/.test(code);
|
|
16578
|
+
return RUST_TEST_ITEM_ATTRIBUTE.test(code);
|
|
16579
|
+
}
|
|
16580
|
+
function rustItemEnd(code, start) {
|
|
16581
|
+
let depth = 0;
|
|
16582
|
+
let opened = false;
|
|
16583
|
+
for (let i = start; i < code.length; i += 1) {
|
|
16584
|
+
for (const ch of code[i]) {
|
|
16585
|
+
if (ch === "{") {
|
|
16586
|
+
depth += 1;
|
|
16587
|
+
opened = true;
|
|
16588
|
+
} else if (ch === "}") {
|
|
16589
|
+
depth -= 1;
|
|
16590
|
+
if (opened && depth <= 0) return i;
|
|
16591
|
+
} else if (ch === ";" && !opened && depth === 0) {
|
|
16592
|
+
return i;
|
|
16593
|
+
}
|
|
16594
|
+
}
|
|
16595
|
+
}
|
|
16596
|
+
return start;
|
|
16597
|
+
}
|
|
16598
|
+
var NO_INLINE_TESTS = /* @__PURE__ */ new Set();
|
|
16599
|
+
function inlineTestLines(relativePath, lines) {
|
|
16600
|
+
if (extensionOf(relativePath).toLowerCase() !== ".rs") return NO_INLINE_TESTS;
|
|
16601
|
+
const code = rustCodeLines(lines);
|
|
16602
|
+
const inside = /* @__PURE__ */ new Set();
|
|
16603
|
+
for (let i = 0; i < code.length; i += 1) {
|
|
16604
|
+
if (inside.has(i) || !isRustTestAttribute(code[i])) continue;
|
|
16605
|
+
const end = rustItemEnd(code, i);
|
|
16606
|
+
for (let j = i; j <= end; j += 1) inside.add(j);
|
|
16607
|
+
}
|
|
16608
|
+
return inside;
|
|
16609
|
+
}
|
|
16459
16610
|
function isDocPath(relativePath) {
|
|
16460
16611
|
const p = relativePath.replace(/\\/g, "/");
|
|
16461
16612
|
return /(?:^|\/)(?:docs?|examples?|samples?)\//i.test(p) || /\.(?:md|mdx|markdown|rst|adoc)$/i.test(p);
|
|
@@ -16464,6 +16615,9 @@ var SOFTENING_ORDER = [
|
|
|
16464
16615
|
"suppressed",
|
|
16465
16616
|
"placeholder",
|
|
16466
16617
|
"self-describing",
|
|
16618
|
+
// Before `test`, because it is the narrower claim: a path holds tests, but a
|
|
16619
|
+
// block *is* one. A Rust file under `tests/` can be both.
|
|
16620
|
+
"test-block",
|
|
16467
16621
|
"test",
|
|
16468
16622
|
"docs"
|
|
16469
16623
|
];
|
|
@@ -16472,6 +16626,7 @@ function softening(reasons) {
|
|
|
16472
16626
|
}
|
|
16473
16627
|
var SECRET_SOFTENING = {
|
|
16474
16628
|
test: "in a test file \u2014 usually a fixture, still worth confirming it is not a live credential",
|
|
16629
|
+
"test-block": "in a test-only block \u2014 usually a fixture, still worth confirming it is not a live credential",
|
|
16475
16630
|
docs: "in documentation \u2014 usually an illustrative example, still worth confirming it is not a live credential",
|
|
16476
16631
|
suppressed: "on a line already marked as a false positive for another linter's security rule",
|
|
16477
16632
|
placeholder: "in example text an empty input field shows, not in data",
|
|
@@ -16479,6 +16634,7 @@ var SECRET_SOFTENING = {
|
|
|
16479
16634
|
};
|
|
16480
16635
|
var CODE_SOFTENING = {
|
|
16481
16636
|
test: "in a test file, where the construct is ordinary",
|
|
16637
|
+
"test-block": "in a test-only block, where the construct is ordinary",
|
|
16482
16638
|
docs: "in documentation or example code, which nothing runs",
|
|
16483
16639
|
suppressed: "on a line another linter's security suppression already covers",
|
|
16484
16640
|
placeholder: "in example text rather than in data",
|
|
@@ -16490,6 +16646,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
16490
16646
|
const suppressions = collectSuppressions(lines);
|
|
16491
16647
|
const inTests = isTestPath(relativePath);
|
|
16492
16648
|
const inDocs = isDocPath(relativePath);
|
|
16649
|
+
const inlineTests = inlineTestLines(relativePath, lines);
|
|
16493
16650
|
lines.forEach((line, index) => {
|
|
16494
16651
|
for (const rule of SECRET_RULES) {
|
|
16495
16652
|
const match = rule.pattern.exec(line);
|
|
@@ -16501,6 +16658,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
16501
16658
|
if (inTests && rule.keywordShaped && isTestFixtureValue(line, value)) continue;
|
|
16502
16659
|
const soft = softening({
|
|
16503
16660
|
test: inTests,
|
|
16661
|
+
"test-block": inlineTests.has(index),
|
|
16504
16662
|
suppressed: foreignSecurityMark(line),
|
|
16505
16663
|
placeholder: isPlaceholderAttribute(line, value),
|
|
16506
16664
|
"self-describing": rule.keywordShaped === true && describesItsOwnKey(line, value)
|
|
@@ -16532,6 +16690,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
16532
16690
|
if (!match) continue;
|
|
16533
16691
|
const soft = softening({
|
|
16534
16692
|
test: inTests,
|
|
16693
|
+
"test-block": inlineTests.has(index),
|
|
16535
16694
|
docs: inDocs,
|
|
16536
16695
|
suppressed: foreignSecurityMark(lines[index] ?? "")
|
|
16537
16696
|
});
|
|
@@ -16555,6 +16714,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
|
|
|
16555
16714
|
if (isSuppressed(suppressions, index, match.rule.id)) continue;
|
|
16556
16715
|
const soft = softening({
|
|
16557
16716
|
test: inTests,
|
|
16717
|
+
"test-block": inlineTests.has(index),
|
|
16558
16718
|
docs: inDocs,
|
|
16559
16719
|
suppressed: foreignSecurityMark(lines[index] ?? "")
|
|
16560
16720
|
});
|