circle-ir 4.19.0 → 4.21.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.
Files changed (262) hide show
  1. package/dist/analysis/advisories.d.ts +21 -3
  2. package/dist/analysis/advisories.d.ts.map +1 -1
  3. package/dist/analysis/advisories.js +26 -8
  4. package/dist/analysis/advisories.js.map +1 -1
  5. package/dist/analysis/arg-executing-programs.d.ts +16 -0
  6. package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
  7. package/dist/analysis/arg-executing-programs.js +24 -0
  8. package/dist/analysis/arg-executing-programs.js.map +1 -0
  9. package/dist/analysis/config-loader.d.ts.map +1 -1
  10. package/dist/analysis/config-loader.js +27 -3
  11. package/dist/analysis/config-loader.js.map +1 -1
  12. package/dist/analysis/constant-caller-gate.d.ts +3 -1
  13. package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
  14. package/dist/analysis/constant-caller-gate.js +108 -1
  15. package/dist/analysis/constant-caller-gate.js.map +1 -1
  16. package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
  17. package/dist/analysis/constant-propagation/index.js +1 -1
  18. package/dist/analysis/constant-propagation/index.js.map +1 -1
  19. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  20. package/dist/analysis/constant-propagation/patterns.js +8 -0
  21. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  22. package/dist/analysis/constant-propagation/propagator.d.ts +47 -2
  23. package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
  24. package/dist/analysis/constant-propagation/propagator.js +422 -57
  25. package/dist/analysis/constant-propagation/propagator.js.map +1 -1
  26. package/dist/analysis/constant-propagation/types.d.ts +2 -0
  27. package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
  28. package/dist/analysis/dependency-versions.d.ts +33 -0
  29. package/dist/analysis/dependency-versions.d.ts.map +1 -1
  30. package/dist/analysis/dependency-versions.js +70 -0
  31. package/dist/analysis/dependency-versions.js.map +1 -1
  32. package/dist/analysis/findings.d.ts.map +1 -1
  33. package/dist/analysis/findings.js +7 -5
  34. package/dist/analysis/findings.js.map +1 -1
  35. package/dist/analysis/interprocedural.d.ts +16 -0
  36. package/dist/analysis/interprocedural.d.ts.map +1 -1
  37. package/dist/analysis/interprocedural.js +545 -197
  38. package/dist/analysis/interprocedural.js.map +1 -1
  39. package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
  40. package/dist/analysis/passes/constant-propagation-pass.js +1 -0
  41. package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
  42. package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
  43. package/dist/analysis/passes/cross-file-pass.js +61 -0
  44. package/dist/analysis/passes/cross-file-pass.js.map +1 -1
  45. package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
  46. package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
  47. package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
  48. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts +58 -0
  49. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
  50. package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
  51. package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
  52. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
  53. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
  54. package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
  55. package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
  56. package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
  57. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  58. package/dist/analysis/passes/interprocedural-pass.js +220 -7
  59. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  60. package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
  61. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  62. package/dist/analysis/passes/language-sources-pass.js +549 -22
  63. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  64. package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
  65. package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
  66. package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
  67. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
  68. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js.map +1 -1
  69. package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
  70. package/dist/analysis/passes/resource-leak-pass.js +15 -3
  71. package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
  72. package/dist/analysis/passes/scan-secrets-pass.js +2 -2
  73. package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
  74. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
  75. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
  76. package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
  77. package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
  78. package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
  79. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  80. package/dist/analysis/passes/sink-filter-pass.js +564 -22
  81. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  82. package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
  83. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  84. package/dist/analysis/passes/taint-propagation-pass.js +464 -27
  85. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  86. package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
  87. package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
  88. package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
  89. package/dist/analysis/pep440-version.d.ts +40 -0
  90. package/dist/analysis/pep440-version.d.ts.map +1 -0
  91. package/dist/analysis/pep440-version.js +149 -0
  92. package/dist/analysis/pep440-version.js.map +1 -0
  93. package/dist/analysis/project-callee-escape-gate.js +1 -1
  94. package/dist/analysis/project-callee-escape-gate.js.map +1 -1
  95. package/dist/analysis/rules.d.ts.map +1 -1
  96. package/dist/analysis/rules.js +15 -0
  97. package/dist/analysis/rules.js.map +1 -1
  98. package/dist/analysis/sbom.d.ts +92 -4
  99. package/dist/analysis/sbom.d.ts.map +1 -1
  100. package/dist/analysis/sbom.js +390 -33
  101. package/dist/analysis/sbom.js.map +1 -1
  102. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  103. package/dist/analysis/taint-matcher.js +124 -19
  104. package/dist/analysis/taint-matcher.js.map +1 -1
  105. package/dist/analysis/taint-propagation.d.ts +1 -0
  106. package/dist/analysis/taint-propagation.d.ts.map +1 -1
  107. package/dist/analysis/taint-propagation.js +32 -0
  108. package/dist/analysis/taint-propagation.js.map +1 -1
  109. package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
  110. package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
  111. package/dist/analysis/test-to-production-taint-gate.js +30 -0
  112. package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
  113. package/dist/analyzer.d.ts +21 -3
  114. package/dist/analyzer.d.ts.map +1 -1
  115. package/dist/analyzer.js +83 -3
  116. package/dist/analyzer.js.map +1 -1
  117. package/dist/browser/circle-ir.js +8118 -2526
  118. package/dist/core/circle-ir-core.cjs +3098 -2280
  119. package/dist/core/circle-ir-core.js +3036 -2214
  120. package/dist/core/extractors/calls.d.ts +10 -1
  121. package/dist/core/extractors/calls.d.ts.map +1 -1
  122. package/dist/core/extractors/calls.js +148 -6
  123. package/dist/core/extractors/calls.js.map +1 -1
  124. package/dist/core/extractors/cfg.d.ts.map +1 -1
  125. package/dist/core/extractors/cfg.js +12 -0
  126. package/dist/core/extractors/cfg.js.map +1 -1
  127. package/dist/core/extractors/dfg.d.ts.map +1 -1
  128. package/dist/core/extractors/dfg.js +151 -18
  129. package/dist/core/extractors/dfg.js.map +1 -1
  130. package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
  131. package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
  132. package/dist/core/extractors/ts-declaration-detail.js +22 -0
  133. package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
  134. package/dist/core/extractors/types.d.ts +5 -0
  135. package/dist/core/extractors/types.d.ts.map +1 -1
  136. package/dist/core/extractors/types.js +149 -4
  137. package/dist/core/extractors/types.js.map +1 -1
  138. package/dist/core/parser.d.ts.map +1 -1
  139. package/dist/core/parser.js +3 -1
  140. package/dist/core/parser.js.map +1 -1
  141. package/dist/core/ts-grammar-workarounds.d.ts +18 -0
  142. package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
  143. package/dist/core/ts-grammar-workarounds.js +40 -0
  144. package/dist/core/ts-grammar-workarounds.js.map +1 -0
  145. package/dist/facts/arrow.d.ts +106 -0
  146. package/dist/facts/arrow.d.ts.map +1 -0
  147. package/dist/facts/arrow.js +196 -0
  148. package/dist/facts/arrow.js.map +1 -0
  149. package/dist/facts/facts2.d.ts +68 -0
  150. package/dist/facts/facts2.d.ts.map +1 -0
  151. package/dist/facts/facts2.js +379 -0
  152. package/dist/facts/facts2.js.map +1 -0
  153. package/dist/facts/index.d.ts +22 -0
  154. package/dist/facts/index.d.ts.map +1 -0
  155. package/dist/facts/index.js +15 -0
  156. package/dist/facts/index.js.map +1 -0
  157. package/dist/facts/java-facts.d.ts +56 -0
  158. package/dist/facts/java-facts.d.ts.map +1 -0
  159. package/dist/facts/java-facts.js +250 -0
  160. package/dist/facts/java-facts.js.map +1 -0
  161. package/dist/facts/order.d.ts +39 -0
  162. package/dist/facts/order.d.ts.map +1 -0
  163. package/dist/facts/order.js +120 -0
  164. package/dist/facts/order.js.map +1 -0
  165. package/dist/facts/schema.d.ts +60 -0
  166. package/dist/facts/schema.d.ts.map +1 -0
  167. package/dist/facts/schema.js +126 -0
  168. package/dist/facts/schema.js.map +1 -0
  169. package/dist/facts/schema2.d.ts +47 -0
  170. package/dist/facts/schema2.d.ts.map +1 -0
  171. package/dist/facts/schema2.js +194 -0
  172. package/dist/facts/schema2.js.map +1 -0
  173. package/dist/facts/t6.d.ts +84 -0
  174. package/dist/facts/t6.d.ts.map +1 -0
  175. package/dist/facts/t6.js +226 -0
  176. package/dist/facts/t6.js.map +1 -0
  177. package/dist/facts/table.d.ts +80 -0
  178. package/dist/facts/table.d.ts.map +1 -0
  179. package/dist/facts/table.js +548 -0
  180. package/dist/facts/table.js.map +1 -0
  181. package/dist/graph-facts/dead-code.d.ts +2 -0
  182. package/dist/graph-facts/dead-code.d.ts.map +1 -1
  183. package/dist/graph-facts/dead-code.js +4 -3
  184. package/dist/graph-facts/dead-code.js.map +1 -1
  185. package/dist/graph-facts/index.d.ts +1 -1
  186. package/dist/graph-facts/index.d.ts.map +1 -1
  187. package/dist/graph-facts/index.js +1 -1
  188. package/dist/graph-facts/index.js.map +1 -1
  189. package/dist/graph-facts/reach.d.ts +53 -8
  190. package/dist/graph-facts/reach.d.ts.map +1 -1
  191. package/dist/graph-facts/reach.js +172 -16
  192. package/dist/graph-facts/reach.js.map +1 -1
  193. package/dist/graph-facts/removal-reach.d.ts +2 -0
  194. package/dist/graph-facts/removal-reach.d.ts.map +1 -1
  195. package/dist/graph-facts/removal-reach.js +1 -1
  196. package/dist/graph-facts/removal-reach.js.map +1 -1
  197. package/dist/index.d.ts +15 -7
  198. package/dist/index.d.ts.map +1 -1
  199. package/dist/index.js +19 -4
  200. package/dist/index.js.map +1 -1
  201. package/dist/navigation/index.d.ts +1 -0
  202. package/dist/navigation/index.d.ts.map +1 -1
  203. package/dist/navigation/index.js +1 -0
  204. package/dist/navigation/index.js.map +1 -1
  205. package/dist/navigation/java-graph.d.ts +47 -2
  206. package/dist/navigation/java-graph.d.ts.map +1 -1
  207. package/dist/navigation/java-graph.js +395 -18
  208. package/dist/navigation/java-graph.js.map +1 -1
  209. package/dist/navigation/java-registrations.d.ts +93 -0
  210. package/dist/navigation/java-registrations.d.ts.map +1 -0
  211. package/dist/navigation/java-registrations.js +254 -0
  212. package/dist/navigation/java-registrations.js.map +1 -0
  213. package/dist/navigation/navigation-index.d.ts +74 -3
  214. package/dist/navigation/navigation-index.d.ts.map +1 -1
  215. package/dist/navigation/navigation-index.js +206 -11
  216. package/dist/navigation/navigation-index.js.map +1 -1
  217. package/dist/navigation/ts-call-edges.d.ts +15 -0
  218. package/dist/navigation/ts-call-edges.d.ts.map +1 -1
  219. package/dist/navigation/ts-call-edges.js.map +1 -1
  220. package/dist/navigation/ts-entry-tables.d.ts +1 -1
  221. package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
  222. package/dist/navigation/ts-entry-tables.js.map +1 -1
  223. package/dist/navigation/xml-scan.d.ts +40 -0
  224. package/dist/navigation/xml-scan.d.ts.map +1 -0
  225. package/dist/navigation/xml-scan.js +269 -0
  226. package/dist/navigation/xml-scan.js.map +1 -0
  227. package/dist/resolution/cross-file.d.ts +44 -0
  228. package/dist/resolution/cross-file.d.ts.map +1 -1
  229. package/dist/resolution/cross-file.js +259 -13
  230. package/dist/resolution/cross-file.js.map +1 -1
  231. package/dist/stable-ids/files.d.ts +22 -0
  232. package/dist/stable-ids/files.d.ts.map +1 -0
  233. package/dist/stable-ids/files.js +28 -0
  234. package/dist/stable-ids/files.js.map +1 -0
  235. package/dist/stable-ids/hash.d.ts +16 -4
  236. package/dist/stable-ids/hash.d.ts.map +1 -1
  237. package/dist/stable-ids/hash.js +266 -80
  238. package/dist/stable-ids/hash.js.map +1 -1
  239. package/dist/stable-ids/index.d.ts +6 -5
  240. package/dist/stable-ids/index.d.ts.map +1 -1
  241. package/dist/stable-ids/index.js +19 -6
  242. package/dist/stable-ids/index.js.map +1 -1
  243. package/dist/stable-ids/nodes.d.ts +61 -7
  244. package/dist/stable-ids/nodes.d.ts.map +1 -1
  245. package/dist/stable-ids/nodes.js +134 -21
  246. package/dist/stable-ids/nodes.js.map +1 -1
  247. package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
  248. package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
  249. package/dist/stable-ids/ts-parse-errors.js +55 -3
  250. package/dist/stable-ids/ts-parse-errors.js.map +1 -1
  251. package/dist/stable-ids/typescript.d.ts +5 -0
  252. package/dist/stable-ids/typescript.d.ts.map +1 -1
  253. package/dist/stable-ids/typescript.js +41 -8
  254. package/dist/stable-ids/typescript.js.map +1 -1
  255. package/dist/types/index.d.ts +21 -3
  256. package/dist/types/index.d.ts.map +1 -1
  257. package/dist/types/index.js +1 -0
  258. package/dist/types/index.js.map +1 -1
  259. package/docs/SPEC.md +9 -0
  260. package/package.json +9 -5
  261. package/schemas/facts@1.json +134 -0
  262. package/schemas/facts@2.json +216 -0
@@ -13,6 +13,7 @@
13
13
  *
14
14
  * Depends on: taint-matcher, constant-propagation
15
15
  */
16
+ import { runsArgvAsCommand } from '../arg-executing-programs.js';
16
17
  import { DOM_ASSIGNMENT_SINK_METHODS, isProvablyLiteralExpression, } from '../literal-expression.js';
17
18
  import { attachSourceLineCode } from '../taint-matcher.js';
18
19
  import { javaReplaceCrLfCoverage } from '../java-crlf-strip.js';
@@ -197,8 +198,14 @@ export class LanguageSourcesPass {
197
198
  additionalSources.push(...findOopFieldReadSources(types, code, language));
198
199
  // -- Java (#78 round 2): static field stores inside the same class -------
199
200
  additionalSources.push(...findStaticFieldSources(types, code, language));
201
+ // -- Java #1198: instance-field HTTP stores + reflection Field.get reads -
202
+ additionalSources.push(...findJavaInstanceFieldHttpSources(types, code, language));
203
+ additionalSources.push(...findJavaReflectionFieldGetSources(types, code, language));
204
+ additionalSources.push(...findJavaReflectionFieldSetSources(types, code, language));
200
205
  // -- Java (#78 round 2): non-bean setter/getter chains -------------------
201
206
  additionalSources.push(...findSetterChainSources(types, code, language));
207
+ // -- Java #1198: taint stored on locals' instance fields (Basic29-style) -
208
+ additionalSources.push(...findJavaHeapFieldDerivedSources(code, language));
202
209
  // -- JavaScript/TypeScript: assignment sources and DOM XSS sinks ---------
203
210
  additionalSources.push(...findJavaScriptAssignmentSources(code, language));
204
211
  // -- C#: explicit ASP.NET request sources --------------------------------
@@ -491,6 +498,8 @@ export class LanguageSourcesPass {
491
498
  additionalSanitizers.push(...findJsParameterizedSqlSanitizers(code));
492
499
  // #223 REG-144-20: JS path.resolve/join + startsWith(root) guard.
493
500
  additionalSanitizers.push(...findJsPathResolveStartsWithGuardSanitizers(code));
501
+ // cognium-dev#1146: same-file helper returns path.resolve after allow-list guard.
502
+ additionalSanitizers.push(...findJsPathAllowlistHelperSanitizers(code));
494
503
  // #223 REG-144-17/18/19: JS/TS command allowlist guard
495
504
  // (Set.has / Array.includes / indexOf) before execFile/spawn.
496
505
  additionalSanitizers.push(...findJsCommandAllowlistGuardSanitizers(code));
@@ -1030,6 +1039,182 @@ function findStaticFieldSources(types, sourceCode, language) {
1030
1039
  }
1031
1040
  return sources;
1032
1041
  }
1042
+ const JAVA_HTTP_RHS_PATTERN = /\b(?:req|request|httpRequest|servletRequest|httpServletRequest)\.(?:getParameter|getParameterValues|getParameterMap|getHeader|getHeaders|getCookies|getQueryString|getPathInfo|getRequestURI|getRequestURL|getInputStream|getReader)\b/;
1043
+ /** Shared line matchers for reflection field get/set heuristics (#1198). */
1044
+ const JAVA_DECLARE_FIELD_LINE_RE = /^\s*(?:[\w.]+\s+)?Field\s+(\w+)\s*=\s*.+\.(?:getField|getDeclaredField)\s*\(\s*"([^"]+)"\s*\)/;
1045
+ const JAVA_FIELD_SET_LINE_RE = /^\s*(\w+)\.set\s*\(\s*(\w+)\s*,\s*(\w+)\s*\)\s*;?/;
1046
+ /** cognium-dev #1198 — heap field stores `base.field = rhs;` (shared for regex-lint budget). */
1047
+ const JAVA_LOCAL_FIELD_ASSIGN_LINE_RE = /^\s*([A-Za-z_]\w*)\.([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
1048
+ const JAVA_BARE_ASSIGN_LINE_RE = /^\s*([A-Za-z_]\w*)\s*=\s*(.+?)(?:;\s*)?$/;
1049
+ /**
1050
+ * cognium-dev #1198 — Instance (non-static) field assigned from HTTP in any method.
1051
+ * Complements constructor-only #78 field sources (SecuriBench `Refl2` writes `name` in
1052
+ * `doGet`, not the ctor).
1053
+ */
1054
+ function findJavaInstanceFieldHttpSources(types, sourceCode, language) {
1055
+ if (language !== 'java')
1056
+ return [];
1057
+ const sources = [];
1058
+ const lines = sourceCode.split('\n');
1059
+ for (const type of types) {
1060
+ if (type.kind !== 'class' || type.name === '<module>')
1061
+ continue;
1062
+ const instanceFields = new Set(type.fields.filter(f => !f.modifiers.includes('static')).map(f => f.name));
1063
+ if (instanceFields.size === 0)
1064
+ continue;
1065
+ for (const m of type.methods) {
1066
+ const mStart = m.start_line;
1067
+ const mEnd = m.end_line;
1068
+ for (let i = mStart - 1; i < Math.min(mEnd, lines.length); i++) {
1069
+ const trimmed = (lines[i] ?? '').trim();
1070
+ if (!trimmed || trimmed.startsWith('//'))
1071
+ continue;
1072
+ const bm = trimmed.match(JAVA_BARE_ASSIGN_LINE_RE);
1073
+ if (!bm)
1074
+ continue;
1075
+ const fieldName = bm[1];
1076
+ const rhs = bm[2].trim().replace(/;\s*$/, '');
1077
+ if (!instanceFields.has(fieldName))
1078
+ continue;
1079
+ if (!JAVA_HTTP_RHS_PATTERN.test(rhs))
1080
+ continue;
1081
+ sources.push({
1082
+ type: 'http_param',
1083
+ location: `${type.name}.${fieldName} instance field (this.) set in ${m.name}() — #1198`,
1084
+ severity: 'high',
1085
+ line: i + 1,
1086
+ confidence: 0.85,
1087
+ variable: `this.${fieldName}`,
1088
+ });
1089
+ }
1090
+ }
1091
+ }
1092
+ return sources;
1093
+ }
1094
+ /**
1095
+ * cognium-dev #1198 — `Field.get` on a reflectively looked-up instance field that was
1096
+ * tainted earlier in the class (SecuriBench `Refl2`).
1097
+ */
1098
+ function findJavaReflectionFieldGetSources(types, sourceCode, language) {
1099
+ if (language !== 'java')
1100
+ return [];
1101
+ const lines = sourceCode.split('\n');
1102
+ const taintedFieldNames = new Set();
1103
+ for (const type of types) {
1104
+ if (type.kind !== 'class' || type.name === '<module>')
1105
+ continue;
1106
+ const instanceFields = new Set(type.fields.filter(f => !f.modifiers.includes('static')).map(f => f.name));
1107
+ for (const m of type.methods) {
1108
+ for (let i = m.start_line - 1; i < Math.min(m.end_line, lines.length); i++) {
1109
+ const trimmed = (lines[i] ?? '').trim();
1110
+ if (!trimmed || trimmed.startsWith('//'))
1111
+ continue;
1112
+ const bm = trimmed.match(JAVA_BARE_ASSIGN_LINE_RE);
1113
+ if (!bm)
1114
+ continue;
1115
+ const fieldName = bm[1];
1116
+ const rhs = bm[2].trim().replace(/;\s*$/, '');
1117
+ if (instanceFields.has(fieldName) && JAVA_HTTP_RHS_PATTERN.test(rhs)) {
1118
+ taintedFieldNames.add(fieldName);
1119
+ }
1120
+ }
1121
+ }
1122
+ }
1123
+ if (taintedFieldNames.size === 0)
1124
+ return [];
1125
+ const sources = [];
1126
+ const fieldVarToName = new Map();
1127
+ const fieldGetAssignRe = /^\s*(?:[\w.]+\s+)?(\w+)\s*=\s*\([^)]*\)\s*(\w+)\.get\s*\(/;
1128
+ for (let i = 0; i < lines.length; i++) {
1129
+ const trimmed = (lines[i] ?? '').trim();
1130
+ if (!trimmed || trimmed.startsWith('//'))
1131
+ continue;
1132
+ const decl = trimmed.match(JAVA_DECLARE_FIELD_LINE_RE);
1133
+ if (decl) {
1134
+ const [, varName, reflectedField] = decl;
1135
+ if (taintedFieldNames.has(reflectedField)) {
1136
+ fieldVarToName.set(varName, reflectedField);
1137
+ }
1138
+ continue;
1139
+ }
1140
+ const assign = trimmed.match(fieldGetAssignRe);
1141
+ if (!assign)
1142
+ continue;
1143
+ const [, lhs, fieldVar] = assign;
1144
+ const reflectedField = fieldVarToName.get(fieldVar);
1145
+ if (!reflectedField)
1146
+ continue;
1147
+ sources.push({
1148
+ type: 'http_param',
1149
+ location: `Field.get("${reflectedField}") assignment — #1198`,
1150
+ severity: 'high',
1151
+ line: i + 1,
1152
+ confidence: 0.85,
1153
+ variable: lhs,
1154
+ });
1155
+ }
1156
+ return sources;
1157
+ }
1158
+ /**
1159
+ * cognium-dev #1198 — `Field.set` stores HTTP-tainted data into a reflectively
1160
+ * looked-up instance field (`Refl3`: set on inner class field, read at sink).
1161
+ */
1162
+ function findJavaReflectionFieldSetSources(types, sourceCode, language) {
1163
+ if (language !== 'java')
1164
+ return [];
1165
+ const lines = sourceCode.split('\n');
1166
+ const taintedVars = new Set();
1167
+ for (const type of types) {
1168
+ if (type.kind !== 'class' || type.name === '<module>')
1169
+ continue;
1170
+ for (const m of type.methods) {
1171
+ for (let i = m.start_line - 1; i < Math.min(m.end_line, lines.length); i++) {
1172
+ const trimmed = (lines[i] ?? '').trim();
1173
+ if (!trimmed || trimmed.startsWith('//'))
1174
+ continue;
1175
+ const bm = trimmed.match(JAVA_BARE_ASSIGN_LINE_RE);
1176
+ if (!bm)
1177
+ continue;
1178
+ const rhs = bm[2].trim().replace(/;\s*$/, '');
1179
+ if (JAVA_HTTP_RHS_PATTERN.test(rhs)) {
1180
+ taintedVars.add(bm[1]);
1181
+ }
1182
+ }
1183
+ }
1184
+ }
1185
+ if (taintedVars.size === 0)
1186
+ return [];
1187
+ const fieldVarToName = new Map();
1188
+ const sources = [];
1189
+ for (let i = 0; i < lines.length; i++) {
1190
+ const trimmed = (lines[i] ?? '').trim();
1191
+ if (!trimmed || trimmed.startsWith('//'))
1192
+ continue;
1193
+ const decl = trimmed.match(JAVA_DECLARE_FIELD_LINE_RE);
1194
+ if (decl) {
1195
+ fieldVarToName.set(decl[1], decl[2]);
1196
+ continue;
1197
+ }
1198
+ const setM = trimmed.match(JAVA_FIELD_SET_LINE_RE);
1199
+ if (!setM)
1200
+ continue;
1201
+ const [, fieldVar, targetObj, valueArg] = setM;
1202
+ const reflectedField = fieldVarToName.get(fieldVar);
1203
+ if (!reflectedField)
1204
+ continue;
1205
+ if (!taintedVars.has(valueArg))
1206
+ continue;
1207
+ sources.push({
1208
+ type: 'http_param',
1209
+ location: `Field.set("${reflectedField}") on ${targetObj} — #1198`,
1210
+ severity: 'high',
1211
+ line: i + 1,
1212
+ confidence: 0.85,
1213
+ variable: `${targetObj}.${reflectedField}`,
1214
+ });
1215
+ }
1216
+ return sources;
1217
+ }
1033
1218
  /**
1034
1219
  * Issue #78 round 2 — Non-bean setter/getter chains (Java).
1035
1220
  *
@@ -1047,7 +1232,8 @@ function findStaticFieldSources(types, sourceCode, language) {
1047
1232
  * Strategy: for each class, build a `field -> { setter, getter }` map.
1048
1233
  * A setter is a 1-param method whose only body statement is
1049
1234
  * `this.<field> = <param>;`. A getter is a 0-param method whose only
1050
- * body statement is `return this.<field>;`. Then walk the whole source
1235
+ * body statement is `return this.<field>;` or `return <field>;` (common
1236
+ * in SecuriBench heap-widget cases). Then walk the whole source
1051
1237
  * for setter call sites whose argument matches a known HTTP source —
1052
1238
  * emit a synthetic source on the setter call line bound to the *getter*
1053
1239
  * method name, so the variable-name scan in `TaintPropagationPass`
@@ -1062,6 +1248,19 @@ function findSetterChainSources(types, sourceCode, language) {
1062
1248
  const sources = [];
1063
1249
  const lines = sourceCode.split('\n');
1064
1250
  const javaHttpPattern = /\b(?:req|request|httpRequest|servletRequest|httpServletRequest)\.(?:getParameter|getParameterValues|getParameterMap|getHeader|getHeaders|getCookies|getQueryString|getPathInfo|getRequestURI|getRequestURL|getInputStream|getReader)\b/;
1251
+ const setterArgFromHttp = (arg) => {
1252
+ const trimmed = arg.trim();
1253
+ if (javaHttpPattern.test(trimmed))
1254
+ return true;
1255
+ const id = /^\s*([A-Za-z_]\w*)\s*$/.exec(trimmed);
1256
+ if (!id)
1257
+ return false;
1258
+ const v = id[1].replace(/[$]/g, '\\$&');
1259
+ // cognium-dev#1198 — SecuriBench Basic16 passes taint as a local (`writePayload(s)`)
1260
+ // after `String s = req.getParameter(...)`; the setter-chain emitter only
1261
+ // matched literal HTTP call expressions in the argument position.
1262
+ return new RegExp(`\\b(?:[\\w.<>,\\s]+\\s+)?${v}\\s*=\\s*[^;\\n]*\\b(?:req|request|httpRequest|servletRequest|httpServletRequest)\\.(?:getParameter|getParameterValues|getHeader|getCookies|getQueryString|getInputStream|getReader)\\s*\\(`).test(sourceCode);
1263
+ };
1065
1264
  for (const type of types) {
1066
1265
  if (type.kind !== 'class')
1067
1266
  continue;
@@ -1070,7 +1269,7 @@ function findSetterChainSources(types, sourceCode, language) {
1070
1269
  // Build setter/getter pairs by inspecting per-method bodies.
1071
1270
  const pairs = new Map();
1072
1271
  const setterRe = /this\.([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\s*;?/;
1073
- const getterRe = /return\s+this\.([A-Za-z_]\w*)\s*;?/;
1272
+ const getterRe = /return\s+(?:this\.)?([A-Za-z_]\w*)\s*;?/;
1074
1273
  for (const m of type.methods) {
1075
1274
  if (m.name === type.name)
1076
1275
  continue; // skip constructor
@@ -1129,7 +1328,7 @@ function findSetterChainSources(types, sourceCode, language) {
1129
1328
  if (!cm)
1130
1329
  continue;
1131
1330
  const arg = cm[2];
1132
- if (!javaHttpPattern.test(arg))
1331
+ if (!setterArgFromHttp(arg))
1133
1332
  continue;
1134
1333
  sources.push({
1135
1334
  type: 'http_param',
@@ -1144,6 +1343,60 @@ function findSetterChainSources(types, sourceCode, language) {
1144
1343
  }
1145
1344
  return sources;
1146
1345
  }
1346
+ /**
1347
+ * cognium-dev #1198 — `next.value = name` heap field stores and reference aliases
1348
+ * (`head.next = next`) for SecuriBench Basic29-style linked structures.
1349
+ */
1350
+ function findJavaHeapFieldDerivedSources(code, language) {
1351
+ if (language !== 'java')
1352
+ return [];
1353
+ const seeds = new Set();
1354
+ for (const line of code.split('\n')) {
1355
+ const trimmed = line.trim();
1356
+ if (!trimmed || trimmed.startsWith('//'))
1357
+ continue;
1358
+ if (!JAVA_HTTP_RHS_PATTERN.test(trimmed))
1359
+ continue;
1360
+ const eq = trimmed.indexOf('=');
1361
+ if (eq < 0)
1362
+ continue;
1363
+ const rhs = trimmed.slice(eq + 1).trim().replace(/;\s*$/, '');
1364
+ if (!JAVA_HTTP_RHS_PATTERN.test(rhs))
1365
+ continue;
1366
+ const lhs = trimmed.slice(0, eq).trim();
1367
+ const bare = JAVA_BARE_ASSIGN_LINE_RE.exec(`${lhs} = ${rhs};`);
1368
+ const local = bare
1369
+ ? bare[1]
1370
+ : lhs.split(/\s+/).pop() ?? '';
1371
+ if (isSimpleJavaLocalIdent(local))
1372
+ seeds.add(local);
1373
+ }
1374
+ if (seeds.size === 0)
1375
+ return [];
1376
+ const derived = buildJavaTaintedVars(code, seeds);
1377
+ const sources = [];
1378
+ for (const [varName, line] of derived) {
1379
+ if (!varName.includes('.'))
1380
+ continue;
1381
+ const lineText = code.split('\n')[line - 1]?.trim() ?? '';
1382
+ const m = JAVA_LOCAL_FIELD_ASSIGN_LINE_RE.exec(lineText);
1383
+ if (!m)
1384
+ continue;
1385
+ const written = `${m[1]}.${m[2]}`;
1386
+ // Direct write or same-line alias (e.g. head.next.value after next.value = name).
1387
+ if (varName !== written && !varName.endsWith(`.${m[2]}`))
1388
+ continue;
1389
+ sources.push({
1390
+ type: 'http_param',
1391
+ location: `heap field read ${varName} — #1198`,
1392
+ severity: 'high',
1393
+ line,
1394
+ confidence: 0.8,
1395
+ variable: varName,
1396
+ });
1397
+ }
1398
+ return sources;
1399
+ }
1147
1400
  /**
1148
1401
  * Explicit ASP.NET Core request sources (cognium-dev C#/.NET Phase-1).
1149
1402
  *
@@ -2251,6 +2504,7 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
2251
2504
  // event-name allowlist to avoid firing on unrelated `.on('drain', cb)`
2252
2505
  // / `.on('close', cb)` etc. that carry non-user-input.
2253
2506
  sources.push(...findJavaScriptCallbackParamSources(sourceCode));
2507
+ sources.push(...findJavaScriptSubscribeCallbackParamSources(sourceCode));
2254
2508
  sources.push(...findExpressDestructuredRequestSources(sourceCode));
2255
2509
  if (language === 'javascript' || language === 'typescript') {
2256
2510
  sources.push(...findGraphqlResolverArgSources(sourceCode));
@@ -2657,6 +2911,41 @@ function findJavaScriptCallbackParamSources(sourceCode) {
2657
2911
  }
2658
2912
  return sources;
2659
2913
  }
2914
+ /**
2915
+ * cognium-dev #1224 — RxJS/Observable `.subscribe` callback first-parameter sources.
2916
+ *
2917
+ * Angular services return HTTP payloads through `service.method().subscribe((data) => …)`.
2918
+ * The first callback argument is user-influenced response body (stored-XSS shapes in Juice Shop).
2919
+ * Scoped to `.subscribe(` only — not every higher-order function — to avoid unrelated FPs.
2920
+ */
2921
+ function findJavaScriptSubscribeCallbackParamSources(sourceCode) {
2922
+ const sources = [];
2923
+ const SUBSCRIBE_CB_RE = /\.subscribe\s*\(\s*(?:async\s+)?(?:function\s*\*?\s*(?:\w+\s*)?\(\s*(\w+)|\(\s*(\w+)\s*(?:[,):]|$)|(\w+)\s*=>)/;
2924
+ const lines = sourceCode.split('\n');
2925
+ for (let i = 0; i < lines.length; i++) {
2926
+ const line = lines[i];
2927
+ const trimmed = line.trimStart();
2928
+ if (trimmed.startsWith('//') || trimmed.startsWith('*'))
2929
+ continue;
2930
+ const m = line.match(SUBSCRIBE_CB_RE);
2931
+ if (!m)
2932
+ continue;
2933
+ const paramName = m[1] ?? m[2] ?? m[3];
2934
+ if (!paramName)
2935
+ continue;
2936
+ if (paramName === 'err' || paramName === 'error')
2937
+ continue;
2938
+ sources.push({
2939
+ type: 'http_body',
2940
+ location: `Observable .subscribe(...) callback param '${paramName}' at line ${i + 1}`,
2941
+ severity: 'high',
2942
+ line: i + 1,
2943
+ confidence: 0.9,
2944
+ variable: paramName,
2945
+ });
2946
+ }
2947
+ return sources;
2948
+ }
2660
2949
  function findPythonAssignmentSources(sourceCode, language) {
2661
2950
  if (language !== 'python')
2662
2951
  return [];
@@ -4059,23 +4348,60 @@ export function buildJavaScriptTaintedVars(sourceCode, language) {
4059
4348
  continue;
4060
4349
  tainted.set(paramName, i + 1);
4061
4350
  }
4351
+ // cognium-dev#582 / #490: scan every assignment on the line; #1149: skip
4352
+ // matches inside string literals so `WHERE name = '…'` in SQL is not a bind.
4353
+ const assignmentRe = /(?:(?:var|let|const)\s+(\w+)\s*:\s*[^=;]+?\s*=(?![>=])|(?:(?:var|let|const)\s+)?(\w+)\s*=)\s*/g;
4354
+ function isInsideStringLiteral(line, index) {
4355
+ let inSingle = false;
4356
+ let inDouble = false;
4357
+ let inTemplate = false;
4358
+ let escape = false;
4359
+ for (let pos = 0; pos < index; pos++) {
4360
+ const c = line[pos];
4361
+ if (escape) {
4362
+ escape = false;
4363
+ continue;
4364
+ }
4365
+ if (c === '\\') {
4366
+ escape = true;
4367
+ continue;
4368
+ }
4369
+ if (!inDouble && !inTemplate && c === "'")
4370
+ inSingle = !inSingle;
4371
+ else if (!inSingle && !inTemplate && c === '"')
4372
+ inDouble = !inDouble;
4373
+ else if (!inSingle && !inDouble && c === '`')
4374
+ inTemplate = !inTemplate;
4375
+ }
4376
+ return inSingle || inDouble || inTemplate;
4377
+ }
4062
4378
  for (let i = 0; i < lines.length; i++) {
4063
4379
  const line = lines[i];
4064
4380
  const trimmed = line.trimStart();
4065
4381
  if (trimmed.startsWith('//') || trimmed.startsWith('*'))
4066
4382
  continue;
4067
- const assignMatch = line.match(/(?:(?:var|let|const)\s+)?(\w+)\s*=\s*(.+)/);
4068
- if (!assignMatch)
4069
- continue;
4070
- const [, lhs, rhs] = assignMatch;
4071
- if (['if', 'while', 'for', 'return', 'true', 'false', 'null', 'undefined', 'case'].includes(lhs))
4072
- continue;
4073
- if (isConstTableLookup(rhs, lookupTables))
4074
- continue; // #667
4075
- const isDirectSource = JS_TAINTED_PATTERNS.some(p => p.pattern.test(rhs));
4076
- const isTaintedPropagation = tainted.size > 0 && [...tainted.keys()].some(v => new RegExp(`\\b${v}\\b`).test(rhs));
4077
- if (isDirectSource || isTaintedPropagation)
4078
- tainted.set(lhs, i + 1);
4383
+ assignmentRe.lastIndex = 0;
4384
+ for (const assignmentMatch of line.matchAll(assignmentRe)) {
4385
+ const matchIndex = assignmentMatch.index ?? 0;
4386
+ if (isInsideStringLiteral(line, matchIndex))
4387
+ continue;
4388
+ const lhs = assignmentMatch[1] ?? assignmentMatch[2];
4389
+ if (!lhs)
4390
+ continue;
4391
+ if (['if', 'while', 'for', 'return', 'true', 'false', 'null', 'undefined', 'case'].includes(lhs)) {
4392
+ continue;
4393
+ }
4394
+ let rhs = line.slice(matchIndex + assignmentMatch[0].length).trim();
4395
+ const semi = rhs.indexOf(';');
4396
+ if (semi >= 0)
4397
+ rhs = rhs.slice(0, semi).trim();
4398
+ if (isConstTableLookup(rhs, lookupTables))
4399
+ continue; // #667
4400
+ const isDirectSource = JS_TAINTED_PATTERNS.some((p) => p.pattern.test(rhs));
4401
+ const isTaintedPropagation = tainted.size > 0 && [...tainted.keys()].some((v) => new RegExp(`\\b${v}\\b`).test(rhs));
4402
+ if (isDirectSource || isTaintedPropagation)
4403
+ tainted.set(lhs, i + 1);
4404
+ }
4079
4405
  }
4080
4406
  return tainted;
4081
4407
  }
@@ -4291,6 +4617,27 @@ function joinWrappedJavaStatement(lines, i) {
4291
4617
  * consumed by `detectExpressionScanFlows` in `taint-propagation-pass.ts`
4292
4618
  * to synthesize a virtual source for each derived var.
4293
4619
  */
4620
+ /** Reference-RHS alias in heap-field stores (no regex — regex-lint budget). */
4621
+ function isSimpleJavaLocalIdent(name) {
4622
+ if (!name)
4623
+ return false;
4624
+ const first = name.charCodeAt(0);
4625
+ if (!((first >= 65 && first <= 90) ||
4626
+ (first >= 97 && first <= 122) ||
4627
+ first === 95)) {
4628
+ return false;
4629
+ }
4630
+ for (let i = 1; i < name.length; i++) {
4631
+ const ch = name.charCodeAt(i);
4632
+ if (!((ch >= 48 && ch <= 57) ||
4633
+ (ch >= 65 && ch <= 90) ||
4634
+ (ch >= 97 && ch <= 122) ||
4635
+ ch === 95)) {
4636
+ return false;
4637
+ }
4638
+ }
4639
+ return true;
4640
+ }
4294
4641
  export function buildJavaTaintedVars(sourceCode, seedVars, deadBranchLines,
4295
4642
  /**
4296
4643
  * `trackSlots` (cognium-dev#913/#914/#916/#917): follow which element of a list
@@ -4303,11 +4650,12 @@ options) {
4303
4650
  const derived = new Map();
4304
4651
  const knownTainted = new Set(seedVars);
4305
4652
  const trackSlots = options?.trackSlots === true;
4306
- // Slot mode also reads `x = list.get(0); // note` as the statement it is: the
4307
- // assignment patterns below are anchored at `;`.
4308
- const lines = trackSlots
4309
- ? sourceCode.split('\n').map(stripJavaTrailingLineComment)
4310
- : sourceCode.split('\n');
4653
+ // Read `x = list.get(0); // note` as the statement it is: the assignment
4654
+ // patterns below are anchored at `;`. Every mode strips, not only slot mode
4655
+ // (#1105): a trailing comment hid the list read in OWASP BenchmarkTest00575.
4656
+ // Precision for safe slots (`get(1)` after `remove(0)`) still comes from
4657
+ // const-prop's list model, which vetoes the derived alias downstream.
4658
+ const lines = sourceCode.split('\n').map(stripJavaTrailingLineComment);
4311
4659
  const dead = deadBranchLines ?? new Set();
4312
4660
  /** list var → element slots: the added identifier, or `null` for a literal. */
4313
4661
  const listElems = new Map();
@@ -4349,6 +4697,29 @@ options) {
4349
4697
  complexTaintedRes.push(new RegExp(`(?<![\\p{L}\\p{N}_])${esc}(?![\\p{L}\\p{N}_])`, 'u'));
4350
4698
  }
4351
4699
  }
4700
+ /** cognium-dev#1198 — `head.next = next` reference alias for heap field reads. */
4701
+ const localRefAlias = new Map();
4702
+ const markQualifiedFieldTainted = (qualified, lineNo) => {
4703
+ if (knownTainted.has(qualified))
4704
+ return;
4705
+ derived.set(qualified, lineNo);
4706
+ knownTainted.add(qualified);
4707
+ if (!/^[\p{L}\p{N}_]+$/u.test(qualified)) {
4708
+ const esc = qualified.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
4709
+ complexTaintedRes.push(new RegExp(`(?<![\\p{L}\\p{N}_])${esc}(?![\\p{L}\\p{N}_])`, 'u'));
4710
+ }
4711
+ changed = true;
4712
+ const dot = qualified.lastIndexOf('.');
4713
+ if (dot <= 0)
4714
+ return;
4715
+ const recv = qualified.slice(0, dot);
4716
+ const field = qualified.slice(dot + 1);
4717
+ for (const [aliasPath, targetLocal] of localRefAlias) {
4718
+ if (targetLocal !== recv)
4719
+ continue;
4720
+ markQualifiedFieldTainted(`${aliasPath}.${field}`, lineNo);
4721
+ }
4722
+ };
4352
4723
  let changed = true;
4353
4724
  let guard = 0;
4354
4725
  while (changed && guard < lines.length + 2) {
@@ -4402,6 +4773,39 @@ options) {
4402
4773
  }
4403
4774
  continue;
4404
4775
  }
4776
+ const thisFieldListAddRe = /^\s*this\.([A-Za-z_]\w*)\.add\s*\(/;
4777
+ const thisListAdd = thisFieldListAddRe.exec(line);
4778
+ if (thisListAdd) {
4779
+ const field = thisListAdd[1];
4780
+ const argMatch = /this\.\w+\.add\s*\(\s*([^)]+)\)/.exec(line);
4781
+ if (argMatch) {
4782
+ const argCode = argMatch[1]
4783
+ .replace(/@?"(?:[^"\\]|\\.)*"/g, ' ')
4784
+ .replace(/'(?:[^'\\]|\\.)'/g, ' ');
4785
+ const idents = argCode.match(/[\p{L}\p{N}_]+/gu);
4786
+ const ref = (idents !== null && idents.some(t => knownTainted.has(t))) ||
4787
+ (complexTaintedRes.length > 0 && complexTaintedRes.some(re => re.test(argCode)));
4788
+ if (ref) {
4789
+ const aliases = [field, `this.${field}`];
4790
+ for (const name of aliases) {
4791
+ if (!knownTainted.has(name)) {
4792
+ derived.set(name, i + 1);
4793
+ knownTainted.add(name);
4794
+ changed = true;
4795
+ }
4796
+ }
4797
+ }
4798
+ }
4799
+ continue;
4800
+ }
4801
+ const addAllRe = /^\s*([A-Za-z_]\w*)\.addAll\s*\(\s*([A-Za-z_]\w*)\s*\)\s*;?\s*$/;
4802
+ const addAllMatch = addAllRe.exec(line.trimEnd());
4803
+ if (addAllMatch && knownTainted.has(addAllMatch[2]) && !knownTainted.has(addAllMatch[1])) {
4804
+ derived.set(addAllMatch[1], i + 1);
4805
+ knownTainted.add(addAllMatch[1]);
4806
+ changed = true;
4807
+ continue;
4808
+ }
4405
4809
  let statement = line;
4406
4810
  let declMatch = declRe.exec(statement);
4407
4811
  let assignMatch = !declMatch ? assignRe.exec(statement) : null;
@@ -4468,6 +4872,29 @@ options) {
4468
4872
  }
4469
4873
  continue;
4470
4874
  }
4875
+ const localFieldMatch = JAVA_LOCAL_FIELD_ASSIGN_LINE_RE.exec(statement.trim());
4876
+ if (localFieldMatch) {
4877
+ const recv = localFieldMatch[1];
4878
+ const field = localFieldMatch[2];
4879
+ const rhs = localFieldMatch[3];
4880
+ const qualified = `${recv}.${field}`;
4881
+ const rhsTrim = rhs.trim();
4882
+ if (isSimpleJavaLocalIdent(rhsTrim) &&
4883
+ !JAVA_KEYWORDS.has(rhsTrim)) {
4884
+ localRefAlias.set(qualified, rhsTrim);
4885
+ }
4886
+ const rhsCode = rhs
4887
+ .replace(/\$@?"(?:[^"\\]|\\.)*"/g, lit => ' ' + [...lit.matchAll(/\{([^}]*)\}/g)].map(x => x[1]).join(' ') + ' ')
4888
+ .replace(/@?"(?:[^"\\]|\\.)*"/g, ' ')
4889
+ .replace(/'(?:[^'\\]|\\.)'/g, ' ');
4890
+ const rhsIdents = rhsCode.match(/[\p{L}\p{N}_]+/gu);
4891
+ const ref = (rhsIdents !== null && rhsIdents.some(t => knownTainted.has(t))) ||
4892
+ (complexTaintedRes.length > 0 && complexTaintedRes.some(re => re.test(rhsCode)));
4893
+ if (ref) {
4894
+ markQualifiedFieldTainted(qualified, i + 1);
4895
+ }
4896
+ continue;
4897
+ }
4471
4898
  const m = declMatch ?? assignMatch;
4472
4899
  if (!m)
4473
4900
  continue;
@@ -5399,7 +5826,7 @@ function findGoMapAllowlistGuardSanitizers(code) {
5399
5826
  // (`if err != nil || !<mapName>[u.Host] {`, #293): the block runs when any
5400
5827
  // disjunct holds, so falling past it proves the key is in the map. The key
5401
5828
  // may be a selector (`u.Host`). Captures the map identifier in group 1.
5402
- const guardOpen = /^\s*if\s+(?:[^{&|]+\|\|\s*)*!\s*([A-Za-z_][A-Za-z0-9_]*)\s*\[\s*[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)?\s*\]\s*(?:\|\|[^{&]+)?\{/;
5829
+ const guardOpen = /^\s*if\s+(?:[^{&|]+\|\|)*\s*!\s*([A-Za-z_][A-Za-z0-9_]*)\s*\[\s*[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)?\s*\]\s*(?:\|\|[^{&]+)?\{/;
5403
5830
  // Allow-list naming heuristic.
5404
5831
  const allowlistName = /^(?:[A-Z][A-Z0-9_]+|.*?(allowed|accepted|whitelist|permitted|valid|approved).*)$/i;
5405
5832
  for (let i = 0; i < lines.length; i++) {
@@ -7411,7 +7838,9 @@ function findJsSsrfAllowlistGuardSanitizers(code) {
7411
7838
  * cannot smuggle shell metacharacters into a separate command.
7412
7839
  *
7413
7840
  * The shell-via-argv form `execFile('sh', ['-c', tainted])` is excluded
7414
- * since `-c` re-enables shell parsing of the subsequent argv slot. A
7841
+ * since `-c` re-enables shell parsing of the subsequent argv slot, and so is
7842
+ * a program that runs its argv as a command (`ssh`, `sudo`, `docker`, …;
7843
+ * cognium-dev#1066). A
7415
7844
  * tainted-program slot `execFile(prog, [arg])` is NOT matched (TP-2
7416
7845
  * control), nor is the single-string `exec("cmd " + arg)` form (TP-1
7417
7846
  * control — `exec` itself spawns a shell regardless).
@@ -7434,6 +7863,10 @@ function findJsArgvFormExecSanitizers(code) {
7434
7863
  continue;
7435
7864
  if (shellArgvRe.test(text))
7436
7865
  continue;
7866
+ // #1066: ssh / sudo / docker / xargs / … run their argv as a command.
7867
+ const prog = /\b(?:execFile|spawn)(?:Sync)?\s*\(\s*(['"`])([^'"`]*)\1/.exec(text);
7868
+ if (prog && runsArgvAsCommand(prog[2]))
7869
+ continue;
7437
7870
  sanitizers.push({
7438
7871
  type: 'js_argv_form_exec',
7439
7872
  method: 'execFile',
@@ -7584,6 +8017,100 @@ function findJsPathResolveStartsWithGuardSanitizers(code) {
7584
8017
  }
7585
8018
  return sanitizers;
7586
8019
  }
8020
+ /** Lines of one `{ ... }` block starting at `startLineIdx` (inclusive). */
8021
+ function jsBracedBlockLines(lines, startLineIdx) {
8022
+ let depth = 0;
8023
+ let started = false;
8024
+ const out = [];
8025
+ for (let i = startLineIdx; i < lines.length; i++) {
8026
+ const l = lines[i];
8027
+ for (const c of l) {
8028
+ if (c === '{') {
8029
+ depth++;
8030
+ started = true;
8031
+ }
8032
+ else if (c === '}') {
8033
+ depth--;
8034
+ }
8035
+ }
8036
+ out.push(l);
8037
+ if (started && depth === 0)
8038
+ return out;
8039
+ }
8040
+ return null;
8041
+ }
8042
+ /**
8043
+ * True when `bodyLines` contains a rejecting allow-list guard on canonical path
8044
+ * variable `canon` (single-root startsWith or multi-root `.some` equality/prefix).
8045
+ */
8046
+ function jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe) {
8047
+ const esc = canon.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
8048
+ const singleRoot = new RegExp(`if\\s*\\(\\s*!\\s*${esc}\\s*\\.\\s*startsWith\\s*\\(`);
8049
+ const multiRootLine = (line) => /if\s*\(\s*!\s*[A-Za-z_\w]*\.some\s*\(/.test(line) &&
8050
+ new RegExp(`\\b${esc}\\b\\s*===\\s*\\w+\\s*\\|\\|\\s*\\b${esc}\\b\\.startsWith\\s*\\(`).test(line);
8051
+ for (let j = 0; j < bodyLines.length; j++) {
8052
+ const line = bodyLines[j];
8053
+ if (!singleRoot.test(line) && !multiRootLine(line))
8054
+ continue;
8055
+ if (guardRejects(bodyLines, j, terminatorRe, 2))
8056
+ return true;
8057
+ }
8058
+ return false;
8059
+ }
8060
+ /**
8061
+ * JS/TS: a helper returns `path.resolve(param)` only after a constant-root
8062
+ * allow-list guard (startsWith or ROOTS.some equality/prefix) with throw/return
8063
+ * on failure (cognium-dev#1146).
8064
+ */
8065
+ function findJsPathAllowlistHelperSanitizers(code) {
8066
+ const sanitizers = [];
8067
+ const lines = code.split('\n');
8068
+ const terminatorRe = /\b(?:throw|return)\b/;
8069
+ const qualified = new Set();
8070
+ for (let i = 0; i < lines.length; i++) {
8071
+ const fnStart = lines[i].match(/\bfunction\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*\{/);
8072
+ if (!fnStart)
8073
+ continue;
8074
+ const fnName = fnStart[1];
8075
+ const param = fnStart[2];
8076
+ const bodyLines = jsBracedBlockLines(lines, i);
8077
+ if (!bodyLines)
8078
+ continue;
8079
+ const bodyText = bodyLines.join('\n');
8080
+ const resolveRe = new RegExp(`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*(?:(?:node:)?path|nodePath|Path)\\s*\\.\\s*(?:resolve|normalize)\\s*\\(\\s*${param}\\s*\\)`);
8081
+ const resolveM = resolveRe.exec(bodyText);
8082
+ if (!resolveM)
8083
+ continue;
8084
+ const canon = resolveM[1];
8085
+ if (!jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe))
8086
+ continue;
8087
+ if (!new RegExp(`\\breturn\\s+${canon}\\b`).test(bodyText))
8088
+ continue;
8089
+ qualified.add(fnName);
8090
+ }
8091
+ for (const fnName of qualified) {
8092
+ const escFn = fnName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
8093
+ const callAssign = new RegExp(`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*${escFn}\\s*\\(`);
8094
+ for (let i = 0; i < lines.length; i++) {
8095
+ const m = callAssign.exec(lines[i]);
8096
+ if (!m)
8097
+ continue;
8098
+ const outVar = m[1];
8099
+ const varRef = new RegExp(`\\b${outVar}\\b`);
8100
+ for (let l = i; l < lines.length; l++) {
8101
+ if (!varRef.test(lines[l]))
8102
+ continue;
8103
+ sanitizers.push({
8104
+ type: 'js_path_allowlist_helper',
8105
+ method: fnName,
8106
+ line: l + 1,
8107
+ sanitizes: ['path_traversal', 'external_taint_escape'],
8108
+ });
8109
+ }
8110
+ }
8111
+ }
8112
+ return sanitizers;
8113
+ }
7587
8114
  /**
7588
8115
  * JS/TS: bounded-command allowlist guard sanitizer (cognium-dev #223
7589
8116
  * REG-144-17/18/19).