circle-ir 4.19.0 → 4.20.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.
- package/dist/analysis/advisories.d.ts +21 -3
- package/dist/analysis/advisories.d.ts.map +1 -1
- package/dist/analysis/advisories.js +26 -8
- package/dist/analysis/advisories.js.map +1 -1
- package/dist/analysis/arg-executing-programs.d.ts +16 -0
- package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
- package/dist/analysis/arg-executing-programs.js +24 -0
- package/dist/analysis/arg-executing-programs.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +10 -1
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +3 -1
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +108 -1
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/index.js +1 -1
- package/dist/analysis/constant-propagation/index.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +5 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +15 -1
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/constant-propagation/types.d.ts +2 -0
- package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.d.ts +33 -0
- package/dist/analysis/dependency-versions.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.js +70 -0
- package/dist/analysis/dependency-versions.js.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +1 -0
- package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +61 -0
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +140 -0
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +110 -6
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +15 -3
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +192 -8
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +176 -15
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
- package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
- package/dist/analysis/pep440-version.d.ts +40 -0
- package/dist/analysis/pep440-version.d.ts.map +1 -0
- package/dist/analysis/pep440-version.js +149 -0
- package/dist/analysis/pep440-version.js.map +1 -0
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +6 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +43 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +265 -33
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +39 -3
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +6 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +27 -1
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3151 -61
- package/dist/core/circle-ir-core.cjs +78 -6
- package/dist/core/circle-ir-core.js +78 -6
- package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.js +22 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
- package/dist/facts/arrow.d.ts +106 -0
- package/dist/facts/arrow.d.ts.map +1 -0
- package/dist/facts/arrow.js +196 -0
- package/dist/facts/arrow.js.map +1 -0
- package/dist/facts/facts2.d.ts +59 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +362 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +20 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +14 -0
- package/dist/facts/index.js.map +1 -0
- package/dist/facts/java-facts.d.ts +56 -0
- package/dist/facts/java-facts.d.ts.map +1 -0
- package/dist/facts/java-facts.js +250 -0
- package/dist/facts/java-facts.js.map +1 -0
- package/dist/facts/order.d.ts +39 -0
- package/dist/facts/order.d.ts.map +1 -0
- package/dist/facts/order.js +120 -0
- package/dist/facts/order.js.map +1 -0
- package/dist/facts/schema.d.ts +60 -0
- package/dist/facts/schema.d.ts.map +1 -0
- package/dist/facts/schema.js +126 -0
- package/dist/facts/schema.js.map +1 -0
- package/dist/facts/schema2.d.ts +47 -0
- package/dist/facts/schema2.d.ts.map +1 -0
- package/dist/facts/schema2.js +194 -0
- package/dist/facts/schema2.js.map +1 -0
- package/dist/facts/table.d.ts +80 -0
- package/dist/facts/table.d.ts.map +1 -0
- package/dist/facts/table.js +548 -0
- package/dist/facts/table.js.map +1 -0
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +1 -1
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +24 -6
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +52 -12
- package/dist/graph-facts/reach.js.map +1 -1
- package/dist/graph-facts/removal-reach.d.ts +2 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -1
- package/dist/graph-facts/removal-reach.js +1 -1
- package/dist/graph-facts/removal-reach.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +23 -0
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +222 -8
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/navigation-index.d.ts +9 -0
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +25 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +9 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/resolution/cross-file.d.ts +44 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +259 -13
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/files.d.ts +22 -0
- package/dist/stable-ids/files.d.ts.map +1 -0
- package/dist/stable-ids/files.js +28 -0
- package/dist/stable-ids/files.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +16 -4
- package/dist/stable-ids/hash.d.ts.map +1 -1
- package/dist/stable-ids/hash.js +266 -80
- package/dist/stable-ids/hash.js.map +1 -1
- package/dist/stable-ids/index.d.ts +3 -2
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +3 -2
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +45 -1
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +118 -15
- package/dist/stable-ids/nodes.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +35 -2
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/package.json +8 -4
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -49,9 +49,13 @@ export declare class TaintPropagationPass implements AnalysisPass<TaintPropagati
|
|
|
49
49
|
* Interpolation bodies are masked recursively, so a quoted subscript inside
|
|
50
50
|
* one (`f"{d['actor']}"`) does not smuggle the literal back in.
|
|
51
51
|
*
|
|
52
|
-
* LANGUAGE SCOPE — this is applied to Python
|
|
53
|
-
* gates it (`MASKABLE_STRING_LANGUAGES`). In those
|
|
54
|
-
*
|
|
52
|
+
* LANGUAGE SCOPE — this is applied to Python, JS/TS and Java, and the caller
|
|
53
|
+
* gates it (`MASKABLE_STRING_LANGUAGES`). In those, a plain quoted string
|
|
54
|
+
* cannot interpolate, so blanking its text is sound. Java was added for
|
|
55
|
+
* cognium-dev#915: `write("Parameter value: " + bar)` tokenised `value` and
|
|
56
|
+
* linked an unrelated tainted loop local of that name to the sink (OWASP
|
|
57
|
+
* BenchmarkTest01439). Java `"…"`, text blocks and char literals never
|
|
58
|
+
* interpolate. Elsewhere it is
|
|
55
59
|
* not, and the suite proved it: Bash double quotes DO interpolate, so
|
|
56
60
|
*
|
|
57
61
|
* mapfile -t lines
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAolBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAiyBhD;CACF;
|
|
1
|
+
{"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAolBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAiyBhD;CACF;AA6rDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6FnE"}
|
|
@@ -1970,6 +1970,9 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
1970
1970
|
existing.push(call);
|
|
1971
1971
|
callsByLine.set(call.location.line, existing);
|
|
1972
1972
|
}
|
|
1973
|
+
const javaDerivedVars = typeof code === 'string'
|
|
1974
|
+
? buildJavaTaintedVars(code, new Set(sources.map(s => s.variable).filter((v) => Boolean(v))))
|
|
1975
|
+
: undefined;
|
|
1973
1976
|
for (const sink of sinks) {
|
|
1974
1977
|
if (unreachableLines.has(sink.line))
|
|
1975
1978
|
continue;
|
|
@@ -2010,7 +2013,7 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2010
2013
|
// primary; method-scope is the tiebreaker; sources[0] is the
|
|
2011
2014
|
// last-resort fallback to preserve existing behaviour when no
|
|
2012
2015
|
// better source is available.
|
|
2013
|
-
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, varName);
|
|
2016
|
+
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, varName, code, 'java', true, javaDerivedVars);
|
|
2014
2017
|
if (source) {
|
|
2015
2018
|
// cognium-dev #101 (Sprint 14 Phase E): when the picked source
|
|
2016
2019
|
// has a binding variable that differs from the sink arg's
|
|
@@ -2073,7 +2076,7 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2073
2076
|
continue;
|
|
2074
2077
|
{
|
|
2075
2078
|
// Sprint 13 #70 — same method-scoped picker as above.
|
|
2076
|
-
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, collectionVar);
|
|
2079
|
+
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, collectionVar, code, 'java', false, javaDerivedVars);
|
|
2077
2080
|
if (source) {
|
|
2078
2081
|
// cognium-dev #101 (Sprint 14 Phase E): cross-method
|
|
2079
2082
|
// bleed guard. See the analogous guard in the
|
|
@@ -3031,7 +3034,7 @@ function pythonSiblingBranchAssignsNonLiteral(lines, idx, variable, strLit, unre
|
|
|
3031
3034
|
* literal text before identifier tokenisation is sound (cognium-dev#353).
|
|
3032
3035
|
* See `maskStringLiteralsForTokenScan` for why the others are excluded.
|
|
3033
3036
|
*/
|
|
3034
|
-
const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript']);
|
|
3037
|
+
const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript', 'java']);
|
|
3035
3038
|
/**
|
|
3036
3039
|
* Blank the *text* of string literals in a sink-argument expression before it
|
|
3037
3040
|
* is tokenised into identifiers, while preserving interpolated expressions.
|
|
@@ -3061,9 +3064,13 @@ const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript']
|
|
|
3061
3064
|
* Interpolation bodies are masked recursively, so a quoted subscript inside
|
|
3062
3065
|
* one (`f"{d['actor']}"`) does not smuggle the literal back in.
|
|
3063
3066
|
*
|
|
3064
|
-
* LANGUAGE SCOPE — this is applied to Python
|
|
3065
|
-
* gates it (`MASKABLE_STRING_LANGUAGES`). In those
|
|
3066
|
-
*
|
|
3067
|
+
* LANGUAGE SCOPE — this is applied to Python, JS/TS and Java, and the caller
|
|
3068
|
+
* gates it (`MASKABLE_STRING_LANGUAGES`). In those, a plain quoted string
|
|
3069
|
+
* cannot interpolate, so blanking its text is sound. Java was added for
|
|
3070
|
+
* cognium-dev#915: `write("Parameter value: " + bar)` tokenised `value` and
|
|
3071
|
+
* linked an unrelated tainted loop local of that name to the sink (OWASP
|
|
3072
|
+
* BenchmarkTest01439). Java `"…"`, text blocks and char literals never
|
|
3073
|
+
* interpolate. Elsewhere it is
|
|
3067
3074
|
* not, and the suite proved it: Bash double quotes DO interpolate, so
|
|
3068
3075
|
*
|
|
3069
3076
|
* mapfile -t lines
|
|
@@ -3205,6 +3212,80 @@ function argsReferenceTaintedVar(expr, sources) {
|
|
|
3205
3212
|
.replace(/\/\/[^\n]*/g, ' ');
|
|
3206
3213
|
return sources.some(s => new RegExp(`(?<![\\p{L}\\p{N}_])${s.variable.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\p{L}\\p{N}_])`, 'u').test(codePart));
|
|
3207
3214
|
}
|
|
3215
|
+
/** Index of the `)` that closes the `(` at `openParenIndex`, or -1. Respects strings. */
|
|
3216
|
+
function matchingCloseParen(lineText, openParenIndex) {
|
|
3217
|
+
let depth = 0;
|
|
3218
|
+
let inStr = null;
|
|
3219
|
+
let esc = false;
|
|
3220
|
+
for (let i = openParenIndex; i < lineText.length; i++) {
|
|
3221
|
+
const ch = lineText[i];
|
|
3222
|
+
if (inStr) {
|
|
3223
|
+
if (esc) {
|
|
3224
|
+
esc = false;
|
|
3225
|
+
continue;
|
|
3226
|
+
}
|
|
3227
|
+
if (ch === '\\' && (inStr === '"' || inStr === '\'')) {
|
|
3228
|
+
esc = true;
|
|
3229
|
+
continue;
|
|
3230
|
+
}
|
|
3231
|
+
if (ch === inStr)
|
|
3232
|
+
inStr = null;
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
if (ch === '"' || ch === '\'' || ch === '`') {
|
|
3236
|
+
inStr = ch;
|
|
3237
|
+
continue;
|
|
3238
|
+
}
|
|
3239
|
+
if (ch === '(')
|
|
3240
|
+
depth++;
|
|
3241
|
+
else if (ch === ')') {
|
|
3242
|
+
depth--;
|
|
3243
|
+
if (depth === 0)
|
|
3244
|
+
return i;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
return -1;
|
|
3248
|
+
}
|
|
3249
|
+
/**
|
|
3250
|
+
* cognium-dev#1156 — `io_input` at `*.parse(...)` has no `method` tag; `location` is
|
|
3251
|
+
* like `parser.parse() in m`. When `path_traversal` (`readFileSync`, …) appears only
|
|
3252
|
+
* inside that `.parse(` argument list on the same line, inline colocation must not
|
|
3253
|
+
* pair them — the nested sink runs before the parse returns.
|
|
3254
|
+
*/
|
|
3255
|
+
function sinkNestedInJsTsParseArgs(lineText, sinkMethod) {
|
|
3256
|
+
if (!lineText || !sinkMethod?.length)
|
|
3257
|
+
return false;
|
|
3258
|
+
const needle = `${sinkMethod}(`;
|
|
3259
|
+
let i = 0;
|
|
3260
|
+
while (i < lineText.length) {
|
|
3261
|
+
const k = lineText.indexOf('parse', i);
|
|
3262
|
+
if (k === -1)
|
|
3263
|
+
return false;
|
|
3264
|
+
if (k > 0 && /[\w$]/.test(lineText[k - 1])) {
|
|
3265
|
+
i = k + 5;
|
|
3266
|
+
continue;
|
|
3267
|
+
}
|
|
3268
|
+
if (lineText.slice(k, k + 5) !== 'parse') {
|
|
3269
|
+
i = k + 1;
|
|
3270
|
+
continue;
|
|
3271
|
+
}
|
|
3272
|
+
const openParen = k + 5;
|
|
3273
|
+
if (lineText[openParen] !== '(') {
|
|
3274
|
+
i = k + 5;
|
|
3275
|
+
continue;
|
|
3276
|
+
}
|
|
3277
|
+
const closeIdx = matchingCloseParen(lineText, openParen);
|
|
3278
|
+
if (closeIdx === -1) {
|
|
3279
|
+
i = k + 5;
|
|
3280
|
+
continue;
|
|
3281
|
+
}
|
|
3282
|
+
const argSpan = lineText.slice(openParen + 1, closeIdx);
|
|
3283
|
+
if (argSpan.includes(needle))
|
|
3284
|
+
return true;
|
|
3285
|
+
i = closeIdx + 1;
|
|
3286
|
+
}
|
|
3287
|
+
return false;
|
|
3288
|
+
}
|
|
3208
3289
|
function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachableLines, tainted, code, language, types) {
|
|
3209
3290
|
const flows = [];
|
|
3210
3291
|
// #472 — Go function ranges for the same-function gate below. Returns the
|
|
@@ -3823,12 +3904,22 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
3823
3904
|
});
|
|
3824
3905
|
}
|
|
3825
3906
|
else {
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3907
|
+
// cognium-dev #914 S6 — a derived local assigned before an unrelated
|
|
3908
|
+
// env_input (e.g. `bar = helper(param)` then `osName = getProperty`)
|
|
3909
|
+
// must not inherit osName's env_input tag for expression-scan pairing
|
|
3910
|
+
// (OWASP BenchmarkTest01791: `cmd + bar` at exec mis-attributed to
|
|
3911
|
+
// System.getProperty on a later line).
|
|
3912
|
+
const unrelatedEnvAnchor = scopedAnchor.type === 'env_input' &&
|
|
3913
|
+
scopedAnchor.variable !== varName &&
|
|
3914
|
+
derivedLine < scopedAnchor.line;
|
|
3915
|
+
if (!unrelatedEnvAnchor) {
|
|
3916
|
+
sourcesWithVar.push({
|
|
3917
|
+
...scopedAnchor,
|
|
3918
|
+
variable: varName,
|
|
3919
|
+
literal_kill_line: derivedLine,
|
|
3920
|
+
...(owner ? { in_method: owner } : {}),
|
|
3921
|
+
});
|
|
3922
|
+
}
|
|
3832
3923
|
}
|
|
3833
3924
|
existingVars.add(varName);
|
|
3834
3925
|
}
|
|
@@ -4540,6 +4631,16 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4540
4631
|
// JSDoc for the per-sink policy).
|
|
4541
4632
|
if (!sourceSemanticsAllowed(source, sink.type))
|
|
4542
4633
|
continue;
|
|
4634
|
+
// cognium-dev#1156 — sink nested only inside `.parse(` args (same line).
|
|
4635
|
+
const colocLineText = sink.code ?? '';
|
|
4636
|
+
if (colocLineText &&
|
|
4637
|
+
(language === 'javascript' || language === 'typescript') &&
|
|
4638
|
+
source.type === 'io_input' &&
|
|
4639
|
+
typeof source.location === 'string' &&
|
|
4640
|
+
source.location.includes('.parse()') &&
|
|
4641
|
+
sinkNestedInJsTsParseArgs(colocLineText, sink.method)) {
|
|
4642
|
+
continue;
|
|
4643
|
+
}
|
|
4543
4644
|
// Variable-scan handoff — if the source carries an LHS-bound
|
|
4544
4645
|
// variable AND that identifier is textually present in the RHS of
|
|
4545
4646
|
// the sink's own source-line code, the variable-scan path is
|
|
@@ -4599,6 +4700,18 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4599
4700
|
source.location.includes(`${sink.method}(`)) {
|
|
4600
4701
|
continue;
|
|
4601
4702
|
}
|
|
4703
|
+
// cognium-dev #914 — OWASP `Runtime.exec(args, env, new File(System.getProperty(...)))`:
|
|
4704
|
+
// the working-directory argument is not shell command input; inline colocation
|
|
4705
|
+
// would otherwise pair `env_input` getProperty with `command_injection` exec.
|
|
4706
|
+
if (source.type === 'env_input' &&
|
|
4707
|
+
sink.type === 'command_injection' &&
|
|
4708
|
+
sink.method === 'exec' &&
|
|
4709
|
+
/System\s*\.\s*getProperty\s*\(/.test(source.location ?? '')) {
|
|
4710
|
+
const sinkCode = sink.code ?? '';
|
|
4711
|
+
if (/new\s+(?:java\.io\.)?File\s*\(\s*System\s*\.\s*getProperty\s*\(/.test(sinkCode)) {
|
|
4712
|
+
continue;
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4602
4715
|
if (flows.some(f => f.source_line === source.line &&
|
|
4603
4716
|
f.sink_line === sink.line &&
|
|
4604
4717
|
f.sink_type === sink.type))
|
|
@@ -4639,7 +4752,9 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4639
4752
|
// 4. Last resort: `sources[0]` (preserves pre-fix behaviour when nothing
|
|
4640
4753
|
// preceding exists — keeps existing test coverage green).
|
|
4641
4754
|
// ---------------------------------------------------------------------------
|
|
4642
|
-
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar
|
|
4755
|
+
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar, code, language,
|
|
4756
|
+
/** When true (#914 S5), do not pair a sink arg with an unrelated preceding source. */
|
|
4757
|
+
strictUnrelatedSourceGuard = false, javaDerivedVars) {
|
|
4643
4758
|
if (sources.length === 0)
|
|
4644
4759
|
return undefined;
|
|
4645
4760
|
// Closest-preceding selector over a candidate list. Strict-preceding
|
|
@@ -4656,6 +4771,40 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4656
4771
|
}
|
|
4657
4772
|
return best;
|
|
4658
4773
|
};
|
|
4774
|
+
const methodAt = (line) => {
|
|
4775
|
+
if (!types)
|
|
4776
|
+
return null;
|
|
4777
|
+
for (const t of types) {
|
|
4778
|
+
for (const m of t.methods) {
|
|
4779
|
+
if (line >= m.start_line && line <= m.end_line)
|
|
4780
|
+
return m.name;
|
|
4781
|
+
}
|
|
4782
|
+
}
|
|
4783
|
+
return null;
|
|
4784
|
+
};
|
|
4785
|
+
// cognium-dev#515 — derived locals must credit the RHS read, not an earlier
|
|
4786
|
+
// decoy source in the same method (alias entries can still carry a stale anchor).
|
|
4787
|
+
if (taintedVar &&
|
|
4788
|
+
strictUnrelatedSourceGuard &&
|
|
4789
|
+
typeof code === 'string' &&
|
|
4790
|
+
(language === 'java' || language === 'csharp') &&
|
|
4791
|
+
javaDerivedVars?.has(taintedVar)) {
|
|
4792
|
+
const owner = methodName ?? methodAt(sinkLine);
|
|
4793
|
+
const realSourceByVar = new Map();
|
|
4794
|
+
for (const s of sources) {
|
|
4795
|
+
if (!s.variable)
|
|
4796
|
+
continue;
|
|
4797
|
+
const sOwner = s.in_method ?? methodAt(s.line);
|
|
4798
|
+
if (owner && sOwner !== owner)
|
|
4799
|
+
continue;
|
|
4800
|
+
const prev = realSourceByVar.get(s.variable);
|
|
4801
|
+
if (!prev || s.line < prev.line)
|
|
4802
|
+
realSourceByVar.set(s.variable, s);
|
|
4803
|
+
}
|
|
4804
|
+
const referenced = resolveJavaDerivedAnchor(taintedVar, javaDerivedVars, realSourceByVar, code.split('\n'), new Set());
|
|
4805
|
+
if (referenced && referenced.line < sinkLine)
|
|
4806
|
+
return referenced;
|
|
4807
|
+
}
|
|
4659
4808
|
// 1. Variable match (preferred — even across methods, falls within the
|
|
4660
4809
|
// method scope check below for the tiebreak).
|
|
4661
4810
|
if (taintedVar) {
|
|
@@ -4664,6 +4813,16 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4664
4813
|
if (pick)
|
|
4665
4814
|
return pick;
|
|
4666
4815
|
}
|
|
4816
|
+
// When the sink arg is a named tainted var, do not attribute it to an unrelated
|
|
4817
|
+
// source (cognium-dev #914 — OWASP BenchmarkTest01791: `bar` at exec paired with
|
|
4818
|
+
// `osName` from System.getProperty because it was the closest preceding source in doPost).
|
|
4819
|
+
// Collection/array flows pass a container name (e.g. `m`) that will not match any
|
|
4820
|
+
// source.variable — they keep the scoped / last-resort fallback (strict guard off).
|
|
4821
|
+
// Loop/`StringBuilder` locals often have no stamped source; only apply the guard when
|
|
4822
|
+
// at least one source carries this variable name on a line before the sink.
|
|
4823
|
+
const hasPrecedingNamedSource = Boolean(taintedVar && sources.some(s => s.variable === taintedVar && s.line < sinkLine));
|
|
4824
|
+
const guardUnrelatedSources = strictUnrelatedSourceGuard && hasPrecedingNamedSource;
|
|
4825
|
+
const matchesTaintedVar = (s) => !guardUnrelatedSources || !taintedVar || s.variable === taintedVar;
|
|
4667
4826
|
// 2. Scope match — restrict to sources whose line is inside the same
|
|
4668
4827
|
// method as the sink.
|
|
4669
4828
|
if (methodName && types && types.length > 0) {
|
|
@@ -4681,18 +4840,20 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4681
4840
|
break;
|
|
4682
4841
|
}
|
|
4683
4842
|
if (methodStart > 0 && methodEnd >= methodStart) {
|
|
4684
|
-
const inScope = sources.filter(s => s.line >= methodStart && s.line <= methodEnd);
|
|
4843
|
+
const inScope = sources.filter(s => s.line >= methodStart && s.line <= methodEnd && matchesTaintedVar(s));
|
|
4685
4844
|
const pick = closestPreceding(inScope);
|
|
4686
4845
|
if (pick)
|
|
4687
4846
|
return pick;
|
|
4688
4847
|
}
|
|
4689
4848
|
}
|
|
4690
4849
|
// 3. Closest preceding source globally.
|
|
4691
|
-
const globalPick = closestPreceding(sources);
|
|
4850
|
+
const globalPick = closestPreceding(sources.filter(matchesTaintedVar));
|
|
4692
4851
|
if (globalPick)
|
|
4693
4852
|
return globalPick;
|
|
4694
4853
|
// 4. Last resort — preserve historical behaviour when there's nothing
|
|
4695
4854
|
// preceding the sink (e.g. synthetic same-line sources).
|
|
4855
|
+
if (guardUnrelatedSources && taintedVar)
|
|
4856
|
+
return undefined;
|
|
4696
4857
|
return sources[0];
|
|
4697
4858
|
}
|
|
4698
4859
|
//# sourceMappingURL=taint-propagation-pass.js.map
|