circle-ir 3.175.0 → 3.176.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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * cognium-dev #256 — same-file argument-type resolver.
3
+ *
4
+ * Two sink-shape gates ship in circle-ir today match only the DIRECT/LITERAL
5
+ * argument form and miss argument indirection:
6
+ *
7
+ * 1. `safe_if_class_literal_at` (taint-matcher.ts, #22) — matches
8
+ * `readValue(json, Foo.class)` but not `readValue(json, templateClass)`
9
+ * where `templateClass` is a `Class<T>` parameter.
10
+ * 2. Stage-11 `PROCESS_BUILDER_ARGV_FORM_RE` (sink-filter-pass.ts, #179)
11
+ * matches `new ProcessBuilder(Arrays.asList(...))` but not
12
+ * `new ProcessBuilder(buildCommand(...))` where `buildCommand` returns
13
+ * `List<String>`.
14
+ *
15
+ * This module provides two pure, same-file, `TypeInfo[]`-based helpers to
16
+ * resolve the effective type of an argument that is either:
17
+ * - a bare identifier (parameter or field name), or
18
+ * - a method-call expression (callee name).
19
+ *
20
+ * Same-file only — locals declared inside method bodies and cross-file
21
+ * resolutions are deferred. Both #256 repros (jib, flyingsaucer) are
22
+ * same-method-parameter / same-class-static-callee, so this scope suffices.
23
+ *
24
+ * Design guarantee: both resolvers return null liberally. A null return
25
+ * flows to the existing gate's default-dangerous behavior (sink fires) —
26
+ * so any resolver bug regresses gracefully to current (over-firing)
27
+ * behavior, never to false-negative.
28
+ */
29
+ import type { TypeInfo } from '../types/index.js';
30
+ /**
31
+ * Resolve the declared type of a bare-identifier argument (parameter or
32
+ * field) visible at `callInMethod` scope.
33
+ *
34
+ * Lookup order:
35
+ * 1. Parameters of the enclosing method (matching `callInMethod`).
36
+ * 2. Fields of the enclosing type (any visibility).
37
+ * 3. If enclosing type not found, scan ALL types' method params + fields
38
+ * (best-effort for top-level functions or method-name collisions).
39
+ *
40
+ * Returns the raw type string as extracted (`"Class<T>"`, `"List<String>"`,
41
+ * `"java.util.List<String>"`, `"Class<? extends JsonTemplate>"`, …) or null.
42
+ */
43
+ export declare function resolveIdentifierType(name: string, callInMethod: string | null | undefined, types: TypeInfo[]): string | null;
44
+ /**
45
+ * Resolve the declared return type of a same-file method invoked by
46
+ * `calleeName`. Accepts a bare callee name (as extracted into
47
+ * `ArgumentInfo.variable` for call expressions like `buildCommand(x, y)`).
48
+ *
49
+ * Preference order:
50
+ * 1. Method on the enclosing type matching `callInMethod`.
51
+ * 2. Method on any type in the file (static call `MyClass.foo()` case).
52
+ *
53
+ * Overload handling: if the enclosing type has multiple methods with the
54
+ * same name, returns the first one whose `return_type` is non-null. Full
55
+ * overload resolution would need argument-expression typing that we don't
56
+ * have; ambiguity is rare in practice and biases toward null (which
57
+ * flows to the current default-dangerous behavior).
58
+ */
59
+ export declare function resolveCallReturnType(calleeName: string, callInMethod: string | null | undefined, types: TypeInfo[]): string | null;
60
+ /**
61
+ * true when the raw type string represents a Java `Class` type (any bound):
62
+ * `Class`, `Class<T>`, `Class<? extends X>`, `Class<Foo>`, `java.lang.Class<...>`.
63
+ *
64
+ * NEVER matches:
65
+ * - `Class.forName(x)` — that's a call expression, not a declared type;
66
+ * lookups against `ir.types` won't find it (JDK reflection isn't
67
+ * user code).
68
+ * - `getClass()` return type — for the same reason.
69
+ * - Raw types missing generic bounds are Jackson-safe in the same way
70
+ * as the generic form: a bare `Class` param still has a compile-time
71
+ * type identity, so we accept it.
72
+ */
73
+ export declare function isBoundedClassType(rawType: string | null): boolean;
74
+ /**
75
+ * true when the raw type resolves to a container shape that
76
+ * `ProcessBuilder(argv)` accepts as non-exploitable — the JVM passes the
77
+ * elements to `fork(2)` directly, no shell interpolation:
78
+ *
79
+ * - `List<String>` (any parameterization narrower than `Object`)
80
+ * - `ArrayList<String>`, `LinkedList<String>`
81
+ * - `Collection<String>`, `Iterable<String>`, `Deque<String>`, `Queue<String>`
82
+ * - `String[]`, `String ...` (varargs)
83
+ * - Fully qualified variants: `java.util.List<String>`, etc.
84
+ *
85
+ * Excludes bare `List` / `List<Object>` / `Collection<?>` — those permit
86
+ * arbitrary element types that could carry non-String content the JVM
87
+ * would `.toString()` unsafely.
88
+ */
89
+ export declare function isArgvContainerType(rawType: string | null): boolean;
90
+ //# sourceMappingURL=arg-type-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arg-type-resolver.d.ts","sourceRoot":"","sources":["../../src/analysis/arg-type-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAoBlD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,KAAK,EAAE,QAAQ,EAAE,GAChB,MAAM,GAAG,IAAI,CA8Bf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,KAAK,EAAE,QAAQ,EAAE,GAChB,MAAM,GAAG,IAAI,CAef;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIlE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAUnE"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * cognium-dev #256 — same-file argument-type resolver.
3
+ *
4
+ * Two sink-shape gates ship in circle-ir today match only the DIRECT/LITERAL
5
+ * argument form and miss argument indirection:
6
+ *
7
+ * 1. `safe_if_class_literal_at` (taint-matcher.ts, #22) — matches
8
+ * `readValue(json, Foo.class)` but not `readValue(json, templateClass)`
9
+ * where `templateClass` is a `Class<T>` parameter.
10
+ * 2. Stage-11 `PROCESS_BUILDER_ARGV_FORM_RE` (sink-filter-pass.ts, #179)
11
+ * matches `new ProcessBuilder(Arrays.asList(...))` but not
12
+ * `new ProcessBuilder(buildCommand(...))` where `buildCommand` returns
13
+ * `List<String>`.
14
+ *
15
+ * This module provides two pure, same-file, `TypeInfo[]`-based helpers to
16
+ * resolve the effective type of an argument that is either:
17
+ * - a bare identifier (parameter or field name), or
18
+ * - a method-call expression (callee name).
19
+ *
20
+ * Same-file only — locals declared inside method bodies and cross-file
21
+ * resolutions are deferred. Both #256 repros (jib, flyingsaucer) are
22
+ * same-method-parameter / same-class-static-callee, so this scope suffices.
23
+ *
24
+ * Design guarantee: both resolvers return null liberally. A null return
25
+ * flows to the existing gate's default-dangerous behavior (sink fires) —
26
+ * so any resolver bug regresses gracefully to current (over-firing)
27
+ * behavior, never to false-negative.
28
+ */
29
+ /**
30
+ * Locate the TypeInfo whose `methods` list contains a method named
31
+ * `callInMethod`. Falls back to `null` if not found (e.g. top-level
32
+ * function, or method name collision that our best-effort match misses).
33
+ */
34
+ function findEnclosingType(callInMethod, types) {
35
+ if (!callInMethod)
36
+ return null;
37
+ for (const t of types) {
38
+ for (const m of t.methods) {
39
+ if (m.name === callInMethod)
40
+ return t;
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * Resolve the declared type of a bare-identifier argument (parameter or
47
+ * field) visible at `callInMethod` scope.
48
+ *
49
+ * Lookup order:
50
+ * 1. Parameters of the enclosing method (matching `callInMethod`).
51
+ * 2. Fields of the enclosing type (any visibility).
52
+ * 3. If enclosing type not found, scan ALL types' method params + fields
53
+ * (best-effort for top-level functions or method-name collisions).
54
+ *
55
+ * Returns the raw type string as extracted (`"Class<T>"`, `"List<String>"`,
56
+ * `"java.util.List<String>"`, `"Class<? extends JsonTemplate>"`, …) or null.
57
+ */
58
+ export function resolveIdentifierType(name, callInMethod, types) {
59
+ if (!name)
60
+ return null;
61
+ const enclosing = findEnclosingType(callInMethod, types);
62
+ if (enclosing) {
63
+ // Parameter check (preferred — narrower scope, shadows fields).
64
+ for (const m of enclosing.methods) {
65
+ if (m.name !== callInMethod)
66
+ continue;
67
+ for (const p of m.parameters) {
68
+ if (p.name === name && p.type)
69
+ return p.type;
70
+ }
71
+ }
72
+ // Field check on the enclosing type.
73
+ for (const f of enclosing.fields) {
74
+ if (f.name === name && f.type)
75
+ return f.type;
76
+ }
77
+ return null;
78
+ }
79
+ // Fallback: scan all types (top-level function case, or extractor didn't
80
+ // populate `in_method` reliably for this language).
81
+ for (const t of types) {
82
+ for (const m of t.methods) {
83
+ for (const p of m.parameters) {
84
+ if (p.name === name && p.type)
85
+ return p.type;
86
+ }
87
+ }
88
+ for (const f of t.fields) {
89
+ if (f.name === name && f.type)
90
+ return f.type;
91
+ }
92
+ }
93
+ return null;
94
+ }
95
+ /**
96
+ * Resolve the declared return type of a same-file method invoked by
97
+ * `calleeName`. Accepts a bare callee name (as extracted into
98
+ * `ArgumentInfo.variable` for call expressions like `buildCommand(x, y)`).
99
+ *
100
+ * Preference order:
101
+ * 1. Method on the enclosing type matching `callInMethod`.
102
+ * 2. Method on any type in the file (static call `MyClass.foo()` case).
103
+ *
104
+ * Overload handling: if the enclosing type has multiple methods with the
105
+ * same name, returns the first one whose `return_type` is non-null. Full
106
+ * overload resolution would need argument-expression typing that we don't
107
+ * have; ambiguity is rare in practice and biases toward null (which
108
+ * flows to the current default-dangerous behavior).
109
+ */
110
+ export function resolveCallReturnType(calleeName, callInMethod, types) {
111
+ if (!calleeName)
112
+ return null;
113
+ const enclosing = findEnclosingType(callInMethod, types);
114
+ if (enclosing) {
115
+ for (const m of enclosing.methods) {
116
+ if (m.name === calleeName && m.return_type)
117
+ return m.return_type;
118
+ }
119
+ }
120
+ // Fallback: any type in file. Static calls / helper classes.
121
+ for (const t of types) {
122
+ for (const m of t.methods) {
123
+ if (m.name === calleeName && m.return_type)
124
+ return m.return_type;
125
+ }
126
+ }
127
+ return null;
128
+ }
129
+ /**
130
+ * true when the raw type string represents a Java `Class` type (any bound):
131
+ * `Class`, `Class<T>`, `Class<? extends X>`, `Class<Foo>`, `java.lang.Class<...>`.
132
+ *
133
+ * NEVER matches:
134
+ * - `Class.forName(x)` — that's a call expression, not a declared type;
135
+ * lookups against `ir.types` won't find it (JDK reflection isn't
136
+ * user code).
137
+ * - `getClass()` return type — for the same reason.
138
+ * - Raw types missing generic bounds are Jackson-safe in the same way
139
+ * as the generic form: a bare `Class` param still has a compile-time
140
+ * type identity, so we accept it.
141
+ */
142
+ export function isBoundedClassType(rawType) {
143
+ if (!rawType)
144
+ return false;
145
+ const stripped = rawType.trim().replace(/^(?:java\.lang\.)+/, '');
146
+ return /^Class(?:\s*<[\s\S]*>)?$/.test(stripped);
147
+ }
148
+ /**
149
+ * true when the raw type resolves to a container shape that
150
+ * `ProcessBuilder(argv)` accepts as non-exploitable — the JVM passes the
151
+ * elements to `fork(2)` directly, no shell interpolation:
152
+ *
153
+ * - `List<String>` (any parameterization narrower than `Object`)
154
+ * - `ArrayList<String>`, `LinkedList<String>`
155
+ * - `Collection<String>`, `Iterable<String>`, `Deque<String>`, `Queue<String>`
156
+ * - `String[]`, `String ...` (varargs)
157
+ * - Fully qualified variants: `java.util.List<String>`, etc.
158
+ *
159
+ * Excludes bare `List` / `List<Object>` / `Collection<?>` — those permit
160
+ * arbitrary element types that could carry non-String content the JVM
161
+ * would `.toString()` unsafely.
162
+ */
163
+ export function isArgvContainerType(rawType) {
164
+ if (!rawType)
165
+ return false;
166
+ const s = rawType.trim().replace(/^(?:java\.util\.|java\.lang\.)+/, '');
167
+ // String[] or String...
168
+ if (/^String\s*(?:\[\s*\]|\.\.\.)$/.test(s))
169
+ return true;
170
+ // Container<String>-like — permit CharSequence too (String subtype narrower
171
+ // than Object). Reject `<?>`, `<? extends Object>`, bare `<Object>`.
172
+ return /^(?:List|ArrayList|LinkedList|Collection|Iterable|Deque|Queue)\s*<\s*(?:String|CharSequence|java\.lang\.String)\b/.test(s);
173
+ }
174
+ //# sourceMappingURL=arg-type-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arg-type-resolver.js","sourceRoot":"","sources":["../../src/analysis/arg-type-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH;;;;GAIG;AACH,SAAS,iBAAiB,CACxB,YAAuC,EACvC,KAAiB;IAEjB,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY;gBAAE,OAAO,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,YAAuC,EACvC,KAAiB;IAEjB,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,SAAS,GAAG,iBAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACzD,IAAI,SAAS,EAAE,CAAC;QACd,gEAAgE;QAChE,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY;gBAAE,SAAS;YACtC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;gBAC7B,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI;oBAAE,OAAO,CAAC,CAAC,IAAI,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,qCAAqC;QACrC,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI;gBAAE,OAAO,CAAC,CAA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gB,oBAAoB,CAClC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EACjC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,EAC3C,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,GACvB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CA2C5B"}
@@ -19,6 +19,11 @@ import { JS_TAINTED_PATTERNS } from './language-sources-pass.js';
19
19
  import { LIBRARY_API_SURFACE_TAG } from '../library-api-surface-downgrade.js';
20
20
  import { isNonExecutableSourceLine } from '../non-executable-lines.js';
21
21
  import { sanitizerCoversSink } from '../sanitizer-index.js';
22
+ import { resolveIdentifierType, resolveCallReturnType, isArgvContainerType, } from '../arg-type-resolver.js';
23
+ /** Escape regex metacharacters for safe pattern building. */
24
+ function escapeReSf(s) {
25
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
26
+ }
22
27
  /**
23
28
  * Common XSS sanitizer patterns for JavaScript/TypeScript.
24
29
  * These indicate the assigned value has been sanitized before use.
@@ -1022,6 +1027,8 @@ export class SinkFilterPass {
1022
1027
  // the exec is non-injectable and the `start` sink is dropped too.
1023
1028
  if (language === 'java') {
1024
1029
  const sourceLines = ctx.code.split('\n');
1030
+ const irCalls = ctx.graph.ir.calls;
1031
+ const irTypes = ctx.graph.ir.types;
1025
1032
  filtered = filtered.filter(sink => {
1026
1033
  if (sink.type !== 'command_injection')
1027
1034
  return true;
@@ -1032,6 +1039,37 @@ export class SinkFilterPass {
1032
1039
  return true;
1033
1040
  if (PROCESS_BUILDER_ARGV_FORM_RE.test(sinkLineText))
1034
1041
  return false;
1042
+ // cognium-dev #256 (3.176.0): resolver fallback for method-call and
1043
+ // variable arguments whose declared type is `List<String>` /
1044
+ // `String[]` / etc. The regex above catches literal shapes
1045
+ // (Arrays.asList, List.of, new String[]{}, varargs); this branch
1046
+ // covers `new ProcessBuilder(buildCommand(binary, opts))` where
1047
+ // `buildCommand` returns `List<String>` (flyingsaucer repro), and
1048
+ // `new ProcessBuilder(argv)` where `argv` is a `List<String>`
1049
+ // parameter. Recall-preserving: on any resolver miss, sink survives.
1050
+ const ctorCall = irCalls.find(c => c.method_name === 'ProcessBuilder' &&
1051
+ c.location.line === sink.line &&
1052
+ (c.receiver === null || c.receiver === undefined));
1053
+ if (!ctorCall || ctorCall.arguments.length === 0)
1054
+ return true;
1055
+ const arg0 = ctorCall.arguments[0];
1056
+ if (!arg0)
1057
+ return true;
1058
+ const argExpr = (arg0.expression ?? '').trim();
1059
+ const varName = arg0.variable ?? '';
1060
+ // Bare identifier — parameter/field lookup.
1061
+ if (varName !== '' && argExpr === varName && !/[(.]/.test(argExpr)) {
1062
+ const t = resolveIdentifierType(varName, ctorCall.in_method, irTypes);
1063
+ if (isArgvContainerType(t))
1064
+ return false;
1065
+ }
1066
+ // Method call — return-type lookup. `variable` field carries the
1067
+ // callee name for call-expression args.
1068
+ if (varName !== '' && new RegExp(`^${escapeReSf(varName)}\\s*\\(`).test(argExpr)) {
1069
+ const t = resolveCallReturnType(varName, ctorCall.in_method, irTypes);
1070
+ if (isArgvContainerType(t))
1071
+ return false;
1072
+ }
1035
1073
  return true;
1036
1074
  });
1037
1075
  }