@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 CHANGED
@@ -6824,6 +6824,7 @@ var SECRET_RULES = [
6824
6824
  keywordShaped: true
6825
6825
  }
6826
6826
  ];
6827
+ var INTERPOLATION = String.raw`(?:\{\{[^}]*\}\}|\$\{[^}]*\}|\$[A-Za-z_]\w*|%[sdv])`;
6827
6828
  var KNOWN_PLACEHOLDERS = [
6828
6829
  // Deliberately NOT here: AWS's published documentation key/secret pair
6829
6830
  // (`AKIAIOSFODNN7EXAMPLE`, `wJalrXUtnFEMI/…`). GitHub allow-lists them, and
@@ -6847,7 +6848,19 @@ var KNOWN_PLACEHOLDERS = [
6847
6848
  //
6848
6849
  // Both halves have to be metasyntactic. `root:hunter2@` is not exempt, since
6849
6850
  // 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
6851
+ /:\/\/(?:user(?:name)?|admin|root|dbuser|myuser):(?:pass(?:word|wd)?|secret|dbpass|mypassword)@/i,
6852
+ // A DSN whose password slot is an interpolation the runtime substitutes:
6853
+ // `postgres://{{.user}}:{{.pass}}@{{.host}}/{{.name}}`. This is a stronger
6854
+ // claim than the metasyntactic pair above rather than a looser one — that
6855
+ // rule reads English words and infers intent, whereas `{{…}}`, `${…}` and
6856
+ // `%s` cannot appear in a credential at all, because the value that reaches
6857
+ // the driver is whatever the template engine puts there. A tool that builds
6858
+ // connection strings holds these by the hundred and none of them is a secret.
6859
+ //
6860
+ // Only the password slot decides it. The username is not a credential, so a
6861
+ // literal one beside a templated password leaks nothing, while the reverse —
6862
+ // `postgres://{{.user}}:hunter2@` — is a real password and stays reported.
6863
+ new RegExp(String.raw`://[^\s'"@/]*:${INTERPOLATION}@`)
6851
6864
  ];
6852
6865
  function isKnownPlaceholder(text) {
6853
6866
  return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
@@ -7115,6 +7128,144 @@ function isTestPath(relativePath) {
7115
7128
  const p = relativePath.replace(/\\/g, "/");
7116
7129
  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
7130
  }
7131
+ function rustCodeLines(lines) {
7132
+ const out = [];
7133
+ let commentDepth = 0;
7134
+ let str = null;
7135
+ for (const line of lines) {
7136
+ let code = "";
7137
+ let i = 0;
7138
+ while (i < line.length) {
7139
+ const c = line[i];
7140
+ const d = line[i + 1];
7141
+ if (commentDepth > 0) {
7142
+ if (c === "*" && d === "/") {
7143
+ commentDepth -= 1;
7144
+ code += " ";
7145
+ i += 2;
7146
+ continue;
7147
+ }
7148
+ if (c === "/" && d === "*") {
7149
+ commentDepth += 1;
7150
+ code += " ";
7151
+ i += 2;
7152
+ continue;
7153
+ }
7154
+ code += " ";
7155
+ i += 1;
7156
+ continue;
7157
+ }
7158
+ if (str) {
7159
+ if (str.raw) {
7160
+ if (c === '"') {
7161
+ let hashes = 0;
7162
+ while (line[i + 1 + hashes] === "#") hashes += 1;
7163
+ if (hashes >= str.hashes) {
7164
+ code += " ".repeat(1 + str.hashes);
7165
+ i += 1 + str.hashes;
7166
+ str = null;
7167
+ continue;
7168
+ }
7169
+ }
7170
+ code += " ";
7171
+ i += 1;
7172
+ continue;
7173
+ }
7174
+ if (c === "\\") {
7175
+ code += " ";
7176
+ i += 2;
7177
+ continue;
7178
+ }
7179
+ if (c === '"') {
7180
+ str = null;
7181
+ code += " ";
7182
+ i += 1;
7183
+ continue;
7184
+ }
7185
+ code += " ";
7186
+ i += 1;
7187
+ continue;
7188
+ }
7189
+ if (c === "/" && d === "/") {
7190
+ code += " ".repeat(line.length - i);
7191
+ break;
7192
+ }
7193
+ if (c === "/" && d === "*") {
7194
+ commentDepth = 1;
7195
+ code += " ";
7196
+ i += 2;
7197
+ continue;
7198
+ }
7199
+ if (i === 0 || !/[A-Za-z0-9_]/.test(line[i - 1])) {
7200
+ const raw = /^b?r(#*)"/.exec(line.slice(i));
7201
+ if (raw) {
7202
+ str = { raw: true, hashes: raw[1].length };
7203
+ code += " ".repeat(raw[0].length);
7204
+ i += raw[0].length;
7205
+ continue;
7206
+ }
7207
+ }
7208
+ if (c === '"') {
7209
+ str = { raw: false, hashes: 0 };
7210
+ code += " ";
7211
+ i += 1;
7212
+ continue;
7213
+ }
7214
+ if (c === "'") {
7215
+ const char = /^'(?:\\.|[^\\'])'/.exec(line.slice(i));
7216
+ if (char) {
7217
+ code += " ".repeat(char[0].length);
7218
+ i += char[0].length;
7219
+ continue;
7220
+ }
7221
+ code += c;
7222
+ i += 1;
7223
+ continue;
7224
+ }
7225
+ code += c;
7226
+ i += 1;
7227
+ }
7228
+ out.push(code);
7229
+ }
7230
+ return out;
7231
+ }
7232
+ var RUST_CFG_NOT_TEST = /\bnot\s*\(\s*test\s*\)/;
7233
+ var RUST_TEST_ITEM_ATTRIBUTE = /^\s*#\s*\[\s*(?:[A-Za-z_]\w*\s*::\s*)*(?:test|bench|rstest|proptest|quickcheck|test_case)\b/;
7234
+ function isRustTestAttribute(code) {
7235
+ if (RUST_CFG_NOT_TEST.test(code)) return false;
7236
+ if (/^\s*#\s*\[\s*cfg\s*\(/.test(code)) return /\btest\b/.test(code);
7237
+ return RUST_TEST_ITEM_ATTRIBUTE.test(code);
7238
+ }
7239
+ function rustItemEnd(code, start) {
7240
+ let depth = 0;
7241
+ let opened = false;
7242
+ for (let i = start; i < code.length; i += 1) {
7243
+ for (const ch of code[i]) {
7244
+ if (ch === "{") {
7245
+ depth += 1;
7246
+ opened = true;
7247
+ } else if (ch === "}") {
7248
+ depth -= 1;
7249
+ if (opened && depth <= 0) return i;
7250
+ } else if (ch === ";" && !opened && depth === 0) {
7251
+ return i;
7252
+ }
7253
+ }
7254
+ }
7255
+ return start;
7256
+ }
7257
+ var NO_INLINE_TESTS = /* @__PURE__ */ new Set();
7258
+ function inlineTestLines(relativePath, lines) {
7259
+ if (extensionOf(relativePath).toLowerCase() !== ".rs") return NO_INLINE_TESTS;
7260
+ const code = rustCodeLines(lines);
7261
+ const inside = /* @__PURE__ */ new Set();
7262
+ for (let i = 0; i < code.length; i += 1) {
7263
+ if (inside.has(i) || !isRustTestAttribute(code[i])) continue;
7264
+ const end = rustItemEnd(code, i);
7265
+ for (let j = i; j <= end; j += 1) inside.add(j);
7266
+ }
7267
+ return inside;
7268
+ }
7118
7269
  function isDocPath(relativePath) {
7119
7270
  const p = relativePath.replace(/\\/g, "/");
7120
7271
  return /(?:^|\/)(?:docs?|examples?|samples?)\//i.test(p) || /\.(?:md|mdx|markdown|rst|adoc)$/i.test(p);
@@ -7123,6 +7274,9 @@ var SOFTENING_ORDER = [
7123
7274
  "suppressed",
7124
7275
  "placeholder",
7125
7276
  "self-describing",
7277
+ // Before `test`, because it is the narrower claim: a path holds tests, but a
7278
+ // block *is* one. A Rust file under `tests/` can be both.
7279
+ "test-block",
7126
7280
  "test",
7127
7281
  "docs"
7128
7282
  ];
@@ -7131,6 +7285,7 @@ function softening(reasons) {
7131
7285
  }
7132
7286
  var SECRET_SOFTENING = {
7133
7287
  test: "in a test file \u2014 usually a fixture, still worth confirming it is not a live credential",
7288
+ "test-block": "in a test-only block \u2014 usually a fixture, still worth confirming it is not a live credential",
7134
7289
  docs: "in documentation \u2014 usually an illustrative example, still worth confirming it is not a live credential",
7135
7290
  suppressed: "on a line already marked as a false positive for another linter's security rule",
7136
7291
  placeholder: "in example text an empty input field shows, not in data",
@@ -7138,6 +7293,7 @@ var SECRET_SOFTENING = {
7138
7293
  };
7139
7294
  var CODE_SOFTENING = {
7140
7295
  test: "in a test file, where the construct is ordinary",
7296
+ "test-block": "in a test-only block, where the construct is ordinary",
7141
7297
  docs: "in documentation or example code, which nothing runs",
7142
7298
  suppressed: "on a line another linter's security suppression already covers",
7143
7299
  placeholder: "in example text rather than in data",
@@ -7149,6 +7305,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7149
7305
  const suppressions = collectSuppressions(lines);
7150
7306
  const inTests = isTestPath(relativePath);
7151
7307
  const inDocs = isDocPath(relativePath);
7308
+ const inlineTests = inlineTestLines(relativePath, lines);
7152
7309
  lines.forEach((line, index) => {
7153
7310
  for (const rule of SECRET_RULES) {
7154
7311
  const match = rule.pattern.exec(line);
@@ -7160,6 +7317,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7160
7317
  if (inTests && rule.keywordShaped && isTestFixtureValue(line, value)) continue;
7161
7318
  const soft = softening({
7162
7319
  test: inTests,
7320
+ "test-block": inlineTests.has(index),
7163
7321
  suppressed: foreignSecurityMark(line),
7164
7322
  placeholder: isPlaceholderAttribute(line, value),
7165
7323
  "self-describing": rule.keywordShaped === true && describesItsOwnKey(line, value)
@@ -7191,6 +7349,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7191
7349
  if (!match) continue;
7192
7350
  const soft = softening({
7193
7351
  test: inTests,
7352
+ "test-block": inlineTests.has(index),
7194
7353
  docs: inDocs,
7195
7354
  suppressed: foreignSecurityMark(lines[index] ?? "")
7196
7355
  });
@@ -7214,6 +7373,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
7214
7373
  if (isSuppressed(suppressions, index, match.rule.id)) continue;
7215
7374
  const soft = softening({
7216
7375
  test: inTests,
7376
+ "test-block": inlineTests.has(index),
7217
7377
  docs: inDocs,
7218
7378
  suppressed: foreignSecurityMark(lines[index] ?? "")
7219
7379
  });