circle-ir 4.22.0 → 4.23.0

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.
@@ -14714,6 +14714,8 @@ var DEFAULT_SINKS = [
14714
14714
  { method: "eval", class: "ScriptContext", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
14715
14715
  // Dynamic class loading (can lead to RCE)
14716
14716
  { method: "forName", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14717
+ // Attacker-chosen class names used for reflective instantiation (yamlbeans CVE-2023-24621, cognium-dev#1290)
14718
+ { method: "forName", class: "Class", type: "deserialization", cwe: "CWE-502", severity: "critical", arg_positions: [0], languages: ["java"] },
14717
14719
  { method: "loadClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14718
14720
  { method: "defineClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0, 1] },
14719
14721
  { method: "newInstance", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [] },
@@ -16449,6 +16451,10 @@ var DEFAULT_SANITIZERS = [
16449
16451
  // Log Injection sanitizers
16450
16452
  { method: "replace", removes: ["log_injection"] },
16451
16453
  // Used to remove newlines/control chars
16454
+ // JSON.stringify escapes CR/LF (and every other control character) inside a
16455
+ // string, so a log entry cannot be split. Log injection only: the output still
16456
+ // carries `<`, quotes and shell/SQL metacharacters.
16457
+ { method: "stringify", class: "JSON", removes: ["log_injection"] },
16452
16458
  // LDAP Injection
16453
16459
  { method: "encodeForLDAP", removes: ["ldap_injection"] },
16454
16460
  { method: "encodeForDN", removes: ["ldap_injection"] },
@@ -18739,6 +18745,7 @@ var LanguageSourcesPass = class {
18739
18745
  additionalSanitizers.push(...findJsCsvFormulaPrefixSanitizers(code));
18740
18746
  additionalSanitizers.push(...findJsWrapperFunctionSanitizers(code));
18741
18747
  additionalSanitizers.push(...findJsSsrfAllowlistGuardSanitizers(code));
18748
+ additionalSanitizers.push(...findJsSsrfAllowlistWrapperSanitizers(code));
18742
18749
  additionalSanitizers.push(...findJsArgvFormExecSanitizers(code));
18743
18750
  additionalSanitizers.push(...findJsParameterizedSqlSanitizers(code));
18744
18751
  additionalSanitizers.push(
@@ -23640,6 +23647,42 @@ function findJsSsrfAllowlistGuardSanitizers(code) {
23640
23647
  }
23641
23648
  return sanitizers;
23642
23649
  }
23650
+ function findJsSsrfAllowlistWrapperSanitizers(code) {
23651
+ const sanitizers = [];
23652
+ const lines = code.split("\n");
23653
+ const fnDeclRe = /\bfunction\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)/;
23654
+ const arrowDeclRe = /\b(?:const|let|var)\s+([A-Za-z_]\w*)\s*=\s*\(\s*([A-Za-z_]\w*)\s*\)\s*=>/;
23655
+ const allowlistName = /^(?:[A-Z][A-Z0-9_]+|.*?(allowed|accepted|whitelist|permitted|valid|approved).*)$/i;
23656
+ const allowGuard = /!\s*([A-Za-z_]\w*)\s*\.\s*(?:has|includes)\s*\(/;
23657
+ const wrappers = /* @__PURE__ */ new Set();
23658
+ for (let i2 = 0; i2 < lines.length; i2++) {
23659
+ const m = fnDeclRe.exec(lines[i2]) ?? arrowDeclRe.exec(lines[i2]);
23660
+ if (!m) continue;
23661
+ const name2 = m[1];
23662
+ const param = m[2];
23663
+ const body2 = lines.slice(i2, Math.min(lines.length, i2 + 12)).join("\n");
23664
+ if (!new RegExp(`new\\s+URL\\s*\\(\\s*${param}\\b`).test(body2)) continue;
23665
+ const gm = allowGuard.exec(body2);
23666
+ if (!gm || !allowlistName.test(gm[1])) continue;
23667
+ if (!/\b(?:throw|return)\b/.test(body2)) continue;
23668
+ if (!new RegExp(`\\breturn\\s+${param}\\b`).test(body2)) continue;
23669
+ wrappers.add(name2);
23670
+ }
23671
+ for (const name2 of wrappers) {
23672
+ for (let i2 = 0; i2 < lines.length; i2++) {
23673
+ const declSelf = new RegExp(`\\b(?:function|const|let|var)\\s+${name2}\\b`);
23674
+ if (declSelf.test(lines[i2])) continue;
23675
+ if (!new RegExp(`\\b${name2}\\s*\\(`).test(lines[i2])) continue;
23676
+ sanitizers.push({
23677
+ type: "js_ssrf_allowlist_wrapper",
23678
+ method: name2,
23679
+ line: i2 + 1,
23680
+ sanitizes: ["ssrf", "external_taint_escape"]
23681
+ });
23682
+ }
23683
+ }
23684
+ return sanitizers;
23685
+ }
23643
23686
  function findJsArgvFormExecSanitizers(code) {
23644
23687
  const sanitizers = [];
23645
23688
  const lines = code.split("\n");
@@ -28142,6 +28185,40 @@ function findJavaSpringReturnXSSSinks(code, types, sources, xssSanitizerLines) {
28142
28185
  return out2;
28143
28186
  }
28144
28187
 
28188
+ // src/types/index.ts
28189
+ var SINK_TYPES = [
28190
+ "sql_injection",
28191
+ "nosql_injection",
28192
+ "command_injection",
28193
+ "path_traversal",
28194
+ "xss",
28195
+ "xxe",
28196
+ "deserialization",
28197
+ "ldap_injection",
28198
+ "xpath_injection",
28199
+ "ssrf",
28200
+ "open_redirect",
28201
+ "code_injection",
28202
+ "log_injection",
28203
+ "redos",
28204
+ "format_string",
28205
+ "crlf",
28206
+ "mass_assignment",
28207
+ "mybatis_mapper_call",
28208
+ "weak_random",
28209
+ "weak_hash",
28210
+ "weak_crypto",
28211
+ "insecure_cookie",
28212
+ "trust_boundary",
28213
+ "cache_poisoning",
28214
+ "prompt_injection",
28215
+ "insecure_storage",
28216
+ "prototype_pollution",
28217
+ "regex_dos",
28218
+ "unsafe_memory",
28219
+ "external_taint_escape"
28220
+ ];
28221
+
28145
28222
  // src/analysis/constant-propagation/patterns.ts
28146
28223
  var TAINT_PATTERNS = [
28147
28224
  // HTTP Sources (Servlet API)
@@ -28371,7 +28448,10 @@ var HTML_CONTEXT_ENCODER_METHODS = /* @__PURE__ */ new Set([
28371
28448
  "htmlEscapeDecimal",
28372
28449
  "htmlEscapeHex"
28373
28450
  ]);
28374
- var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = /* @__PURE__ */ new Set(["trust_boundary"]);
28451
+ var HTML_CONTEXT_ENCODER_COVERED_SINKS = /* @__PURE__ */ new Set(["xss", "external_taint_escape"]);
28452
+ var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = new Set(
28453
+ SINK_TYPES.filter((t) => !HTML_CONTEXT_ENCODER_COVERED_SINKS.has(t))
28454
+ );
28375
28455
  var ANTI_SANITIZER_METHODS = /* @__PURE__ */ new Set([
28376
28456
  // URL decoding (reverses URL encoding)
28377
28457
  "decode",
@@ -47951,7 +48031,7 @@ function jsLibxmljsNoentDisablesXxe(code, sinkLine) {
47951
48031
  if (closeIdx < 0) return false;
47952
48032
  const inner = afterCall.slice(openParen + 1, closeIdx);
47953
48033
  const commaIdx = inner.indexOf(",");
47954
- if (commaIdx < 0) return true;
48034
+ if (commaIdx < 0) return false;
47955
48035
  const secondArg = inner.slice(commaIdx + 1).trim();
47956
48036
  if (/^[A-Za-z_$][\w$]*$/.test(secondArg)) return false;
47957
48037
  return secondArg.startsWith("{");
@@ -51658,6 +51738,13 @@ function goConstantHelperCalleeFromLines(lines, lineNumber) {
51658
51738
  }
51659
51739
  return null;
51660
51740
  }
51741
+ function encoderLeavesSinkUncovered(constProp, graph, step, sinkType) {
51742
+ const unc = constProp.sanitizedVarUncovered;
51743
+ if (!unc || unc.size === 0) return false;
51744
+ if (step.variable.includes(":")) return !!unc.get(step.variable)?.has(sinkType);
51745
+ const method = methodAtLine(graph, step.line);
51746
+ return !!unc.get(method ? `${method}:${step.variable}` : step.variable)?.has(sinkType);
51747
+ }
51661
51748
  function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers) {
51662
51749
  const lines = typeof code === "string" ? code.split("\n") : [];
51663
51750
  const selfReassign = /* @__PURE__ */ new Map();
@@ -51684,7 +51771,7 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
51684
51771
  const use = (graph.usesByLine.get(line) ?? []).find((u) => u.variable === v && u.def_id != null);
51685
51772
  return use ? graph.defById.get(use.def_id) : void 0;
51686
51773
  };
51687
- return (step, sourceLine, sinkLine, sinkType) => {
51774
+ return (step, sourceLine, sinkLine, sinkType, encodedUpstream) => {
51688
51775
  if (step.variable.includes(".") && sources.some(
51689
51776
  (s) => s.variable === step.variable && s.line >= sourceLine && s.line <= sinkLine && typeof s.location === "string" && s.location.includes("heap field read")
51690
51777
  )) {
@@ -51702,6 +51789,7 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
51702
51789
  const r = isFalsePositive(constProp, step.line, fpLookup);
51703
51790
  if (!r.isFalsePositive) return false;
51704
51791
  if (r.reason !== "variable_not_tainted") return true;
51792
+ if (encodedUpstream) return false;
51705
51793
  if (r.reason === "variable_not_tainted" && language === "java" && method && fpLookup === step.variable && !step.variable.includes(".")) {
51706
51794
  const v = step.variable;
51707
51795
  if (constProp.tainted.has(`${method}:${v}`)) return false;
@@ -51805,8 +51893,10 @@ var TaintPropagationPass = class {
51805
51893
  const isVetoed = makeConstPropVeto(constProp, graph, sources, ctx.code, ctx.language, sanitizers);
51806
51894
  const verifiedFlows = propagationResult.flows.filter((flow) => {
51807
51895
  if (constProp.unreachableLines.has(flow.sink.line)) return false;
51896
+ let encodedUpstream = false;
51808
51897
  for (const step of flow.path) {
51809
- if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type)) return false;
51898
+ if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type, encodedUpstream)) return false;
51899
+ if (!encodedUpstream) encodedUpstream = encoderLeavesSinkUncovered(constProp, graph, step, flow.sink.type);
51810
51900
  }
51811
51901
  if (isCorrelatedPredicateFP(constProp, flow)) return false;
51812
51902
  return true;
@@ -52371,13 +52461,20 @@ function isInJavaSanitizedMethod(code, types, sinkLine, sinkType) {
52371
52461
  return true;
52372
52462
  }
52373
52463
  if (sinkType === "xxe") {
52374
- const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
52375
- if (setFeatureRe.test(body2)) return true;
52376
- if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body2)) return true;
52377
- return false;
52464
+ return isHardenedXmlFactory(body2);
52378
52465
  }
52379
52466
  return false;
52380
52467
  }
52468
+ function isHardenedXmlFactory(body2) {
52469
+ const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
52470
+ if (setFeatureRe.test(body2)) return true;
52471
+ if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body2)) return true;
52472
+ const accessName = '(?:ACCESS_EXTERNAL_(?:DTD|STYLESHEET|SCHEMA)\\b|"https?:\\/\\/javax\\.xml\\.XMLConstants\\/property\\/accessExternal(?:DTD|Stylesheet|Schema)")';
52473
+ const emptyExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*""`);
52474
+ const permissiveExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*"[^"]+"`);
52475
+ if (emptyExternalAccessRe.test(body2) && !permissiveExternalAccessRe.test(body2)) return true;
52476
+ return false;
52477
+ }
52381
52478
  function detectGoPackageGlobalFlows(code, _calls, sources, sinks, unreachableLines) {
52382
52479
  const flows = [];
52383
52480
  if (!code || sinks.length === 0) return flows;
@@ -14241,6 +14241,8 @@ var DEFAULT_SINKS = [
14241
14241
  { method: "eval", class: "ScriptContext", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
14242
14242
  // Dynamic class loading (can lead to RCE)
14243
14243
  { method: "forName", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14244
+ // Attacker-chosen class names used for reflective instantiation (yamlbeans CVE-2023-24621, cognium-dev#1290)
14245
+ { method: "forName", class: "Class", type: "deserialization", cwe: "CWE-502", severity: "critical", arg_positions: [0], languages: ["java"] },
14244
14246
  { method: "loadClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14245
14247
  { method: "defineClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0, 1] },
14246
14248
  { method: "newInstance", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [] },
@@ -15976,6 +15978,10 @@ var DEFAULT_SANITIZERS = [
15976
15978
  // Log Injection sanitizers
15977
15979
  { method: "replace", removes: ["log_injection"] },
15978
15980
  // Used to remove newlines/control chars
15981
+ // JSON.stringify escapes CR/LF (and every other control character) inside a
15982
+ // string, so a log entry cannot be split. Log injection only: the output still
15983
+ // carries `<`, quotes and shell/SQL metacharacters.
15984
+ { method: "stringify", class: "JSON", removes: ["log_injection"] },
15979
15985
  // LDAP Injection
15980
15986
  { method: "encodeForLDAP", removes: ["ldap_injection"] },
15981
15987
  { method: "encodeForDN", removes: ["ldap_injection"] },
@@ -16387,6 +16393,40 @@ function getDefaultConfig() {
16387
16393
  };
16388
16394
  }
16389
16395
 
16396
+ // src/types/index.ts
16397
+ var SINK_TYPES = [
16398
+ "sql_injection",
16399
+ "nosql_injection",
16400
+ "command_injection",
16401
+ "path_traversal",
16402
+ "xss",
16403
+ "xxe",
16404
+ "deserialization",
16405
+ "ldap_injection",
16406
+ "xpath_injection",
16407
+ "ssrf",
16408
+ "open_redirect",
16409
+ "code_injection",
16410
+ "log_injection",
16411
+ "redos",
16412
+ "format_string",
16413
+ "crlf",
16414
+ "mass_assignment",
16415
+ "mybatis_mapper_call",
16416
+ "weak_random",
16417
+ "weak_hash",
16418
+ "weak_crypto",
16419
+ "insecure_cookie",
16420
+ "trust_boundary",
16421
+ "cache_poisoning",
16422
+ "prompt_injection",
16423
+ "insecure_storage",
16424
+ "prototype_pollution",
16425
+ "regex_dos",
16426
+ "unsafe_memory",
16427
+ "external_taint_escape"
16428
+ ];
16429
+
16390
16430
  // src/analysis/constant-propagation/patterns.ts
16391
16431
  var TAINT_PATTERNS = [
16392
16432
  // HTTP Sources (Servlet API)
@@ -16616,7 +16656,10 @@ var HTML_CONTEXT_ENCODER_METHODS = /* @__PURE__ */ new Set([
16616
16656
  "htmlEscapeDecimal",
16617
16657
  "htmlEscapeHex"
16618
16658
  ]);
16619
- var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = /* @__PURE__ */ new Set(["trust_boundary"]);
16659
+ var HTML_CONTEXT_ENCODER_COVERED_SINKS = /* @__PURE__ */ new Set(["xss", "external_taint_escape"]);
16660
+ var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = new Set(
16661
+ SINK_TYPES.filter((t) => !HTML_CONTEXT_ENCODER_COVERED_SINKS.has(t))
16662
+ );
16620
16663
  var ANTI_SANITIZER_METHODS = /* @__PURE__ */ new Set([
16621
16664
  // URL decoding (reverses URL encoding)
16622
16665
  "decode",
@@ -14179,6 +14179,8 @@ var DEFAULT_SINKS = [
14179
14179
  { method: "eval", class: "ScriptContext", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
14180
14180
  // Dynamic class loading (can lead to RCE)
14181
14181
  { method: "forName", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14182
+ // Attacker-chosen class names used for reflective instantiation (yamlbeans CVE-2023-24621, cognium-dev#1290)
14183
+ { method: "forName", class: "Class", type: "deserialization", cwe: "CWE-502", severity: "critical", arg_positions: [0], languages: ["java"] },
14182
14184
  { method: "loadClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
14183
14185
  { method: "defineClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0, 1] },
14184
14186
  { method: "newInstance", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [] },
@@ -15914,6 +15916,10 @@ var DEFAULT_SANITIZERS = [
15914
15916
  // Log Injection sanitizers
15915
15917
  { method: "replace", removes: ["log_injection"] },
15916
15918
  // Used to remove newlines/control chars
15919
+ // JSON.stringify escapes CR/LF (and every other control character) inside a
15920
+ // string, so a log entry cannot be split. Log injection only: the output still
15921
+ // carries `<`, quotes and shell/SQL metacharacters.
15922
+ { method: "stringify", class: "JSON", removes: ["log_injection"] },
15917
15923
  // LDAP Injection
15918
15924
  { method: "encodeForLDAP", removes: ["ldap_injection"] },
15919
15925
  { method: "encodeForDN", removes: ["ldap_injection"] },
@@ -16325,6 +16331,40 @@ function getDefaultConfig() {
16325
16331
  };
16326
16332
  }
16327
16333
 
16334
+ // src/types/index.ts
16335
+ var SINK_TYPES = [
16336
+ "sql_injection",
16337
+ "nosql_injection",
16338
+ "command_injection",
16339
+ "path_traversal",
16340
+ "xss",
16341
+ "xxe",
16342
+ "deserialization",
16343
+ "ldap_injection",
16344
+ "xpath_injection",
16345
+ "ssrf",
16346
+ "open_redirect",
16347
+ "code_injection",
16348
+ "log_injection",
16349
+ "redos",
16350
+ "format_string",
16351
+ "crlf",
16352
+ "mass_assignment",
16353
+ "mybatis_mapper_call",
16354
+ "weak_random",
16355
+ "weak_hash",
16356
+ "weak_crypto",
16357
+ "insecure_cookie",
16358
+ "trust_boundary",
16359
+ "cache_poisoning",
16360
+ "prompt_injection",
16361
+ "insecure_storage",
16362
+ "prototype_pollution",
16363
+ "regex_dos",
16364
+ "unsafe_memory",
16365
+ "external_taint_escape"
16366
+ ];
16367
+
16328
16368
  // src/analysis/constant-propagation/patterns.ts
16329
16369
  var TAINT_PATTERNS = [
16330
16370
  // HTTP Sources (Servlet API)
@@ -16554,7 +16594,10 @@ var HTML_CONTEXT_ENCODER_METHODS = /* @__PURE__ */ new Set([
16554
16594
  "htmlEscapeDecimal",
16555
16595
  "htmlEscapeHex"
16556
16596
  ]);
16557
- var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = /* @__PURE__ */ new Set(["trust_boundary"]);
16597
+ var HTML_CONTEXT_ENCODER_COVERED_SINKS = /* @__PURE__ */ new Set(["xss", "external_taint_escape"]);
16598
+ var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = new Set(
16599
+ SINK_TYPES.filter((t) => !HTML_CONTEXT_ENCODER_COVERED_SINKS.has(t))
16600
+ );
16558
16601
  var ANTI_SANITIZER_METHODS = /* @__PURE__ */ new Set([
16559
16602
  // URL decoding (reverses URL encoding)
16560
16603
  "decode",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circle-ir",
3
- "version": "4.22.0",
3
+ "version": "4.23.0",
4
4
  "description": "High-performance Static Application Security Testing (SAST) library for detecting security vulnerabilities through taint analysis",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",