@profullstack/threatcrush 0.12.7 → 0.12.8

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
@@ -5359,7 +5359,8 @@ var CODE_RULES = [
5359
5359
  severity: "high",
5360
5360
  languages: ["python"],
5361
5361
  pattern: /\brequests\.(?:get|request|head)\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\burlopen\s*\(\s*[a-zA-Z_]\w*\s*[,)]|\bhttpx\.get\s*\(\s*[a-zA-Z_]\w*\s*[,)]/,
5362
- needsContext: true
5362
+ needsContext: true,
5363
+ constantRequestHostGuard: true
5363
5364
  },
5364
5365
  {
5365
5366
  id: "go-ssrf-outbound-request",
@@ -6274,6 +6275,21 @@ function identifierAfter(text, start) {
6274
6275
  while (isIdentifierPart(text[index])) index += 1;
6275
6276
  return text.slice(from, index);
6276
6277
  }
6278
+ function urlAuthority(text) {
6279
+ const found = /['"]\s*https?:\/\/([^'"/?#\s]*)/.exec(text);
6280
+ return found ? found[1] : null;
6281
+ }
6282
+ function requestHostIsConstant(line, fileText) {
6283
+ const call = /(?:urlopen|requests\.(?:get|request|head)|httpx\.get)\s*\(\s*([A-Za-z_]\w*)\s*[,)]/.exec(line);
6284
+ if (!call) return false;
6285
+ const assignment = new RegExp(String.raw`^[ \t]*${call[1]}[ \t]*=[ \t]*(.+)$`, "gm");
6286
+ const values = [...fileText.matchAll(assignment)].map((m) => m[1]);
6287
+ if (!values.length) return false;
6288
+ return values.every((value) => {
6289
+ const authority = urlAuthority(value);
6290
+ return authority !== null && /^[A-Za-z0-9.-]+(?::\d+)?$/.test(authority);
6291
+ });
6292
+ }
6277
6293
  function hasSafeRedirectValue(line, fileText) {
6278
6294
  const location = line.indexOf("window.location");
6279
6295
  const redirect = line.indexOf(".redirect");
@@ -6383,6 +6399,9 @@ function evaluateRule(rule, ctx) {
6383
6399
  if (rule.safeRedirectGuard && hasSafeRedirectValue(line, fileTextOf(ctx.lines))) {
6384
6400
  return null;
6385
6401
  }
6402
+ if (rule.constantRequestHostGuard && requestHostIsConstant(line, fileTextOf(ctx.lines))) {
6403
+ return null;
6404
+ }
6386
6405
  if (rule.filledBeforeUseGuard && bufferFilledBeforeUse(ctx)) return null;
6387
6406
  const guard = rule.guard === void 0 ? GENERIC_GUARD : rule.guard;
6388
6407
  if (guard && (guard.test(line) || guard.test(context))) return null;