@profullstack/threatcrush 0.11.8 → 0.11.10

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 CHANGED
@@ -5505,7 +5505,9 @@ var CODE_RULES = [
5505
5505
  guard: false,
5506
5506
  // Installer instructions printed by the script do not execute. Matching
5507
5507
  // them made a script report its own documentation as a network pipeline.
5508
- lineGuard: /^\s*(?:echo|printf|say|info|warn|error)\s+["'][^"'\n]*\b(?:curl|wget)\b/
5508
+ lineGuard: /^\s*(?:echo|printf|say|info|warn|error)\s+["'][^"'\n]*\b(?:curl|wget)\b/,
5509
+ // The same instructions written as a `cat <<USAGE` help block.
5510
+ displayedHeredocGuard: true
5509
5511
  },
5510
5512
  {
5511
5513
  id: "sh-eval-expansion",
@@ -6178,6 +6180,23 @@ function bufferFilledBeforeUse(ctx) {
6178
6180
  }
6179
6181
  return false;
6180
6182
  }
6183
+ var HEREDOC_OPENER = /<<(-?)\s*(['"]?)([A-Za-z_][\w]*)\2/;
6184
+ function insideDisplayedHeredoc(lines, index) {
6185
+ let open = null;
6186
+ for (let i = 0; i < index; i += 1) {
6187
+ const line = lines[i] ?? "";
6188
+ if (open) {
6189
+ if (line.trim() === open.terminator) open = null;
6190
+ continue;
6191
+ }
6192
+ if (line.includes("<<<")) continue;
6193
+ const found = HEREDOC_OPENER.exec(line);
6194
+ if (found) open = { terminator: found[3], opener: line };
6195
+ }
6196
+ if (!open) return false;
6197
+ const opener = open.opener.replace(/\s[12]?>&2\b/g, " ");
6198
+ return /^\s*cat\b/.test(opener) && !/>/.test(opener) && !/\|/.test(opener);
6199
+ }
6181
6200
  function evaluateRule(rule, ctx) {
6182
6201
  if (rule.languages && !rule.languages.includes(ctx.language)) return null;
6183
6202
  const line = ctx.lines[ctx.index] ?? "";
@@ -6189,6 +6208,7 @@ function evaluateRule(rule, ctx) {
6189
6208
  const context = windowText(ctx.lines, ctx.index, back, forward, ctx.prose);
6190
6209
  if (rule.requires && !rule.requires.test(context)) return null;
6191
6210
  if (rule.lineGuard?.test(line)) return null;
6211
+ if (rule.displayedHeredocGuard && insideDisplayedHeredoc(ctx.lines, ctx.index)) return null;
6192
6212
  if (rule.enclosingCallGuard) {
6193
6213
  const callees = enclosingCallees(ctx.lines, ctx.index, back);
6194
6214
  if (callees.some((callee) => rule.enclosingCallGuard.test(callee))) return null;
@@ -6466,7 +6486,10 @@ var POPULAR_NPM = [
6466
6486
  "svelte",
6467
6487
  "angular",
6468
6488
  "rxjs",
6469
- "zod"
6489
+ "zod",
6490
+ // One edit from `react` and a popular framework in its own right: listing it
6491
+ // stops it being reported as a squat and starts protecting it from one.
6492
+ "preact"
6470
6493
  ];
6471
6494
  var POPULAR_PYPI = [
6472
6495
  "requests",
@@ -6824,6 +6847,7 @@ var SECRET_RULES = [
6824
6847
  keywordShaped: true
6825
6848
  }
6826
6849
  ];
6850
+ var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv])`;
6827
6851
  var KNOWN_PLACEHOLDERS = [
6828
6852
  // Deliberately NOT here: AWS's published documentation key/secret pair
6829
6853
  // (`AKIAIOSFODNN7EXAMPLE`, `wJalrXUtnFEMI/…`). GitHub allow-lists them, and
@@ -6847,7 +6871,19 @@ var KNOWN_PLACEHOLDERS = [
6847
6871
  //
6848
6872
  // Both halves have to be metasyntactic. `root:hunter2@` is not exempt, since
6849
6873
  // a real password beside a common username is the case this must not swallow.
6850
- /:\/\/(?:user(?:name)?|admin|root|dbuser|myuser):(?:pass(?:word|wd)?|secret|dbpass|mypassword)@/i
6874
+ /:\/\/(?:user(?:name)?|admin|root|dbuser|myuser):(?:pass(?:word|wd)?|secret|dbpass|mypassword)@/i,
6875
+ // A DSN whose password slot is an interpolation the runtime substitutes:
6876
+ // `postgres://{{.user}}:{{.pass}}@{{.host}}/{{.name}}`. This is a stronger
6877
+ // claim than the metasyntactic pair above rather than a looser one — that
6878
+ // rule reads English words and infers intent, whereas `{{…}}`, `${…}` and
6879
+ // `%s` cannot appear in a credential at all, because the value that reaches
6880
+ // the driver is whatever the template engine puts there. A tool that builds
6881
+ // connection strings holds these by the hundred and none of them is a secret.
6882
+ //
6883
+ // Only the password slot decides it. The username is not a credential, so a
6884
+ // literal one beside a templated password leaks nothing, while the reverse —
6885
+ // `postgres://{{.user}}:hunter2@` — is a real password and stays reported.
6886
+ new RegExp(String.raw`://[^\s'"@/]*:${INTERPOLATION}@`)
6851
6887
  ];
6852
6888
  function isKnownPlaceholder(text) {
6853
6889
  return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
@@ -7115,6 +7151,144 @@ function isTestPath(relativePath) {
7115
7151
  const p = relativePath.replace(/\\/g, "/");
7116
7152
  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);
7117
7153
  }
7154
+ function rustCodeLines(lines) {
7155
+ const out = [];
7156
+ let commentDepth = 0;
7157
+ let str = null;
7158
+ for (const line of lines) {
7159
+ let code = "";
7160
+ let i = 0;
7161
+ while (i < line.length) {
7162
+ const c = line[i];
7163
+ const d = line[i + 1];
7164
+ if (commentDepth > 0) {
7165
+ if (c === "*" && d === "/") {
7166
+ commentDepth -= 1;
7167
+ code += " ";
7168
+ i += 2;
7169
+ continue;
7170
+ }
7171
+ if (c === "/" && d === "*") {
7172
+ commentDepth += 1;
7173
+ code += " ";
7174
+ i += 2;
7175
+ continue;
7176
+ }
7177
+ code += " ";
7178
+ i += 1;
7179
+ continue;
7180
+ }
7181
+ if (str) {
7182
+ if (str.raw) {
7183
+ if (c === '"') {
7184
+ let hashes = 0;
7185
+ while (line[i + 1 + hashes] === "#") hashes += 1;
7186
+ if (hashes >= str.hashes) {
7187
+ code += " ".repeat(1 + str.hashes);
7188
+ i += 1 + str.hashes;
7189
+ str = null;
7190
+ continue;
7191
+ }
7192
+ }
7193
+ code += " ";
7194
+ i += 1;
7195
+ continue;
7196
+ }
7197
+ if (c === "\\") {
7198
+ code += " ";
7199
+ i += 2;
7200
+ continue;
7201
+ }
7202
+ if (c === '"') {
7203
+ str = null;
7204
+ code += " ";
7205
+ i += 1;
7206
+ continue;
7207
+ }
7208
+ code += " ";
7209
+ i += 1;
7210
+ continue;
7211
+ }
7212
+ if (c === "/" && d === "/") {
7213
+ code += " ".repeat(line.length - i);
7214
+ break;
7215
+ }
7216
+ if (c === "/" && d === "*") {
7217
+ commentDepth = 1;
7218
+ code += " ";
7219
+ i += 2;
7220
+ continue;
7221
+ }
7222
+ if (i === 0 || !/[A-Za-z0-9_]/.test(line[i - 1])) {
7223
+ const raw = /^b?r(#*)"/.exec(line.slice(i));
7224
+ if (raw) {
7225
+ str = { raw: true, hashes: raw[1].length };
7226
+ code += " ".repeat(raw[0].length);
7227
+ i += raw[0].length;
7228
+ continue;
7229
+ }
7230
+ }
7231
+ if (c === '"') {
7232
+ str = { raw: false, hashes: 0 };
7233
+ code += " ";
7234
+ i += 1;
7235
+ continue;
7236
+ }
7237
+ if (c === "'") {
7238
+ const char = /^'(?:\\.|[^\\'])'/.exec(line.slice(i));
7239
+ if (char) {
7240
+ code += " ".repeat(char[0].length);
7241
+ i += char[0].length;
7242
+ continue;
7243
+ }
7244
+ code += c;
7245
+ i += 1;
7246
+ continue;
7247
+ }
7248
+ code += c;
7249
+ i += 1;
7250
+ }
7251
+ out.push(code);
7252
+ }
7253
+ return out;
7254
+ }
7255
+ var RUST_CFG_NOT_TEST = /\bnot\s*\(\s*test\s*\)/;
7256
+ var RUST_TEST_ITEM_ATTRIBUTE = /^\s*#\s*\[\s*(?:[A-Za-z_]\w*\s*::\s*)*(?:test|bench|rstest|proptest|quickcheck|test_case)\b/;
7257
+ function isRustTestAttribute(code) {
7258
+ if (RUST_CFG_NOT_TEST.test(code)) return false;
7259
+ if (/^\s*#\s*\[\s*cfg\s*\(/.test(code)) return /\btest\b/.test(code);
7260
+ return RUST_TEST_ITEM_ATTRIBUTE.test(code);
7261
+ }
7262
+ function rustItemEnd(code, start) {
7263
+ let depth = 0;
7264
+ let opened = false;
7265
+ for (let i = start; i < code.length; i += 1) {
7266
+ for (const ch of code[i]) {
7267
+ if (ch === "{") {
7268
+ depth += 1;
7269
+ opened = true;
7270
+ } else if (ch === "}") {
7271
+ depth -= 1;
7272
+ if (opened && depth <= 0) return i;
7273
+ } else if (ch === ";" && !opened && depth === 0) {
7274
+ return i;
7275
+ }
7276
+ }
7277
+ }
7278
+ return start;
7279
+ }
7280
+ var NO_INLINE_TESTS = /* @__PURE__ */ new Set();
7281
+ function inlineTestLines(relativePath, lines) {
7282
+ if (extensionOf(relativePath).toLowerCase() !== ".rs") return NO_INLINE_TESTS;
7283
+ const code = rustCodeLines(lines);
7284
+ const inside = /* @__PURE__ */ new Set();
7285
+ for (let i = 0; i < code.length; i += 1) {
7286
+ if (inside.has(i) || !isRustTestAttribute(code[i])) continue;
7287
+ const end = rustItemEnd(code, i);
7288
+ for (let j = i; j <= end; j += 1) inside.add(j);
7289
+ }
7290
+ return inside;
7291
+ }
7118
7292
  function isDocPath(relativePath) {
7119
7293
  const p = relativePath.replace(/\\/g, "/");
7120
7294
  return /(?:^|\/)(?:docs?|examples?|samples?)\//i.test(p) || /\.(?:md|mdx|markdown|rst|adoc)$/i.test(p);
@@ -7123,6 +7297,9 @@ var SOFTENING_ORDER = [
7123
7297
  "suppressed",
7124
7298
  "placeholder",
7125
7299
  "self-describing",
7300
+ // Before `test`, because it is the narrower claim: a path holds tests, but a
7301
+ // block *is* one. A Rust file under `tests/` can be both.
7302
+ "test-block",
7126
7303
  "test",
7127
7304
  "docs"
7128
7305
  ];
@@ -7131,6 +7308,7 @@ function softening(reasons) {
7131
7308
  }
7132
7309
  var SECRET_SOFTENING = {
7133
7310
  test: "in a test file \u2014 usually a fixture, still worth confirming it is not a live credential",
7311
+ "test-block": "in a test-only block \u2014 usually a fixture, still worth confirming it is not a live credential",
7134
7312
  docs: "in documentation \u2014 usually an illustrative example, still worth confirming it is not a live credential",
7135
7313
  suppressed: "on a line already marked as a false positive for another linter's security rule",
7136
7314
  placeholder: "in example text an empty input field shows, not in data",
@@ -7138,6 +7316,7 @@ var SECRET_SOFTENING = {
7138
7316
  };
7139
7317
  var CODE_SOFTENING = {
7140
7318
  test: "in a test file, where the construct is ordinary",
7319
+ "test-block": "in a test-only block, where the construct is ordinary",
7141
7320
  docs: "in documentation or example code, which nothing runs",
7142
7321
  suppressed: "on a line another linter's security suppression already covers",
7143
7322
  placeholder: "in example text rather than in data",
@@ -7149,6 +7328,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7149
7328
  const suppressions = collectSuppressions(lines);
7150
7329
  const inTests = isTestPath(relativePath);
7151
7330
  const inDocs = isDocPath(relativePath);
7331
+ const inlineTests = inlineTestLines(relativePath, lines);
7152
7332
  lines.forEach((line, index) => {
7153
7333
  for (const rule of SECRET_RULES) {
7154
7334
  const match = rule.pattern.exec(line);
@@ -7160,6 +7340,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7160
7340
  if (inTests && rule.keywordShaped && isTestFixtureValue(line, value)) continue;
7161
7341
  const soft = softening({
7162
7342
  test: inTests,
7343
+ "test-block": inlineTests.has(index),
7163
7344
  suppressed: foreignSecurityMark(line),
7164
7345
  placeholder: isPlaceholderAttribute(line, value),
7165
7346
  "self-describing": rule.keywordShaped === true && describesItsOwnKey(line, value)
@@ -7191,6 +7372,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7191
7372
  if (!match) continue;
7192
7373
  const soft = softening({
7193
7374
  test: inTests,
7375
+ "test-block": inlineTests.has(index),
7194
7376
  docs: inDocs,
7195
7377
  suppressed: foreignSecurityMark(lines[index] ?? "")
7196
7378
  });
@@ -7214,6 +7396,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7214
7396
  if (isSuppressed(suppressions, index, match.rule.id)) continue;
7215
7397
  const soft = softening({
7216
7398
  test: inTests,
7399
+ "test-block": inlineTests.has(index),
7217
7400
  docs: inDocs,
7218
7401
  suppressed: foreignSecurityMark(lines[index] ?? "")
7219
7402
  });