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.
- 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 +27 -3
- 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 +8 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +47 -2
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +422 -57
- 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/findings.d.ts.map +1 -1
- package/dist/analysis/findings.js +7 -5
- package/dist/analysis/findings.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts +16 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +545 -197
- package/dist/analysis/interprocedural.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/csrf-samesite-none-session-pass.d.ts +58 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
- 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 +220 -7
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +549 -22
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-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/scan-secrets-pass.js +2 -2
- package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
- package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +564 -22
- 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 +464 -27
- 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/project-callee-escape-gate.js +1 -1
- package/dist/analysis/project-callee-escape-gate.js.map +1 -1
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +15 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +92 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +390 -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 +124 -19
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analysis/taint-propagation.d.ts +1 -0
- package/dist/analysis/taint-propagation.d.ts.map +1 -1
- package/dist/analysis/taint-propagation.js +32 -0
- package/dist/analysis/taint-propagation.js.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
- package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
- package/dist/analysis/test-to-production-taint-gate.js +30 -0
- package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
- package/dist/analyzer.d.ts +21 -3
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +83 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +8118 -2526
- package/dist/core/circle-ir-core.cjs +3098 -2280
- package/dist/core/circle-ir-core.js +3036 -2214
- package/dist/core/extractors/calls.d.ts +10 -1
- package/dist/core/extractors/calls.d.ts.map +1 -1
- package/dist/core/extractors/calls.js +148 -6
- package/dist/core/extractors/calls.js.map +1 -1
- package/dist/core/extractors/cfg.d.ts.map +1 -1
- package/dist/core/extractors/cfg.js +12 -0
- package/dist/core/extractors/cfg.js.map +1 -1
- package/dist/core/extractors/dfg.d.ts.map +1 -1
- package/dist/core/extractors/dfg.js +151 -18
- package/dist/core/extractors/dfg.js.map +1 -1
- 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/core/extractors/types.d.ts +5 -0
- package/dist/core/extractors/types.d.ts.map +1 -1
- package/dist/core/extractors/types.js +149 -4
- package/dist/core/extractors/types.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +3 -1
- package/dist/core/parser.js.map +1 -1
- package/dist/core/ts-grammar-workarounds.d.ts +18 -0
- package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
- package/dist/core/ts-grammar-workarounds.js +40 -0
- package/dist/core/ts-grammar-workarounds.js.map +1 -0
- 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 +68 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +379 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +22 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +15 -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/t6.d.ts +84 -0
- package/dist/facts/t6.d.ts.map +1 -0
- package/dist/facts/t6.js +226 -0
- package/dist/facts/t6.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 +4 -3
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/index.d.ts +1 -1
- package/dist/graph-facts/index.d.ts.map +1 -1
- package/dist/graph-facts/index.js +1 -1
- package/dist/graph-facts/index.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +53 -8
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +172 -16
- 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 +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +47 -2
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +395 -18
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/java-registrations.d.ts +93 -0
- package/dist/navigation/java-registrations.d.ts.map +1 -0
- package/dist/navigation/java-registrations.js +254 -0
- package/dist/navigation/java-registrations.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +74 -3
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +206 -11
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +15 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/navigation/ts-entry-tables.d.ts +1 -1
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
- package/dist/navigation/ts-entry-tables.js.map +1 -1
- package/dist/navigation/xml-scan.d.ts +40 -0
- package/dist/navigation/xml-scan.d.ts.map +1 -0
- package/dist/navigation/xml-scan.js +269 -0
- package/dist/navigation/xml-scan.js.map +1 -0
- 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 +6 -5
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +19 -6
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +61 -7
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +134 -21
- 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 +55 -3
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/dist/stable-ids/typescript.d.ts +5 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -1
- package/dist/stable-ids/typescript.js +41 -8
- package/dist/stable-ids/typescript.js.map +1 -1
- package/dist/types/index.d.ts +21 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/docs/SPEC.md +9 -0
- package/package.json +9 -5
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { findJavaSpringReturnXSSSinks } from './language-sources-pass.js';
|
|
14
14
|
import { expressionFullyWrappedBySanitizer, identifierOutsideSanitizerCalls, identifierOutsideSanitizerCallsInText, propagateTaint } from '../taint-propagation.js';
|
|
15
15
|
import { isFalsePositive, isCorrelatedPredicateFP, constPropScopedVar } from '../constant-propagation.js';
|
|
16
|
-
import { buildJavaTaintedVars, buildPythonTaintedVars, buildRustTaintedVars, findPythonTrustBoundaryViolations, findPythonReturnXSSSinks, findJavaWikiPluginReturnXSSSinks } from './language-sources-pass.js';
|
|
16
|
+
import { buildJavaTaintedVars, buildJavaScriptTaintedVars, buildPythonTaintedVars, buildRustTaintedVars, findPythonTrustBoundaryViolations, findPythonReturnXSSSinks, findJavaWikiPluginReturnXSSSinks } from './language-sources-pass.js';
|
|
17
17
|
import { parseJavaArrayAccessExpression } from '../java-array-element-keys.js';
|
|
18
18
|
import { canSourceReachSink, sourceSemanticsAllowed } from '../findings.js';
|
|
19
19
|
import { walkBackwardDefs } from '../dfg-walk.js';
|
|
@@ -506,6 +506,15 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
|
|
|
506
506
|
return use ? graph.defById.get(use.def_id) : undefined;
|
|
507
507
|
};
|
|
508
508
|
return (step, sourceLine, sinkLine, sinkType) => {
|
|
509
|
+
// cognium-dev#1198 — heap-field stamped sources are not in constProp.tainted.
|
|
510
|
+
if (step.variable.includes('.') &&
|
|
511
|
+
sources.some((s) => s.variable === step.variable &&
|
|
512
|
+
s.line >= sourceLine &&
|
|
513
|
+
s.line <= sinkLine &&
|
|
514
|
+
typeof s.location === 'string' &&
|
|
515
|
+
s.location.includes('heap field read'))) {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
509
518
|
const method = methodAtLine(graph, step.line);
|
|
510
519
|
const blockLine = defLineForUse(graph, step.variable, step.line);
|
|
511
520
|
const fpLookup = constPropFlowLookup(language, method, step.variable, blockLine, constProp);
|
|
@@ -919,7 +928,7 @@ export class TaintPropagationPass {
|
|
|
919
928
|
pushIfNew(f);
|
|
920
929
|
}
|
|
921
930
|
// Supplement: collection/iterator flows — with FP filtering
|
|
922
|
-
const collectionFlows = detectCollectionFlows(calls, sources, sinks, constProp, ctx.code, types, graph) ?? [];
|
|
931
|
+
const collectionFlows = detectCollectionFlows(calls, sources, sinks, constProp, ctx.code, types, graph, ctx.language) ?? [];
|
|
923
932
|
for (const f of collectionFlows) {
|
|
924
933
|
if (flowKeys.has(flowKey(f)))
|
|
925
934
|
continue;
|
|
@@ -1329,6 +1338,25 @@ export class TaintPropagationPass {
|
|
|
1329
1338
|
return false;
|
|
1330
1339
|
});
|
|
1331
1340
|
}
|
|
1341
|
+
// cognium-dev #1152 / #1247 — Java `new Cookie(…, value)` trust_boundary only
|
|
1342
|
+
// when `value` is HTTP-sourced in the same method. Method parameters such as
|
|
1343
|
+
// `InsecureCookieTp.set(..., String sid)` are not CWE-501 session-trust writes.
|
|
1344
|
+
const javaCookieTrustSinkLines = new Set();
|
|
1345
|
+
for (const s of sinks) {
|
|
1346
|
+
if (s.type === 'trust_boundary' &&
|
|
1347
|
+
(s.method === 'Cookie' || s.method === 'setValue')) {
|
|
1348
|
+
javaCookieTrustSinkLines.add(s.line);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (javaCookieTrustSinkLines.size > 0) {
|
|
1352
|
+
finalFlows = finalFlows.filter(f => {
|
|
1353
|
+
if (f.sink_type !== 'trust_boundary')
|
|
1354
|
+
return true;
|
|
1355
|
+
if (!javaCookieTrustSinkLines.has(f.sink_line))
|
|
1356
|
+
return true;
|
|
1357
|
+
return typeof f.source_type === 'string' && f.source_type.startsWith('http_');
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1332
1360
|
// cognium-dev #49 — final dedup on (source_line, sink_line, sink_type).
|
|
1333
1361
|
// The DFG propagator and the four supplementary detectors each emit
|
|
1334
1362
|
// independently; merge-time dedup at the supplement seams is partial
|
|
@@ -1411,6 +1439,21 @@ export class TaintPropagationPass {
|
|
|
1411
1439
|
return true;
|
|
1412
1440
|
});
|
|
1413
1441
|
}
|
|
1442
|
+
// cognium-dev #1156: `parser.parse(fs.readFileSync(abs))`. When every sink
|
|
1443
|
+
// of the flow's type on the line is a call nested inside the arguments of a
|
|
1444
|
+
// source call of the flow's source type, the sink runs first and the
|
|
1445
|
+
// source's result never reaches it. Applied to the flows of every emitter;
|
|
1446
|
+
// JavaScript and TypeScript only for now.
|
|
1447
|
+
if (ctx.language === 'javascript' || ctx.language === 'typescript')
|
|
1448
|
+
finalFlows = finalFlows.filter(f => {
|
|
1449
|
+
if (f.source_line !== f.sink_line)
|
|
1450
|
+
return true;
|
|
1451
|
+
const lineSinks = sinks.filter(k => k.line === f.sink_line && k.type === f.sink_type);
|
|
1452
|
+
const lineSources = sources.filter(x => x.line === f.source_line && x.type === f.source_type);
|
|
1453
|
+
if (lineSinks.length === 0 || lineSources.length === 0)
|
|
1454
|
+
return true;
|
|
1455
|
+
return !lineSinks.every(k => lineSources.some(x => sinkNestedInSourceCall(x, k)));
|
|
1456
|
+
});
|
|
1414
1457
|
return { flows: finalFlows };
|
|
1415
1458
|
}
|
|
1416
1459
|
}
|
|
@@ -1506,7 +1549,7 @@ function isMongoValueBoundFilter(sinkCode, sinkMethod, sourceVar) {
|
|
|
1506
1549
|
if (!body)
|
|
1507
1550
|
return false;
|
|
1508
1551
|
// Strip string literals so `$` inside string values doesn't false-trip.
|
|
1509
|
-
const stripped = body.replace(/(['"`])(?:\\.|(?!\1)
|
|
1552
|
+
const stripped = body.replace(/(['"`])(?:\\.|(?!\1)[^\\\n\r\u2028\u2029])*\1/g, '""');
|
|
1510
1553
|
// Spread / rest disqualifies (opaque subset).
|
|
1511
1554
|
if (/\.\.\./.test(stripped))
|
|
1512
1555
|
return false;
|
|
@@ -1752,13 +1795,16 @@ function detectJsModuleScopeFlows(code, sources, sinks, unreachableLines) {
|
|
|
1752
1795
|
return flows;
|
|
1753
1796
|
const lines = code.split('\n');
|
|
1754
1797
|
const moduleVars = new Set();
|
|
1798
|
+
const moduleDeclRe = /(?:^|;)\s*(?:export\s+)?(?:let|var|const)\s+([A-Za-z_$][\w$]*)\b/g;
|
|
1755
1799
|
for (const line of lines) {
|
|
1756
1800
|
const stripped = line.replace(/\s+$/, '');
|
|
1757
1801
|
if (!stripped || /^[ \t]/.test(line))
|
|
1758
1802
|
continue;
|
|
1759
|
-
|
|
1760
|
-
|
|
1803
|
+
let m;
|
|
1804
|
+
moduleDeclRe.lastIndex = 0;
|
|
1805
|
+
while ((m = moduleDeclRe.exec(stripped)) !== null) {
|
|
1761
1806
|
moduleVars.add(m[1]);
|
|
1807
|
+
}
|
|
1762
1808
|
}
|
|
1763
1809
|
if (moduleVars.size === 0)
|
|
1764
1810
|
return flows;
|
|
@@ -1956,7 +2002,7 @@ function isMapLiteralKeyTainted(constProp, mapName, key, inMethod) {
|
|
|
1956
2002
|
return false;
|
|
1957
2003
|
return keys.has(key) || keys.has('*');
|
|
1958
2004
|
}
|
|
1959
|
-
function detectCollectionFlows(calls, sources, sinks, constProp, code, types, graph) {
|
|
2005
|
+
function detectCollectionFlows(calls, sources, sinks, constProp, code, types, graph, language) {
|
|
1960
2006
|
const taintedVars = constProp.tainted;
|
|
1961
2007
|
const unreachableLines = constProp.unreachableLines;
|
|
1962
2008
|
const flows = [];
|
|
@@ -1970,6 +2016,20 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
1970
2016
|
existing.push(call);
|
|
1971
2017
|
callsByLine.set(call.location.line, existing);
|
|
1972
2018
|
}
|
|
2019
|
+
const javaDerivedVars = language === 'java' && typeof code === 'string'
|
|
2020
|
+
? buildJavaTaintedVars(code, new Set(sources.map(s => s.variable).filter((v) => Boolean(v))))
|
|
2021
|
+
: undefined;
|
|
2022
|
+
// Stamp qualified sources (#1198 heap-field reads) — seeds are not
|
|
2023
|
+
// present in the derived-only map returned by `buildJavaTaintedVars`.
|
|
2024
|
+
if (javaDerivedVars) {
|
|
2025
|
+
for (const s of sources) {
|
|
2026
|
+
if (s.variable?.includes('.') &&
|
|
2027
|
+
typeof s.location === 'string' &&
|
|
2028
|
+
s.location.includes('heap field read')) {
|
|
2029
|
+
javaDerivedVars.set(s.variable, s.line);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
1973
2033
|
for (const sink of sinks) {
|
|
1974
2034
|
if (unreachableLines.has(sink.line))
|
|
1975
2035
|
continue;
|
|
@@ -1982,9 +2042,22 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
1982
2042
|
continue;
|
|
1983
2043
|
}
|
|
1984
2044
|
if (arg.variable) {
|
|
1985
|
-
const
|
|
2045
|
+
const expr = arg.expression ?? '';
|
|
2046
|
+
let varName = arg.variable;
|
|
2047
|
+
// cognium-dev#1198 — Tree-sitter sink args carry the innermost
|
|
2048
|
+
// identifier (`value` in `next.value`); `buildJavaTaintedVars` keys
|
|
2049
|
+
// the qualified field path instead.
|
|
2050
|
+
if (language === 'java' &&
|
|
2051
|
+
expr.includes('.') &&
|
|
2052
|
+
!expr.startsWith('this.') &&
|
|
2053
|
+
(javaDerivedVars?.has(expr) ||
|
|
2054
|
+
sources.some((s) => s.variable === expr &&
|
|
2055
|
+
typeof s.location === 'string' &&
|
|
2056
|
+
s.location.includes('heap field read')))) {
|
|
2057
|
+
varName = expr;
|
|
2058
|
+
}
|
|
1986
2059
|
let scopedName = varName;
|
|
1987
|
-
if (call.in_method) {
|
|
2060
|
+
if (call.in_method && !varName.includes('.')) {
|
|
1988
2061
|
const blockLine = graph
|
|
1989
2062
|
? defLineForUse(graph, varName, call.location.line)
|
|
1990
2063
|
: call.location.line;
|
|
@@ -1993,7 +2066,6 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
1993
2066
|
// Bare `name` that is a field read (no local of that name in this
|
|
1994
2067
|
// method) still counts as a field use — Inter4-style. A shadowing
|
|
1995
2068
|
// local declaration in the method does not.
|
|
1996
|
-
const expr = arg.expression ?? '';
|
|
1997
2069
|
const explicitField = isFieldUseExpression(expr, varName, enclosingTypeNamesAt(types, call.location.line));
|
|
1998
2070
|
const bareFieldRead = fieldNames.has(varName)
|
|
1999
2071
|
&& expr === varName
|
|
@@ -2001,6 +2073,14 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2001
2073
|
const isFieldUse = explicitField || bareFieldRead;
|
|
2002
2074
|
const mapKeyRead = mapGetLiteralKeyFromExpr(expr);
|
|
2003
2075
|
let argTainted = isTaintedInMethod(taintedVars, varName, scopedName, fieldNames, isFieldUse);
|
|
2076
|
+
if (language === 'java' &&
|
|
2077
|
+
!argTainted &&
|
|
2078
|
+
javaDerivedVars?.has(varName) &&
|
|
2079
|
+
sources.some((s) => s.variable === varName &&
|
|
2080
|
+
typeof s.location === 'string' &&
|
|
2081
|
+
s.location.includes('heap field read'))) {
|
|
2082
|
+
argTainted = true;
|
|
2083
|
+
}
|
|
2004
2084
|
if (mapKeyRead && mapKeyRead.map === varName) {
|
|
2005
2085
|
argTainted = isMapLiteralKeyTainted(constProp, varName, mapKeyRead.key, call.in_method);
|
|
2006
2086
|
}
|
|
@@ -2010,7 +2090,7 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2010
2090
|
// primary; method-scope is the tiebreaker; sources[0] is the
|
|
2011
2091
|
// last-resort fallback to preserve existing behaviour when no
|
|
2012
2092
|
// better source is available.
|
|
2013
|
-
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, varName);
|
|
2093
|
+
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, varName, code, 'java', true, javaDerivedVars);
|
|
2014
2094
|
if (source) {
|
|
2015
2095
|
// cognium-dev #101 (Sprint 14 Phase E): when the picked source
|
|
2016
2096
|
// has a binding variable that differs from the sink arg's
|
|
@@ -2073,7 +2153,7 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2073
2153
|
continue;
|
|
2074
2154
|
{
|
|
2075
2155
|
// Sprint 13 #70 — same method-scoped picker as above.
|
|
2076
|
-
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, collectionVar);
|
|
2156
|
+
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, collectionVar, code, 'java', false, javaDerivedVars);
|
|
2077
2157
|
if (source) {
|
|
2078
2158
|
// cognium-dev #101 (Sprint 14 Phase E): cross-method
|
|
2079
2159
|
// bleed guard. See the analogous guard in the
|
|
@@ -2110,6 +2190,16 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
2110
2190
|
}
|
|
2111
2191
|
return flows;
|
|
2112
2192
|
}
|
|
2193
|
+
/** cognium-dev#476 — `array[n-n]` in SecuriBench stores index as `0` but sink arg is `n-n`. */
|
|
2194
|
+
function normalizeJavaArrayIndexKey(indexKey) {
|
|
2195
|
+
const trimmed = indexKey.trim();
|
|
2196
|
+
if (/^\d+$/.test(trimmed))
|
|
2197
|
+
return trimmed;
|
|
2198
|
+
const sameVarDiff = trimmed.match(/^([A-Za-z_]\w*)\s*-\s*\1$/);
|
|
2199
|
+
if (sameVarDiff)
|
|
2200
|
+
return '0';
|
|
2201
|
+
return trimmed;
|
|
2202
|
+
}
|
|
2113
2203
|
function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, unreachableLines, types) {
|
|
2114
2204
|
const flows = [];
|
|
2115
2205
|
const callsByLine = new Map();
|
|
@@ -2132,9 +2222,12 @@ function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, un
|
|
|
2132
2222
|
const arrayAccess = parseJavaArrayAccessExpression(arg.expression);
|
|
2133
2223
|
if (arrayAccess) {
|
|
2134
2224
|
const { base, arrayName, indexKey, displayVar } = arrayAccess;
|
|
2225
|
+
const resolvedIndex = normalizeJavaArrayIndexKey(indexKey);
|
|
2135
2226
|
const taintedIndices = taintedArrayElements.get(arrayName);
|
|
2136
2227
|
if (taintedIndices) {
|
|
2137
|
-
const isTainted = taintedIndices.has(
|
|
2228
|
+
const isTainted = taintedIndices.has(resolvedIndex) ||
|
|
2229
|
+
taintedIndices.has(indexKey) ||
|
|
2230
|
+
taintedIndices.has('*');
|
|
2138
2231
|
if (isTainted) {
|
|
2139
2232
|
// Sprint 13 #70 — method-scoped source picker (see detectCollectionFlows).
|
|
2140
2233
|
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, base);
|
|
@@ -2193,7 +2286,7 @@ function shouldGateCSharpPatPermsLibraryParamFlow(flow, sources, sinks, types, c
|
|
|
2193
2286
|
}
|
|
2194
2287
|
/** Parameter names referenced as identifiers inside a compound sink argument (#685). */
|
|
2195
2288
|
function compoundArgParamNames(expression, paramNames) {
|
|
2196
|
-
const stripped = expression.replace(/(['"`])(?:\\.|(?!\1)
|
|
2289
|
+
const stripped = expression.replace(/(['"`])(?:\\.|(?!\1)[^\\\n\r\u2028\u2029])*\1/g, (m) => ' '.repeat(m.length));
|
|
2197
2290
|
const matched = [];
|
|
2198
2291
|
for (const raw of paramNames) {
|
|
2199
2292
|
const name = raw.startsWith('*') ? raw.slice(1) : raw;
|
|
@@ -3031,7 +3124,7 @@ function pythonSiblingBranchAssignsNonLiteral(lines, idx, variable, strLit, unre
|
|
|
3031
3124
|
* literal text before identifier tokenisation is sound (cognium-dev#353).
|
|
3032
3125
|
* See `maskStringLiteralsForTokenScan` for why the others are excluded.
|
|
3033
3126
|
*/
|
|
3034
|
-
const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript']);
|
|
3127
|
+
const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript', 'java']);
|
|
3035
3128
|
/**
|
|
3036
3129
|
* Blank the *text* of string literals in a sink-argument expression before it
|
|
3037
3130
|
* is tokenised into identifiers, while preserving interpolated expressions.
|
|
@@ -3061,9 +3154,13 @@ const MASKABLE_STRING_LANGUAGES = new Set(['python', 'javascript', 'typescript']
|
|
|
3061
3154
|
* Interpolation bodies are masked recursively, so a quoted subscript inside
|
|
3062
3155
|
* one (`f"{d['actor']}"`) does not smuggle the literal back in.
|
|
3063
3156
|
*
|
|
3064
|
-
* LANGUAGE SCOPE — this is applied to Python
|
|
3065
|
-
* gates it (`MASKABLE_STRING_LANGUAGES`). In those
|
|
3066
|
-
*
|
|
3157
|
+
* LANGUAGE SCOPE — this is applied to Python, JS/TS and Java, and the caller
|
|
3158
|
+
* gates it (`MASKABLE_STRING_LANGUAGES`). In those, a plain quoted string
|
|
3159
|
+
* cannot interpolate, so blanking its text is sound. Java was added for
|
|
3160
|
+
* cognium-dev#915: `write("Parameter value: " + bar)` tokenised `value` and
|
|
3161
|
+
* linked an unrelated tainted loop local of that name to the sink (OWASP
|
|
3162
|
+
* BenchmarkTest01439). Java `"…"`, text blocks and char literals never
|
|
3163
|
+
* interpolate. Elsewhere it is
|
|
3067
3164
|
* not, and the suite proved it: Bash double quotes DO interpolate, so
|
|
3068
3165
|
*
|
|
3069
3166
|
* mapfile -t lines
|
|
@@ -3205,6 +3302,139 @@ function argsReferenceTaintedVar(expr, sources) {
|
|
|
3205
3302
|
.replace(/\/\/[^\n]*/g, ' ');
|
|
3206
3303
|
return sources.some(s => new RegExp(`(?<![\\p{L}\\p{N}_])${s.variable.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\p{L}\\p{N}_])`, 'u').test(codePart));
|
|
3207
3304
|
}
|
|
3305
|
+
/** Index of the `)` that closes the `(` at `openParenIndex`, or -1. Respects strings. */
|
|
3306
|
+
function matchingCloseParen(lineText, openParenIndex) {
|
|
3307
|
+
let depth = 0;
|
|
3308
|
+
let inStr = null;
|
|
3309
|
+
let esc = false;
|
|
3310
|
+
for (let i = openParenIndex; i < lineText.length; i++) {
|
|
3311
|
+
const ch = lineText[i];
|
|
3312
|
+
if (inStr) {
|
|
3313
|
+
if (esc) {
|
|
3314
|
+
esc = false;
|
|
3315
|
+
continue;
|
|
3316
|
+
}
|
|
3317
|
+
if (ch === '\\' && (inStr === '"' || inStr === '\'')) {
|
|
3318
|
+
esc = true;
|
|
3319
|
+
continue;
|
|
3320
|
+
}
|
|
3321
|
+
if (ch === inStr)
|
|
3322
|
+
inStr = null;
|
|
3323
|
+
continue;
|
|
3324
|
+
}
|
|
3325
|
+
if (ch === '"' || ch === '\'' || ch === '`') {
|
|
3326
|
+
inStr = ch;
|
|
3327
|
+
continue;
|
|
3328
|
+
}
|
|
3329
|
+
if (ch === '(')
|
|
3330
|
+
depth++;
|
|
3331
|
+
else if (ch === ')') {
|
|
3332
|
+
depth--;
|
|
3333
|
+
if (depth === 0)
|
|
3334
|
+
return i;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
return -1;
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* cognium-dev#1223 — `req.query.url` contains the token `query`, which must not
|
|
3341
|
+
* pair with a tainted local named `query` in another function. True when every
|
|
3342
|
+
* occurrence of `ident` in `expr` is only as `(req|request|ctx).ident`.
|
|
3343
|
+
*/
|
|
3344
|
+
function jsBareIdentOnlyAsRequestProxy(expr, ident) {
|
|
3345
|
+
const escaped = ident.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3346
|
+
const re = new RegExp(`\\b${escaped}\\b`, 'gu');
|
|
3347
|
+
let hits = 0;
|
|
3348
|
+
let m;
|
|
3349
|
+
while ((m = re.exec(expr)) !== null) {
|
|
3350
|
+
hits++;
|
|
3351
|
+
const before = expr.slice(0, m.index);
|
|
3352
|
+
if (!/(?:\breq|\brequest|\bctx)\.\s*$/.test(before))
|
|
3353
|
+
return false;
|
|
3354
|
+
}
|
|
3355
|
+
return hits > 0;
|
|
3356
|
+
}
|
|
3357
|
+
/**
|
|
3358
|
+
* cognium-dev#1223 — when `types[].methods` is empty (common for
|
|
3359
|
+
* `module.exports.foo = function` handlers), derive function line ranges from
|
|
3360
|
+
* the source so the #472-style same-function gate still applies.
|
|
3361
|
+
*/
|
|
3362
|
+
function buildJsTsFunctionRangesFromSource(code) {
|
|
3363
|
+
const lines = code.split('\n');
|
|
3364
|
+
const ranges = [];
|
|
3365
|
+
const startPatterns = [
|
|
3366
|
+
/\bfunction\b/,
|
|
3367
|
+
/(?:^|\s)(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?function\b/,
|
|
3368
|
+
/(?:^|\s)(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/,
|
|
3369
|
+
/(?:^|\s)(?:const|let|var)\s+\w+\s*=\s*(?:async\s+)?function\b/,
|
|
3370
|
+
/(?:^|\s)(?:const|let|var)\s+\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/,
|
|
3371
|
+
];
|
|
3372
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3373
|
+
const line = lines[i];
|
|
3374
|
+
if (line.trimStart().startsWith('//'))
|
|
3375
|
+
continue;
|
|
3376
|
+
if (!startPatterns.some((re) => re.test(line)))
|
|
3377
|
+
continue;
|
|
3378
|
+
const startLine = i + 1;
|
|
3379
|
+
let depth = 0;
|
|
3380
|
+
let started = false;
|
|
3381
|
+
for (let j = i; j < lines.length; j++) {
|
|
3382
|
+
for (const ch of lines[j]) {
|
|
3383
|
+
if (ch === '{') {
|
|
3384
|
+
depth++;
|
|
3385
|
+
started = true;
|
|
3386
|
+
}
|
|
3387
|
+
else if (ch === '}')
|
|
3388
|
+
depth--;
|
|
3389
|
+
}
|
|
3390
|
+
if (started && depth === 0) {
|
|
3391
|
+
ranges.push([startLine, j + 1]);
|
|
3392
|
+
break;
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
return ranges;
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* cognium-dev#1156 — `io_input` at `*.parse(...)` has no `method` tag; `location` is
|
|
3400
|
+
* like `parser.parse() in m`. When `path_traversal` (`readFileSync`, …) appears only
|
|
3401
|
+
* inside that `.parse(` argument list on the same line, inline colocation must not
|
|
3402
|
+
* pair them — the nested sink runs before the parse returns.
|
|
3403
|
+
*/
|
|
3404
|
+
function sinkNestedInJsTsParseArgs(lineText, sinkMethod) {
|
|
3405
|
+
if (!lineText || !sinkMethod?.length)
|
|
3406
|
+
return false;
|
|
3407
|
+
const needle = `${sinkMethod}(`;
|
|
3408
|
+
let i = 0;
|
|
3409
|
+
while (i < lineText.length) {
|
|
3410
|
+
const k = lineText.indexOf('parse', i);
|
|
3411
|
+
if (k === -1)
|
|
3412
|
+
return false;
|
|
3413
|
+
if (k > 0 && /[\w$]/.test(lineText[k - 1])) {
|
|
3414
|
+
i = k + 5;
|
|
3415
|
+
continue;
|
|
3416
|
+
}
|
|
3417
|
+
if (lineText.slice(k, k + 5) !== 'parse') {
|
|
3418
|
+
i = k + 1;
|
|
3419
|
+
continue;
|
|
3420
|
+
}
|
|
3421
|
+
const openParen = k + 5;
|
|
3422
|
+
if (lineText[openParen] !== '(') {
|
|
3423
|
+
i = k + 5;
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
const closeIdx = matchingCloseParen(lineText, openParen);
|
|
3427
|
+
if (closeIdx === -1) {
|
|
3428
|
+
i = k + 5;
|
|
3429
|
+
continue;
|
|
3430
|
+
}
|
|
3431
|
+
const argSpan = lineText.slice(openParen + 1, closeIdx);
|
|
3432
|
+
if (argSpan.includes(needle))
|
|
3433
|
+
return true;
|
|
3434
|
+
i = closeIdx + 1;
|
|
3435
|
+
}
|
|
3436
|
+
return false;
|
|
3437
|
+
}
|
|
3208
3438
|
function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachableLines, tainted, code, language, types) {
|
|
3209
3439
|
const flows = [];
|
|
3210
3440
|
// #472 — Go function ranges for the same-function gate below. Returns the
|
|
@@ -3233,7 +3463,12 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
3233
3463
|
// is every Juliet C# file.
|
|
3234
3464
|
const csFnRanges = methodRanges(['csharp']);
|
|
3235
3465
|
const csFnStart = (line) => enclosingStart(csFnRanges, line);
|
|
3236
|
-
|
|
3466
|
+
let jsFnRanges = methodRanges(['javascript', 'typescript']);
|
|
3467
|
+
if (jsFnRanges.length === 0 &&
|
|
3468
|
+
typeof code === 'string' &&
|
|
3469
|
+
(language === 'javascript' || language === 'typescript')) {
|
|
3470
|
+
jsFnRanges = buildJsTsFunctionRangesFromSource(code);
|
|
3471
|
+
}
|
|
3237
3472
|
const jsFnStart = (line) => enclosingStart(jsFnRanges, line);
|
|
3238
3473
|
// cognium-dev#548 — names declared as class fields. A field is the one kind
|
|
3239
3474
|
// of variable whose value legitimately crosses from one method to another, so
|
|
@@ -3451,6 +3686,64 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
3451
3686
|
}
|
|
3452
3687
|
}
|
|
3453
3688
|
}
|
|
3689
|
+
// JS/TS body-parse chains (#1149 IL-22): virtual sources for variables
|
|
3690
|
+
// derived from `JSON.parse(req.body)` without widening to all jsTaintedVars.
|
|
3691
|
+
if ((language === 'javascript' || language === 'typescript') &&
|
|
3692
|
+
typeof code === 'string') {
|
|
3693
|
+
const httpTypes = new Set([
|
|
3694
|
+
'http_body',
|
|
3695
|
+
'http_query',
|
|
3696
|
+
'http_param',
|
|
3697
|
+
'http_header',
|
|
3698
|
+
'http_cookie',
|
|
3699
|
+
]);
|
|
3700
|
+
const httpAnchor = sourcesWithVar.find((s) => httpTypes.has(s.type));
|
|
3701
|
+
if (httpAnchor) {
|
|
3702
|
+
const lines = code.split('\n');
|
|
3703
|
+
const chainVars = new Set();
|
|
3704
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3705
|
+
const line = lines[i];
|
|
3706
|
+
if (/\bJSON\.parse\b/.test(line) && /\b(?:req|request)\.body\b/.test(line)) {
|
|
3707
|
+
const bind = line.match(/(?:const|let|var)\s+(\w+)\s*=/);
|
|
3708
|
+
if (bind?.[1])
|
|
3709
|
+
chainVars.add(bind[1]);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
let expanded = true;
|
|
3713
|
+
while (expanded) {
|
|
3714
|
+
expanded = false;
|
|
3715
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3716
|
+
const line = lines[i];
|
|
3717
|
+
for (const seed of chainVars) {
|
|
3718
|
+
const prop = line.match(new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*${seed}\\.`));
|
|
3719
|
+
const alias = line.match(new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*\\b${seed}\\b`));
|
|
3720
|
+
const lhs = prop?.[1] ?? alias?.[1];
|
|
3721
|
+
if (lhs && !chainVars.has(lhs)) {
|
|
3722
|
+
chainVars.add(lhs);
|
|
3723
|
+
expanded = true;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
if (chainVars.size > 0) {
|
|
3729
|
+
const derivedLines = buildJavaScriptTaintedVars(code, language);
|
|
3730
|
+
const existingVars = new Set(sourcesWithVar.map((s) => s.variable));
|
|
3731
|
+
for (const varName of chainVars) {
|
|
3732
|
+
if (!varName || existingVars.has(varName))
|
|
3733
|
+
continue;
|
|
3734
|
+
const originLine = derivedLines.get(varName);
|
|
3735
|
+
if (originLine === undefined)
|
|
3736
|
+
continue;
|
|
3737
|
+
sourcesWithVar.push({
|
|
3738
|
+
...httpAnchor,
|
|
3739
|
+
variable: varName,
|
|
3740
|
+
line: originLine,
|
|
3741
|
+
});
|
|
3742
|
+
existingVars.add(varName);
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3454
3747
|
// Rust alias expansion (#71): mirror the Python branch above so that
|
|
3455
3748
|
// multi-level extractor chains like
|
|
3456
3749
|
// let form = f.into_inner();
|
|
@@ -3823,12 +4116,22 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
3823
4116
|
});
|
|
3824
4117
|
}
|
|
3825
4118
|
else {
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
4119
|
+
// cognium-dev #914 S6 — a derived local assigned before an unrelated
|
|
4120
|
+
// env_input (e.g. `bar = helper(param)` then `osName = getProperty`)
|
|
4121
|
+
// must not inherit osName's env_input tag for expression-scan pairing
|
|
4122
|
+
// (OWASP BenchmarkTest01791: `cmd + bar` at exec mis-attributed to
|
|
4123
|
+
// System.getProperty on a later line).
|
|
4124
|
+
const unrelatedEnvAnchor = scopedAnchor.type === 'env_input' &&
|
|
4125
|
+
scopedAnchor.variable !== varName &&
|
|
4126
|
+
derivedLine < scopedAnchor.line;
|
|
4127
|
+
if (!unrelatedEnvAnchor) {
|
|
4128
|
+
sourcesWithVar.push({
|
|
4129
|
+
...scopedAnchor,
|
|
4130
|
+
variable: varName,
|
|
4131
|
+
literal_kill_line: derivedLine,
|
|
4132
|
+
...(owner ? { in_method: owner } : {}),
|
|
4133
|
+
});
|
|
4134
|
+
}
|
|
3832
4135
|
}
|
|
3833
4136
|
existingVars.add(varName);
|
|
3834
4137
|
}
|
|
@@ -4319,6 +4622,20 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4319
4622
|
if (srcFn !== -1 && sinkFn !== -1 && srcFn !== sinkFn)
|
|
4320
4623
|
continue;
|
|
4321
4624
|
}
|
|
4625
|
+
// cognium-dev#1223 — cross-function name collision on request proxies:
|
|
4626
|
+
// `req.query` must not match a local `query` in another handler.
|
|
4627
|
+
if (jsFnRanges.length > 0 &&
|
|
4628
|
+
source.variable &&
|
|
4629
|
+
!complex) {
|
|
4630
|
+
const srcFn = jsFnStart(source.line);
|
|
4631
|
+
const sinkFn = jsFnStart(sink.line);
|
|
4632
|
+
if (srcFn !== -1 &&
|
|
4633
|
+
sinkFn !== -1 &&
|
|
4634
|
+
srcFn !== sinkFn &&
|
|
4635
|
+
jsBareIdentOnlyAsRequestProxy(expr, source.variable)) {
|
|
4636
|
+
continue;
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4322
4639
|
// cognium-dev#752: GraphQL resolver args are seeded by name only; scope
|
|
4323
4640
|
// them to the resolver (or factory) they came from so a same-named
|
|
4324
4641
|
// local in another recorded function does not inherit the seed.
|
|
@@ -4540,6 +4857,16 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4540
4857
|
// JSDoc for the per-sink policy).
|
|
4541
4858
|
if (!sourceSemanticsAllowed(source, sink.type))
|
|
4542
4859
|
continue;
|
|
4860
|
+
// cognium-dev#1156 — sink nested only inside `.parse(` args (same line).
|
|
4861
|
+
const colocLineText = sink.code ?? '';
|
|
4862
|
+
if (colocLineText &&
|
|
4863
|
+
(language === 'javascript' || language === 'typescript') &&
|
|
4864
|
+
source.type === 'io_input' &&
|
|
4865
|
+
typeof source.location === 'string' &&
|
|
4866
|
+
source.location.includes('.parse()') &&
|
|
4867
|
+
sinkNestedInJsTsParseArgs(colocLineText, sink.method)) {
|
|
4868
|
+
continue;
|
|
4869
|
+
}
|
|
4543
4870
|
// Variable-scan handoff — if the source carries an LHS-bound
|
|
4544
4871
|
// variable AND that identifier is textually present in the RHS of
|
|
4545
4872
|
// the sink's own source-line code, the variable-scan path is
|
|
@@ -4599,6 +4926,18 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4599
4926
|
source.location.includes(`${sink.method}(`)) {
|
|
4600
4927
|
continue;
|
|
4601
4928
|
}
|
|
4929
|
+
// cognium-dev #914 — OWASP `Runtime.exec(args, env, new File(System.getProperty(...)))`:
|
|
4930
|
+
// the working-directory argument is not shell command input; inline colocation
|
|
4931
|
+
// would otherwise pair `env_input` getProperty with `command_injection` exec.
|
|
4932
|
+
if (source.type === 'env_input' &&
|
|
4933
|
+
sink.type === 'command_injection' &&
|
|
4934
|
+
sink.method === 'exec' &&
|
|
4935
|
+
/System\s*\.\s*getProperty\s*\(/.test(source.location ?? '')) {
|
|
4936
|
+
const sinkCode = sink.code ?? '';
|
|
4937
|
+
if (/new\s+(?:java\.io\.)?File\s*\(\s*System\s*\.\s*getProperty\s*\(/.test(sinkCode)) {
|
|
4938
|
+
continue;
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4602
4941
|
if (flows.some(f => f.source_line === source.line &&
|
|
4603
4942
|
f.sink_line === sink.line &&
|
|
4604
4943
|
f.sink_type === sink.type))
|
|
@@ -4639,7 +4978,9 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
4639
4978
|
// 4. Last resort: `sources[0]` (preserves pre-fix behaviour when nothing
|
|
4640
4979
|
// preceding exists — keeps existing test coverage green).
|
|
4641
4980
|
// ---------------------------------------------------------------------------
|
|
4642
|
-
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar
|
|
4981
|
+
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar, code, language,
|
|
4982
|
+
/** When true (#914 S5), do not pair a sink arg with an unrelated preceding source. */
|
|
4983
|
+
strictUnrelatedSourceGuard = false, javaDerivedVars) {
|
|
4643
4984
|
if (sources.length === 0)
|
|
4644
4985
|
return undefined;
|
|
4645
4986
|
// Closest-preceding selector over a candidate list. Strict-preceding
|
|
@@ -4656,6 +4997,48 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4656
4997
|
}
|
|
4657
4998
|
return best;
|
|
4658
4999
|
};
|
|
5000
|
+
const methodAt = (line) => {
|
|
5001
|
+
if (!types)
|
|
5002
|
+
return null;
|
|
5003
|
+
for (const t of types) {
|
|
5004
|
+
for (const m of t.methods) {
|
|
5005
|
+
if (line >= m.start_line && line <= m.end_line)
|
|
5006
|
+
return m.name;
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
return null;
|
|
5010
|
+
};
|
|
5011
|
+
// cognium-dev#1198 — stamped heap-field sources (`next.value`) must win over
|
|
5012
|
+
// RHS-derived anchor resolution (#515), which would otherwise credit `name`.
|
|
5013
|
+
if (language === 'java' && taintedVar?.includes('.')) {
|
|
5014
|
+
const byQualified = sources.filter((s) => s.variable === taintedVar);
|
|
5015
|
+
const pickQualified = closestPreceding(byQualified);
|
|
5016
|
+
if (pickQualified)
|
|
5017
|
+
return pickQualified;
|
|
5018
|
+
}
|
|
5019
|
+
// cognium-dev#515 — derived locals must credit the RHS read, not an earlier
|
|
5020
|
+
// decoy source in the same method (alias entries can still carry a stale anchor).
|
|
5021
|
+
if (taintedVar &&
|
|
5022
|
+
strictUnrelatedSourceGuard &&
|
|
5023
|
+
typeof code === 'string' &&
|
|
5024
|
+
(language === 'java' || language === 'csharp') &&
|
|
5025
|
+
javaDerivedVars?.has(taintedVar)) {
|
|
5026
|
+
const owner = methodName ?? methodAt(sinkLine);
|
|
5027
|
+
const realSourceByVar = new Map();
|
|
5028
|
+
for (const s of sources) {
|
|
5029
|
+
if (!s.variable)
|
|
5030
|
+
continue;
|
|
5031
|
+
const sOwner = s.in_method ?? methodAt(s.line);
|
|
5032
|
+
if (owner && sOwner !== owner)
|
|
5033
|
+
continue;
|
|
5034
|
+
const prev = realSourceByVar.get(s.variable);
|
|
5035
|
+
if (!prev || s.line < prev.line)
|
|
5036
|
+
realSourceByVar.set(s.variable, s);
|
|
5037
|
+
}
|
|
5038
|
+
const referenced = resolveJavaDerivedAnchor(taintedVar, javaDerivedVars, realSourceByVar, code.split('\n'), new Set());
|
|
5039
|
+
if (referenced && referenced.line < sinkLine)
|
|
5040
|
+
return referenced;
|
|
5041
|
+
}
|
|
4659
5042
|
// 1. Variable match (preferred — even across methods, falls within the
|
|
4660
5043
|
// method scope check below for the tiebreak).
|
|
4661
5044
|
if (taintedVar) {
|
|
@@ -4664,6 +5047,16 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4664
5047
|
if (pick)
|
|
4665
5048
|
return pick;
|
|
4666
5049
|
}
|
|
5050
|
+
// When the sink arg is a named tainted var, do not attribute it to an unrelated
|
|
5051
|
+
// source (cognium-dev #914 — OWASP BenchmarkTest01791: `bar` at exec paired with
|
|
5052
|
+
// `osName` from System.getProperty because it was the closest preceding source in doPost).
|
|
5053
|
+
// Collection/array flows pass a container name (e.g. `m`) that will not match any
|
|
5054
|
+
// source.variable — they keep the scoped / last-resort fallback (strict guard off).
|
|
5055
|
+
// Loop/`StringBuilder` locals often have no stamped source; only apply the guard when
|
|
5056
|
+
// at least one source carries this variable name on a line before the sink.
|
|
5057
|
+
const hasPrecedingNamedSource = Boolean(taintedVar && sources.some(s => s.variable === taintedVar && s.line < sinkLine));
|
|
5058
|
+
const guardUnrelatedSources = strictUnrelatedSourceGuard && hasPrecedingNamedSource;
|
|
5059
|
+
const matchesTaintedVar = (s) => !guardUnrelatedSources || !taintedVar || s.variable === taintedVar;
|
|
4667
5060
|
// 2. Scope match — restrict to sources whose line is inside the same
|
|
4668
5061
|
// method as the sink.
|
|
4669
5062
|
if (methodName && types && types.length > 0) {
|
|
@@ -4681,18 +5074,62 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
4681
5074
|
break;
|
|
4682
5075
|
}
|
|
4683
5076
|
if (methodStart > 0 && methodEnd >= methodStart) {
|
|
4684
|
-
const inScope = sources.filter(s => s.line >= methodStart && s.line <= methodEnd);
|
|
5077
|
+
const inScope = sources.filter(s => s.line >= methodStart && s.line <= methodEnd && matchesTaintedVar(s));
|
|
4685
5078
|
const pick = closestPreceding(inScope);
|
|
4686
5079
|
if (pick)
|
|
4687
5080
|
return pick;
|
|
4688
5081
|
}
|
|
4689
5082
|
}
|
|
4690
5083
|
// 3. Closest preceding source globally.
|
|
4691
|
-
const globalPick = closestPreceding(sources);
|
|
5084
|
+
const globalPick = closestPreceding(sources.filter(matchesTaintedVar));
|
|
4692
5085
|
if (globalPick)
|
|
4693
5086
|
return globalPick;
|
|
4694
5087
|
// 4. Last resort — preserve historical behaviour when there's nothing
|
|
4695
5088
|
// preceding the sink (e.g. synthetic same-line sources).
|
|
5089
|
+
if (guardUnrelatedSources && taintedVar)
|
|
5090
|
+
return undefined;
|
|
4696
5091
|
return sources[0];
|
|
4697
5092
|
}
|
|
5093
|
+
/**
|
|
5094
|
+
* cognium-dev #1156: true when every call to the sink's method on the sink line
|
|
5095
|
+
* sits inside the argument list of a call to the source's method on that line,
|
|
5096
|
+
* as in `parser.parse(fs.readFileSync(abs))`. The inner call runs first and the
|
|
5097
|
+
* outer call consumes its result, so the source's value cannot reach the sink.
|
|
5098
|
+
* When the source text or a sink call outside every source call can't be
|
|
5099
|
+
* found, it returns false and the flow is kept.
|
|
5100
|
+
*/
|
|
5101
|
+
function sinkNestedInSourceCall(source, sink) {
|
|
5102
|
+
if (source.line !== sink.line || !sink.method || !sink.code)
|
|
5103
|
+
return false;
|
|
5104
|
+
const srcMethod = /([A-Za-z_$][\w$]*)\s*\(\)\s+in\b/.exec(source.location ?? '')?.[1];
|
|
5105
|
+
if (!srcMethod || srcMethod === sink.method)
|
|
5106
|
+
return false;
|
|
5107
|
+
// Blank string literals so parentheses inside them don't count.
|
|
5108
|
+
const text = sink.code.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, m => m[0] + ' '.repeat(m.length - 2) + m[0]);
|
|
5109
|
+
const callStarts = (name) => {
|
|
5110
|
+
const re = new RegExp(`(?<![\\w$])${name.replace(/\$/g, '\\$')}\\s*\\(`, 'g');
|
|
5111
|
+
const out = [];
|
|
5112
|
+
for (let m = re.exec(text); m; m = re.exec(text))
|
|
5113
|
+
out.push(m.index + m[0].length - 1);
|
|
5114
|
+
return out;
|
|
5115
|
+
};
|
|
5116
|
+
const ranges = [];
|
|
5117
|
+
for (const open of callStarts(srcMethod)) {
|
|
5118
|
+
let depth = 0;
|
|
5119
|
+
for (let i = open; i < text.length; i++) {
|
|
5120
|
+
if (text[i] === '(')
|
|
5121
|
+
depth++;
|
|
5122
|
+
else if (text[i] === ')' && --depth === 0) {
|
|
5123
|
+
ranges.push([open, i]);
|
|
5124
|
+
break;
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
if (ranges.length === 0)
|
|
5129
|
+
return false;
|
|
5130
|
+
const sinks = callStarts(sink.method);
|
|
5131
|
+
if (sinks.length === 0)
|
|
5132
|
+
return false;
|
|
5133
|
+
return sinks.every(pos => ranges.some(([a, b]) => pos > a && pos < b));
|
|
5134
|
+
}
|
|
4698
5135
|
//# sourceMappingURL=taint-propagation-pass.js.map
|