circle-ir 3.212.0 → 3.213.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.
@@ -26175,6 +26175,7 @@ var LanguageSourcesPass = class {
26175
26175
  ...findJavaPathNormalizeStartsWithGuardSanitizers(code)
26176
26176
  );
26177
26177
  additionalSanitizers.push(...findJavaPathGetFileNameSanitizers(code));
26178
+ additionalSanitizers.push(...findJavaCanonicalPathStartsWithGuardSanitizers(code));
26178
26179
  additionalSanitizers.push(...findJavaInlineCrlfStripLogSanitizers(code));
26179
26180
  additionalSanitizers.push(...findJavaArgvFormExecSanitizers(code));
26180
26181
  for (const finding of findJavaPatternFindings(code, graph.ir.meta.file)) {
@@ -28726,19 +28727,65 @@ function findJavaPathNormalizeStartsWithGuardSanitizers(code) {
28726
28727
  }
28727
28728
  return sanitizers;
28728
28729
  }
28730
+ function findJavaCanonicalPathStartsWithGuardSanitizers(code) {
28731
+ const sanitizers = [];
28732
+ const lines = code.split("\n");
28733
+ const guardRe = /\bif\s*\(\s*!\s*([A-Za-z_]\w*)\s*\.\s*getCanonicalPath\s*\(\s*\)\s*\.\s*startsWith\s*\(/;
28734
+ const terminatorRe = /\b(throw|return)\b/;
28735
+ const assignRe = /^\s*(?:[A-Za-z_][\w.<>[\]]*\s+)?([A-Za-z_]\w*)\s*=(?!=)\s*(.*)$/;
28736
+ for (let i2 = 0; i2 < lines.length; i2++) {
28737
+ const m = guardRe.exec(lines[i2]);
28738
+ if (!m) continue;
28739
+ let hasTerminator = terminatorRe.test(lines[i2]);
28740
+ if (!hasTerminator) {
28741
+ for (let j = i2 + 1; j < Math.min(lines.length, i2 + 6); j++) {
28742
+ if (terminatorRe.test(lines[j])) {
28743
+ hasTerminator = true;
28744
+ break;
28745
+ }
28746
+ if (lines[j].includes("}")) break;
28747
+ }
28748
+ }
28749
+ if (!hasTerminator) continue;
28750
+ const guarded = /* @__PURE__ */ new Set([m[1]]);
28751
+ const mentions = (t) => {
28752
+ for (const n of guarded) if (new RegExp(`\\b${n}\\b`).test(t)) return true;
28753
+ return false;
28754
+ };
28755
+ for (let l = 0; l < lines.length; l++) {
28756
+ const lt = lines[l];
28757
+ const a = assignRe.exec(lt);
28758
+ if (a) {
28759
+ if (mentions(a[2])) guarded.add(a[1]);
28760
+ else if (a[1] !== m[1]) guarded.delete(a[1]);
28761
+ }
28762
+ if (mentions(lt)) {
28763
+ sanitizers.push({
28764
+ type: "java_canonical_startswith_guard",
28765
+ method: "getCanonicalPath",
28766
+ line: l + 1,
28767
+ sanitizes: ["path_traversal", "external_taint_escape"]
28768
+ });
28769
+ }
28770
+ }
28771
+ }
28772
+ return sanitizers;
28773
+ }
28729
28774
  function findJavaPathGetFileNameSanitizers(code) {
28730
28775
  const sanitizers = [];
28731
28776
  const lines = code.split("\n");
28732
28777
  const assignmentRe2 = /^\s*(?:(?:final\s+)?[A-Za-z_][\w.<>?,\s\[\]]*?\s+)?([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
28733
28778
  const rhsHasGetFileNameRe = /\.\s*getFileName\s*\(\s*\)/;
28734
28779
  const rhsHasPathsChainRe = /\b(?:Paths\s*\.\s*get|Path\s*\.\s*of)\s*\(/;
28780
+ const rhsNewFileGetNameRe = /\bnew\s+File\s*\([\s\S]*\)\s*\.\s*getName\s*\(\s*\)/;
28735
28781
  const candidates = [];
28736
28782
  for (let i2 = 0; i2 < lines.length; i2++) {
28737
28783
  const m = assignmentRe2.exec(lines[i2]);
28738
28784
  if (!m) continue;
28739
28785
  const rhs = m[2];
28740
- if (!rhsHasGetFileNameRe.test(rhs)) continue;
28741
- if (!rhsHasPathsChainRe.test(rhs)) continue;
28786
+ const isNioGetFileName = rhsHasGetFileNameRe.test(rhs) && rhsHasPathsChainRe.test(rhs);
28787
+ const isNewFileGetName = rhsNewFileGetNameRe.test(rhs);
28788
+ if (!isNioGetFileName && !isNewFileGetName) continue;
28742
28789
  candidates.push({ line: i2 + 1, boundVar: m[1] });
28743
28790
  }
28744
28791
  if (candidates.length === 0) return sanitizers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circle-ir",
3
- "version": "3.212.0",
3
+ "version": "3.213.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",