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
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Depends on: taint-matcher, constant-propagation, language-sources
|
|
17
17
|
*/
|
|
18
|
+
import { runsArgvAsCommand } from '../arg-executing-programs.js';
|
|
18
19
|
import { CSHARP_SANITIZER_RES, CSharpCredit, csharpSanitizersFor } from './csharp-sanitizer-credit.js';
|
|
19
20
|
import { JS_TAINTED_PATTERNS } from './language-sources-pass.js';
|
|
20
21
|
import { LIBRARY_API_SURFACE_TAG } from '../library-api-surface-downgrade.js';
|
|
21
22
|
import { isNonExecutableSourceLine } from '../non-executable-lines.js';
|
|
22
23
|
import { sanitizerCoversSink } from '../sanitizer-index.js';
|
|
23
|
-
import { identifierOutsideSanitizerCalls } from '../taint-propagation.js';
|
|
24
|
+
import { identifierOutsideSanitizerCalls, identifierOutsideSanitizerCallsInConcatOperand, } from '../taint-propagation.js';
|
|
24
25
|
import { parseJavaArrayAccessExpression } from '../java-array-element-keys.js';
|
|
25
26
|
import { resolveIdentifierType, resolveCallReturnType, isArgvContainerType, } from '../arg-type-resolver.js';
|
|
26
27
|
/** Escape regex metacharacters for safe pattern building. */
|
|
@@ -46,7 +47,9 @@ const JS_XSS_SANITIZERS = [
|
|
|
46
47
|
/\bencodeURI\s*\(/,
|
|
47
48
|
/\bcreateSafeHTML\s*\(/,
|
|
48
49
|
/\btrustAsHtml\s*\(/, // Angular
|
|
49
|
-
|
|
50
|
+
// Not `bypassSecurityTrust*` (#1171): it switches Angular's sanitizer off and is
|
|
51
|
+
// registered as the xss sink itself (config-loader, #184), so listing it here
|
|
52
|
+
// filtered every such sink out on its own line.
|
|
50
53
|
];
|
|
51
54
|
// ---------------------------------------------------------------------------
|
|
52
55
|
// Stage 16 — JS log_injection (CWE-117) sanitizer patterns.
|
|
@@ -725,9 +728,13 @@ export function synthesizeCrossFileArgvWrapperFlows(fileAnalyses, projectGraph,
|
|
|
725
728
|
continue;
|
|
726
729
|
const wrapperMethod = ctorCall.in_method;
|
|
727
730
|
const t = resolveJavaArgvIdentifierType(varName, wrapperMethod, sinkLine, ir.types, projectGraph);
|
|
728
|
-
|
|
731
|
+
const assembledLocal = wrapperMethod != null
|
|
732
|
+
&& javaAssembledArgvLocalFromInstanceFields(wrapperMethod, sinkLine, ir.types, lines);
|
|
733
|
+
const typedArgv = isArgvContainerType(t);
|
|
734
|
+
if (!typedArgv && !assembledLocal)
|
|
729
735
|
continue;
|
|
730
|
-
if (
|
|
736
|
+
if (typedArgv
|
|
737
|
+
&& sameFileCallerPassesShellArgv(varName, wrapperMethod, sinkLine, ir.types, ir.calls, lines)) {
|
|
731
738
|
continue;
|
|
732
739
|
}
|
|
733
740
|
const calleeMethod = ir.types
|
|
@@ -740,7 +747,7 @@ export function synthesizeCrossFileArgvWrapperFlows(fileAnalyses, projectGraph,
|
|
|
740
747
|
const fieldArgv = pos < 0
|
|
741
748
|
&& wrapperMethod
|
|
742
749
|
&& javaFieldArgvAtSink(projectGraph, ir.types, varName, wrapperMethod, sinkLine);
|
|
743
|
-
if (pos < 0 && !fieldArgv)
|
|
750
|
+
if (!assembledLocal && pos < 0 && !fieldArgv)
|
|
744
751
|
continue;
|
|
745
752
|
const relatedCalleeFiles = javaRelatedCalleeFiles(projectGraph, fa.file, hostType);
|
|
746
753
|
const shellArgvCtx = { projectGraph, sourceLinesByFile };
|
|
@@ -751,7 +758,17 @@ export function synthesizeCrossFileArgvWrapperFlows(fileAnalyses, projectGraph,
|
|
|
751
758
|
return;
|
|
752
759
|
const setterName = `set${varName.charAt(0).toUpperCase()}${varName.slice(1)}`;
|
|
753
760
|
let shellProof = false;
|
|
754
|
-
if (
|
|
761
|
+
if (assembledLocal && hostType) {
|
|
762
|
+
if (!wrapperMethod || !wrapperMethodMatchesTarget(wrapperMethod, targetMethod))
|
|
763
|
+
return;
|
|
764
|
+
const callerMethod = ctx.types
|
|
765
|
+
.flatMap(ty => ty.methods)
|
|
766
|
+
.find(mm => call.location.line >= mm.start_line && call.location.line <= mm.end_line);
|
|
767
|
+
if (!callerMethod)
|
|
768
|
+
return;
|
|
769
|
+
shellProof = javaCallerReceiverConstructedWithShell(call, hostType, callerMethod.start_line, callerMethod.end_line, ctx.lines, ctx.types, shellArgvCtx);
|
|
770
|
+
}
|
|
771
|
+
else if (pos >= 0) {
|
|
755
772
|
if (!wrapperMethod || !wrapperMethodMatchesTarget(wrapperMethod, targetMethod))
|
|
756
773
|
return;
|
|
757
774
|
if (call.arguments.length <= pos)
|
|
@@ -849,6 +866,66 @@ export function synthesizeCrossFileArgvWrapperFlows(fileAnalyses, projectGraph,
|
|
|
849
866
|
}
|
|
850
867
|
}
|
|
851
868
|
}
|
|
869
|
+
/** cognium-dev#1199 — local `argv` list built from instance fields before ProcessBuilder. */
|
|
870
|
+
function javaAssembledArgvLocalFromInstanceFields(wrapperMethod, sinkLine, types, sourceLines) {
|
|
871
|
+
const method = types
|
|
872
|
+
.flatMap(t => t.methods)
|
|
873
|
+
.find(mm => mm.name === wrapperMethod && sinkLine >= mm.start_line && sinkLine <= mm.end_line);
|
|
874
|
+
if (!method)
|
|
875
|
+
return false;
|
|
876
|
+
let sawAddExec = false;
|
|
877
|
+
let sawAddAll = false;
|
|
878
|
+
const addExecRe = /\bargv\s*\.\s*add\s*\(\s*(?:this\.)?\w+\s*\)/;
|
|
879
|
+
const addAllRe = /\bargv\s*\.\s*addAll\s*\(\s*(?:this\.)?\w+\s*\)/;
|
|
880
|
+
for (let l = method.start_line; l < sinkLine && l <= method.end_line; l++) {
|
|
881
|
+
const line = sourceLines[l - 1] ?? '';
|
|
882
|
+
if (addExecRe.test(line))
|
|
883
|
+
sawAddExec = true;
|
|
884
|
+
if (addAllRe.test(line))
|
|
885
|
+
sawAddAll = true;
|
|
886
|
+
}
|
|
887
|
+
return sawAddExec && sawAddAll;
|
|
888
|
+
}
|
|
889
|
+
function javaIsConstructorCallToType(targetMethod, call, hostTypeName) {
|
|
890
|
+
if (targetMethod.includes('<init>') && targetMethod.includes(hostTypeName))
|
|
891
|
+
return true;
|
|
892
|
+
return call.method_name === hostTypeName && (call.receiver === null || call.receiver === undefined);
|
|
893
|
+
}
|
|
894
|
+
/** cognium-dev#1199 — `recv.execute()` only counts when `recv` was `new HostType("sh", …)` above. */
|
|
895
|
+
function javaCallerReceiverConstructedWithShell(call, hostTypeName, methodStart, methodEnd, sourceLines, types, shellArgvCtx) {
|
|
896
|
+
const recv = call.receiver?.trim();
|
|
897
|
+
if (!recv || recv === 'this')
|
|
898
|
+
return false;
|
|
899
|
+
const ctorRe = new RegExp(`\\b${escapeReSf(hostTypeName)}\\s+${escapeReSf(recv)}\\s*=\\s*new\\s+${escapeReSf(hostTypeName)}\\s*\\(\\s*([^)]+)\\)`);
|
|
900
|
+
for (let l = methodStart; l < call.location.line && l <= methodEnd; l++) {
|
|
901
|
+
const line = (sourceLines[l - 1] ?? '').trim();
|
|
902
|
+
const m = ctorRe.exec(line);
|
|
903
|
+
if (m
|
|
904
|
+
&& javaExpressionLooksLikeShellArgv(m[1].trim(), l, types, sourceLines, shellArgvCtx)) {
|
|
905
|
+
return true;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return false;
|
|
909
|
+
}
|
|
910
|
+
function projectCallerPassesShellForAssembledArgv(hostTypeName, wrapperMethod, getCallerContext, forEachCrossFileCall, shellArgvCtx) {
|
|
911
|
+
let found = false;
|
|
912
|
+
forEachCrossFileCall((callerFile, call, targetMethod) => {
|
|
913
|
+
if (!wrapperMethod || !wrapperMethodMatchesTarget(wrapperMethod, targetMethod))
|
|
914
|
+
return;
|
|
915
|
+
const ctx = getCallerContext(callerFile);
|
|
916
|
+
if (!ctx)
|
|
917
|
+
return;
|
|
918
|
+
const callerMethod = ctx.types
|
|
919
|
+
.flatMap(t => t.methods)
|
|
920
|
+
.find(mm => call.location.line >= mm.start_line && call.location.line <= mm.end_line);
|
|
921
|
+
if (!callerMethod)
|
|
922
|
+
return;
|
|
923
|
+
if (javaCallerReceiverConstructedWithShell(call, hostTypeName, callerMethod.start_line, callerMethod.end_line, ctx.lines, ctx.types, shellArgvCtx)) {
|
|
924
|
+
found = true;
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
return found;
|
|
928
|
+
}
|
|
852
929
|
/** cognium-dev#626 — drop argv-wrapper flows with no shell-argv caller (incl. cross-file). */
|
|
853
930
|
export function filterJavaArgvWrapperFlowsWithoutShellCaller(fileAnalyses, projectGraph, sourceLinesByFile) {
|
|
854
931
|
const getCallerContext = (file) => {
|
|
@@ -897,12 +974,23 @@ export function filterJavaArgvWrapperFlowsWithoutShellCaller(fileAnalyses, proje
|
|
|
897
974
|
if (!varName || argExpr !== varName || /[(.]/.test(argExpr))
|
|
898
975
|
return true;
|
|
899
976
|
const t = resolveJavaArgvIdentifierType(varName, ctorCall.in_method, flow.sink_line, ir.types, projectGraph);
|
|
900
|
-
if (!isArgvContainerType(t))
|
|
901
|
-
return true;
|
|
902
977
|
const hostType = ctorCall.in_method
|
|
903
978
|
? javaHostTypeAtSink(ir.types, ctorCall.in_method, flow.sink_line)
|
|
904
979
|
: undefined;
|
|
905
980
|
const relatedCalleeFiles = javaRelatedCalleeFiles(projectGraph, fa.file, hostType);
|
|
981
|
+
if (!isArgvContainerType(t)) {
|
|
982
|
+
if (ctorCall.in_method
|
|
983
|
+
&& hostType
|
|
984
|
+
&& javaAssembledArgvLocalFromInstanceFields(ctorCall.in_method, flow.sink_line, ir.types, lines)) {
|
|
985
|
+
const shellArgvCtx = { projectGraph, sourceLinesByFile };
|
|
986
|
+
return projectCallerPassesShellForAssembledArgv(hostType, ctorCall.in_method ?? '', getCallerContext, cb => {
|
|
987
|
+
for (const calleeFile of relatedCalleeFiles) {
|
|
988
|
+
forEachCrossFileCall(calleeFile, cb);
|
|
989
|
+
}
|
|
990
|
+
}, shellArgvCtx);
|
|
991
|
+
}
|
|
992
|
+
return true;
|
|
993
|
+
}
|
|
906
994
|
return projectCallerPassesShellArgvForWrapper(varName, ctorCall.in_method, flow.sink_line, ir.types, ir.calls, lines, projectGraph, sourceLinesByFile, getCallerContext, cb => {
|
|
907
995
|
for (const calleeFile of relatedCalleeFiles) {
|
|
908
996
|
forEachCrossFileCall(calleeFile, cb);
|
|
@@ -1117,11 +1205,42 @@ function rustSsrfRequestUsesFixedHostFormat(code, sinkLine) {
|
|
|
1117
1205
|
const assignRe = new RegExp(`\\blet\\s+${escapeRegex(varName)}\\s*=\\s*format!`);
|
|
1118
1206
|
for (let i = sinkLine - 2; i >= Math.max(0, sinkLine - 20); i--) {
|
|
1119
1207
|
const line = lines[i] ?? '';
|
|
1120
|
-
if (assignRe.test(line)
|
|
1208
|
+
if (!assignRe.test(line))
|
|
1209
|
+
continue;
|
|
1210
|
+
if (RUST_FIXED_HOST_FORMAT_RE.test(line))
|
|
1211
|
+
return true;
|
|
1212
|
+
if (rustFormatLeadsWithFixedHostConst(code, line))
|
|
1121
1213
|
return true;
|
|
1122
1214
|
}
|
|
1123
1215
|
return false;
|
|
1124
1216
|
}
|
|
1217
|
+
/**
|
|
1218
|
+
* `format!("{}/path/{}", BASE, x)` where `BASE` is a file-level
|
|
1219
|
+
* `const`/`static` string holding a literal origin (cognium-dev#922).
|
|
1220
|
+
* The origin is fixed when the const is `scheme://host[:port]` and the
|
|
1221
|
+
* format string continues with `/` right after the first `{}` (or the
|
|
1222
|
+
* const itself already ends in a path), so the remaining slots can only
|
|
1223
|
+
* reach path segments of that host.
|
|
1224
|
+
*/
|
|
1225
|
+
const RUST_FORMAT_CONST_LEAD_RE = /format!\(\s*"\{\}([^"]*)"\s*,\s*([A-Z_][A-Z0-9_]*)\s*[,)]/;
|
|
1226
|
+
const RUST_ORIGIN_RE = /^https?:\/\/[A-Za-z0-9.-]+(?::\d+)?(\/[^"]*)?$/;
|
|
1227
|
+
function rustFormatLeadsWithFixedHostConst(code, line) {
|
|
1228
|
+
const m = line.match(RUST_FORMAT_CONST_LEAD_RE);
|
|
1229
|
+
if (!m)
|
|
1230
|
+
return false;
|
|
1231
|
+
const rest = m[1] ?? '';
|
|
1232
|
+
const constName = m[2] ?? '';
|
|
1233
|
+
const declRe = new RegExp(`^\\s*(?:pub(?:\\([^)]*\\))?\\s+)?(?:const|static)\\s+${escapeRegex(constName)}\\s*:\\s*&(?:'static\\s+)?str\\s*=\\s*"([^"\\\\]*)"\\s*;`, 'm');
|
|
1234
|
+
const decl = code.match(declRe);
|
|
1235
|
+
if (!decl)
|
|
1236
|
+
return false;
|
|
1237
|
+
const origin = RUST_ORIGIN_RE.exec(decl[1] ?? '');
|
|
1238
|
+
if (!origin)
|
|
1239
|
+
return false;
|
|
1240
|
+
// `"http://host"` + `"{}{}"` could still be extended into another host
|
|
1241
|
+
// (`.evil.example`); require the path separator to be fixed too.
|
|
1242
|
+
return rest.startsWith('/') || origin[1] !== undefined;
|
|
1243
|
+
}
|
|
1125
1244
|
/**
|
|
1126
1245
|
* True when the string literal that ended at `end` is the WHOLE initializer:
|
|
1127
1246
|
* the next code token is `;`, `,`, end of input, or (ASI) a token on a later
|
|
@@ -1213,7 +1332,7 @@ function regExpTemplateArgument(code, lines, line) {
|
|
|
1213
1332
|
let offset = 0;
|
|
1214
1333
|
for (let i = 0; i < line - 1; i++)
|
|
1215
1334
|
offset += lines[i].length + 1;
|
|
1216
|
-
const argument = /^(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[
|
|
1335
|
+
const argument = /^(?:\s|\/\/[^\n]*(?:\n|$)|\/\*(?:[^*]|\*(?!\/))*\*\/)*`((?:\\.|[^`\\])*)`(?=\s*[,)])/;
|
|
1217
1336
|
for (const start of text.matchAll(/new\s+RegExp\s*\(/g)) {
|
|
1218
1337
|
// The literal must be the whole first argument: `` `…` + text `` is not constant.
|
|
1219
1338
|
const m = argument.exec(code.slice(offset + start.index + start[0].length));
|
|
@@ -1224,6 +1343,67 @@ function regExpTemplateArgument(code, lines, line) {
|
|
|
1224
1343
|
}
|
|
1225
1344
|
/** A group that holds an unbounded quantifier and is itself quantified: `(a+)+`, `(x*)*`, `(\w{2,})+`, `(a+){2,}`. */
|
|
1226
1345
|
const NESTED_QUANTIFIER_RE = /\([^()]*(?:[+*]|\{\d+,\d*\})[^()]*\)\s*[+*{]/;
|
|
1346
|
+
/** Named helpers that escape regex metacharacters before `new RegExp` (cognium-dev#1145). */
|
|
1347
|
+
const JS_REGEXP_ESCAPE_CALL_RE = /^escape(?:RegExp|Re|Regex)\s*\(\s*[A-Za-z_$][\w$]*\s*\)$/;
|
|
1348
|
+
function jsRegexpFirstArgument(text) {
|
|
1349
|
+
const start = text.search(/new\s+RegExp\s*\(/);
|
|
1350
|
+
if (start < 0)
|
|
1351
|
+
return null;
|
|
1352
|
+
const open = text.indexOf('(', start);
|
|
1353
|
+
if (open < 0)
|
|
1354
|
+
return null;
|
|
1355
|
+
let depth = 0;
|
|
1356
|
+
const argStart = open + 1;
|
|
1357
|
+
for (let i = open; i < text.length; i++) {
|
|
1358
|
+
const c = text[i];
|
|
1359
|
+
if (c === '(')
|
|
1360
|
+
depth++;
|
|
1361
|
+
else if (c === ')') {
|
|
1362
|
+
depth--;
|
|
1363
|
+
if (depth === 0)
|
|
1364
|
+
return text.slice(argStart, i).trim();
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* True when the `new RegExp(` on `sinkLine` builds its pattern only from string
|
|
1371
|
+
* literals plus `escapeRegExp`-style calls — the interpolated part cannot carry
|
|
1372
|
+
* regex structure, so ReDoS from a tainted subject alone does not apply.
|
|
1373
|
+
*/
|
|
1374
|
+
function jsRegexpPatternOnlyViaEscapeHelper(code, lines, sinkLine) {
|
|
1375
|
+
const text = lines[sinkLine - 1] ?? '';
|
|
1376
|
+
if (!/new\s+RegExp\s*\(/.test(text))
|
|
1377
|
+
return false;
|
|
1378
|
+
const tpl = regExpTemplateArgument(code, lines, sinkLine);
|
|
1379
|
+
if (tpl !== null) {
|
|
1380
|
+
let sawInterpolation = false;
|
|
1381
|
+
for (const m of tpl.matchAll(/\$\{([^}]*)\}/g)) {
|
|
1382
|
+
sawInterpolation = true;
|
|
1383
|
+
if (!JS_REGEXP_ESCAPE_CALL_RE.test(m[1].trim()))
|
|
1384
|
+
return false;
|
|
1385
|
+
}
|
|
1386
|
+
return sawInterpolation;
|
|
1387
|
+
}
|
|
1388
|
+
const arg = jsRegexpFirstArgument(text);
|
|
1389
|
+
if (!arg)
|
|
1390
|
+
return false;
|
|
1391
|
+
if (!/escape(?:RegExp|Re|Regex)\s*\(/.test(arg))
|
|
1392
|
+
return false;
|
|
1393
|
+
const segments = arg.split(/\s*\+\s*/);
|
|
1394
|
+
let sawEscape = false;
|
|
1395
|
+
for (const seg of segments) {
|
|
1396
|
+
const s = seg.trim();
|
|
1397
|
+
if (/^(['"`])(?:\\.|(?!\1)[^\\])*\1$/.test(s))
|
|
1398
|
+
continue;
|
|
1399
|
+
if (JS_REGEXP_ESCAPE_CALL_RE.test(s)) {
|
|
1400
|
+
sawEscape = true;
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
return sawEscape;
|
|
1406
|
+
}
|
|
1227
1407
|
/** A template literal that starts with `${IDENT}/` (cognium-dev#680). */
|
|
1228
1408
|
const CONST_BASE_TEMPLATE_RE = /`\$\{\s*([A-Za-z_$][\w$]*)\s*\}\//g;
|
|
1229
1409
|
/**
|
|
@@ -1384,6 +1564,54 @@ function jsSsrfHostGuardedLines(code) {
|
|
|
1384
1564
|
}
|
|
1385
1565
|
return covered;
|
|
1386
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* True when a libxmljs `parseXml` / `parseXmlString` call at `sinkLine` has
|
|
1569
|
+
* disabled external entities: `noent: false`, an inline options object without
|
|
1570
|
+
* `noent: true`, or a single-argument call (default `noent: false`).
|
|
1571
|
+
* Dynamic options (`parseXml(buf, opts)`) → false (unknown; keep the sink).
|
|
1572
|
+
* (cognium-dev#1222)
|
|
1573
|
+
*/
|
|
1574
|
+
function jsLibxmljsNoentDisablesXxe(code, sinkLine) {
|
|
1575
|
+
const lines = code.split('\n');
|
|
1576
|
+
const start = Math.max(0, sinkLine - 2);
|
|
1577
|
+
const end = Math.min(lines.length, sinkLine + 4);
|
|
1578
|
+
const window = lines.slice(start, end).join('\n');
|
|
1579
|
+
if (!/\blibxml(?:js)?\s*\.\s*parseXml(?:String)?\s*\(/.test(window))
|
|
1580
|
+
return false;
|
|
1581
|
+
if (/\bnoent\s*:\s*true\b/.test(window))
|
|
1582
|
+
return false;
|
|
1583
|
+
const callIdx = window.search(/\bparseXml(?:String)?\s*\(/);
|
|
1584
|
+
if (callIdx < 0)
|
|
1585
|
+
return false;
|
|
1586
|
+
const afterCall = window.slice(callIdx);
|
|
1587
|
+
const openParen = afterCall.indexOf('(');
|
|
1588
|
+
if (openParen < 0)
|
|
1589
|
+
return false;
|
|
1590
|
+
let depth = 0;
|
|
1591
|
+
let closeIdx = -1;
|
|
1592
|
+
for (let i = openParen; i < afterCall.length; i++) {
|
|
1593
|
+
const ch = afterCall[i];
|
|
1594
|
+
if (ch === '(')
|
|
1595
|
+
depth++;
|
|
1596
|
+
else if (ch === ')') {
|
|
1597
|
+
depth--;
|
|
1598
|
+
if (depth === 0) {
|
|
1599
|
+
closeIdx = i;
|
|
1600
|
+
break;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
if (closeIdx < 0)
|
|
1605
|
+
return false;
|
|
1606
|
+
const inner = afterCall.slice(openParen + 1, closeIdx);
|
|
1607
|
+
const commaIdx = inner.indexOf(',');
|
|
1608
|
+
if (commaIdx < 0)
|
|
1609
|
+
return true;
|
|
1610
|
+
const secondArg = inner.slice(commaIdx + 1).trim();
|
|
1611
|
+
if (/^[A-Za-z_$][\w$]*$/.test(secondArg))
|
|
1612
|
+
return false;
|
|
1613
|
+
return secondArg.startsWith('{');
|
|
1614
|
+
}
|
|
1387
1615
|
/**
|
|
1388
1616
|
* Is this `plugin_param` source a map read that provably yields `null` or a
|
|
1389
1617
|
* string literal — a key that was never written, or any key of a literal-only
|
|
@@ -1414,6 +1642,11 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
1414
1642
|
return false;
|
|
1415
1643
|
const lines = code.split('\n');
|
|
1416
1644
|
const lineText = lines[source.line - 1] ?? '';
|
|
1645
|
+
return (isUnwrittenLocalMapKeyReadJava(lines, lineText) ||
|
|
1646
|
+
isUnwrittenLocalMapKeyReadJsMap(lines, lineText));
|
|
1647
|
+
}
|
|
1648
|
+
/** Java `HashMap` / `TreeMap` literal-key reads (#584). */
|
|
1649
|
+
function isUnwrittenLocalMapKeyReadJava(lines, lineText) {
|
|
1417
1650
|
// (c1) the read itself: `<recv>.get("<key>")`
|
|
1418
1651
|
const read = /\b([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*"([^"]*)"\s*\)/.exec(lineText);
|
|
1419
1652
|
if (!read)
|
|
@@ -1426,6 +1659,37 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
1426
1659
|
`\\b${recv}\\s*=\\s*new\\s+(?:java\\.util\\.(?:concurrent\\.)?)?(?:Hash|Tree|LinkedHash|ConcurrentHash|Concurrent|Identity|Weak)?Map\\s*(?:<[^>]*>)?\\s*\\(`);
|
|
1427
1660
|
if (!lines.some(l => ctorRe.test(l)))
|
|
1428
1661
|
return false;
|
|
1662
|
+
if (!localMapReceiverDoesNotEscape(lines, recv))
|
|
1663
|
+
return false;
|
|
1664
|
+
// (c2) was this literal key ever written? If so, drop when that key's puts are
|
|
1665
|
+
// all literals (#584 key-shuffle), even if another key holds tainted data.
|
|
1666
|
+
const putRe = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"`);
|
|
1667
|
+
if (lines.some(l => putRe.test(l)))
|
|
1668
|
+
return isLiteralOnlyLocalMapKey(lines, recv, key);
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
/** TS/JS `new Map()` literal-key reads (#985 S2, port of #584). */
|
|
1672
|
+
function isUnwrittenLocalMapKeyReadJsMap(lines, lineText) {
|
|
1673
|
+
const readLocal = /\b([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*(['"])([^'"]*)\2\s*\)/.exec(lineText);
|
|
1674
|
+
const readThis = /\bthis\s*\.\s*([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*(['"])([^'"]*)\2\s*\)/.exec(lineText);
|
|
1675
|
+
const read = readLocal ?? readThis;
|
|
1676
|
+
if (!read)
|
|
1677
|
+
return false;
|
|
1678
|
+
const recv = readLocal ? readLocal[1] : readThis[1];
|
|
1679
|
+
const quote = readLocal ? readLocal[2] : readThis[2];
|
|
1680
|
+
const key = readLocal ? readLocal[3] : readThis[3];
|
|
1681
|
+
const ctorRe = new RegExp(`(?:\\b${recv}\\s*=\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\(|\\bthis\\.${recv}\\s*=\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\(|\\b(?:private|readonly|public|protected)?\\s*\\w+\\s+${recv}\\s*(?:=|:)\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\()`);
|
|
1682
|
+
if (!lines.some(l => ctorRe.test(l)))
|
|
1683
|
+
return false;
|
|
1684
|
+
if (!localMapReceiverDoesNotEscape(lines, recv))
|
|
1685
|
+
return false;
|
|
1686
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1687
|
+
const setRe = new RegExp(`(?:\\b${recv}|\\bthis\\.${recv})\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}`);
|
|
1688
|
+
if (lines.some(l => setRe.test(l)))
|
|
1689
|
+
return isLiteralOnlyLocalMapKeyJs(lines, recv, key, quote);
|
|
1690
|
+
return true;
|
|
1691
|
+
}
|
|
1692
|
+
function localMapReceiverDoesNotEscape(lines, recv) {
|
|
1429
1693
|
// (b) no escape: the receiver must not appear inside any call's arguments.
|
|
1430
1694
|
// `m.put(...)` / `m.get(...)` are receiver positions, not arguments.
|
|
1431
1695
|
const escapeRe = new RegExp(`\\w\\s*\\([^)]*(?<![\\w.])${recv}(?![\\w.])[^)]*\\)`);
|
|
@@ -1433,15 +1697,10 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
1433
1697
|
if (!escapeRe.test(l))
|
|
1434
1698
|
continue;
|
|
1435
1699
|
// Allow the map's own keyed calls on this line.
|
|
1436
|
-
const stripped = l.replace(new RegExp(`\\b
|
|
1700
|
+
const stripped = l.replace(new RegExp(`\\b(?:this\\.)?${recv}\\s*\\.\\s*\\w+\\s*\\(`, 'g'), 'X(');
|
|
1437
1701
|
if (escapeRe.test(stripped))
|
|
1438
1702
|
return false;
|
|
1439
1703
|
}
|
|
1440
|
-
// (c2) was this literal key ever written? If so, drop when that key's puts are
|
|
1441
|
-
// all literals (#584 key-shuffle), even if another key holds tainted data.
|
|
1442
|
-
const putRe = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"`);
|
|
1443
|
-
if (lines.some(l => putRe.test(l)))
|
|
1444
|
-
return isLiteralOnlyLocalMapKey(lines, recv, key);
|
|
1445
1704
|
return true;
|
|
1446
1705
|
}
|
|
1447
1706
|
/**
|
|
@@ -1470,6 +1729,21 @@ function isLiteralOnlyLocalMapKey(lines, recv, key) {
|
|
|
1470
1729
|
}
|
|
1471
1730
|
return putsForKey > 0 && putsForKey === literalPutsForKey;
|
|
1472
1731
|
}
|
|
1732
|
+
/** TS/JS `Map.set` literal-only key writes (#985 S2). */
|
|
1733
|
+
function isLiteralOnlyLocalMapKeyJs(lines, recv, key, quote) {
|
|
1734
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1735
|
+
const recvAlt = `(?:\\b${recv}|\\bthis\\.${recv})`;
|
|
1736
|
+
const anyKeySet = new RegExp(`${recvAlt}\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}`);
|
|
1737
|
+
const qClass = quote === '"' ? '[^"\\\\]' : "[^'\\\\]";
|
|
1738
|
+
const literalSet = new RegExp(`${recvAlt}\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}\\s*,\\s*${quote}(?:${qClass}|\\\\.)*${quote}\\s*\\)`);
|
|
1739
|
+
let setsForKey = 0;
|
|
1740
|
+
let literalSetsForKey = 0;
|
|
1741
|
+
for (const l of lines) {
|
|
1742
|
+
setsForKey += (l.match(anyKeySet) ?? []).length;
|
|
1743
|
+
literalSetsForKey += (l.match(literalSet) ?? []).length;
|
|
1744
|
+
}
|
|
1745
|
+
return setsForKey > 0 && setsForKey === literalSetsForKey;
|
|
1746
|
+
}
|
|
1473
1747
|
/**
|
|
1474
1748
|
* cognium-dev#818 (src14) / #888 — `class: 'cache'` seeds `cache.get()` as db_input for
|
|
1475
1749
|
* redis `createClient()` bindings. Drop in-memory shapes: local `new Map()`, object
|
|
@@ -1999,6 +2273,41 @@ function isSameOriginQueryPrefix(prefix) {
|
|
|
1999
2273
|
return false; // protocol-relative
|
|
2000
2274
|
return prefix.includes('?'); // taint lands in the query
|
|
2001
2275
|
}
|
|
2276
|
+
/**
|
|
2277
|
+
* The values a JS sink call reads: each dotted name (`target`, `req.query.next`)
|
|
2278
|
+
* in the argument list of `method(` on the sink line, outside string literals,
|
|
2279
|
+
* and not itself called. Empty when the call is not found on the line.
|
|
2280
|
+
*/
|
|
2281
|
+
export function jsSinkArgumentValues(lineText, method) {
|
|
2282
|
+
if (!method)
|
|
2283
|
+
return [];
|
|
2284
|
+
const m = new RegExp(`\\b${method.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\(`).exec(lineText);
|
|
2285
|
+
if (!m)
|
|
2286
|
+
return [];
|
|
2287
|
+
let depth = 1, i = m.index + m[0].length;
|
|
2288
|
+
const start = i;
|
|
2289
|
+
for (; i < lineText.length && depth > 0; i++) {
|
|
2290
|
+
const ch = lineText[i];
|
|
2291
|
+
if (ch === '(')
|
|
2292
|
+
depth++;
|
|
2293
|
+
else if (ch === ')')
|
|
2294
|
+
depth--;
|
|
2295
|
+
}
|
|
2296
|
+
const args = lineText.slice(start, depth === 0 ? i - 1 : i)
|
|
2297
|
+
.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, '""');
|
|
2298
|
+
const out = new Set();
|
|
2299
|
+
const re = /(?<![\w$.])([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)(?![\w$])(?!\s*\()/g;
|
|
2300
|
+
for (let r = re.exec(args); r; r = re.exec(args)) {
|
|
2301
|
+
const name = r[1].replace(/\s+/g, '');
|
|
2302
|
+
if (!/^(?:true|false|null|undefined|this|new|typeof|await)$/.test(name))
|
|
2303
|
+
out.add(name);
|
|
2304
|
+
}
|
|
2305
|
+
return [...out];
|
|
2306
|
+
}
|
|
2307
|
+
/** True if a guard line mentions one of the sink's values as a whole name. */
|
|
2308
|
+
function guardTestsValue(line, values) {
|
|
2309
|
+
return values.some(v => new RegExp(`(?<![\\w$.])${v.replace(/[.$]/g, '\\$&')}(?![\\w$])`).test(line));
|
|
2310
|
+
}
|
|
2002
2311
|
export class SinkFilterPass {
|
|
2003
2312
|
name = 'sink-filter';
|
|
2004
2313
|
category = 'security';
|
|
@@ -2079,7 +2388,7 @@ export class SinkFilterPass {
|
|
|
2079
2388
|
// Stage 2 — clean array elements
|
|
2080
2389
|
filtered = filterCleanArraySinks(filtered, calls, constProp.taintedArrayElements, constProp.symbols);
|
|
2081
2390
|
// Stage 3 — clean variables
|
|
2082
|
-
filtered = filterCleanVariableSinks(filtered, calls, constProp.tainted, constProp.symbols, dfg, constProp.sanitizedVars, constProp.synchronizedLines, language, constProp.sanitizedVarUncovered);
|
|
2391
|
+
filtered = filterCleanVariableSinks(filtered, calls, constProp.tainted, constProp.symbols, dfg, constProp.sanitizedVars, constProp.synchronizedLines, language, constProp.sanitizedVarUncovered, sanitizers);
|
|
2083
2392
|
// Stage 4 — sanitized sinks. A sanitizer on one operand does not drop
|
|
2084
2393
|
// the sink while another source operand is still raw (#641).
|
|
2085
2394
|
filtered = filterSanitizedSinks(filtered, sanitizers, calls, sources);
|
|
@@ -2258,6 +2567,12 @@ export class SinkFilterPass {
|
|
|
2258
2567
|
// Default: keep the sink (conservative when no taint info available)
|
|
2259
2568
|
return true;
|
|
2260
2569
|
});
|
|
2570
|
+
// Stage 7b — JS/TS libxmljs xxe: hardened `noent` drops the taint sink (#1222).
|
|
2571
|
+
filtered = filtered.filter(sink => {
|
|
2572
|
+
if (sink.type !== 'xxe')
|
|
2573
|
+
return true;
|
|
2574
|
+
return !jsLibxmljsNoentDisablesXxe(ctx.code, sink.line);
|
|
2575
|
+
});
|
|
2261
2576
|
}
|
|
2262
2577
|
// Stage 8 — JavaScript open_redirect / crlf / header_injection FP reduction.
|
|
2263
2578
|
// Suppresses res.redirect(url) and res.setHeader(...) sinks when an
|
|
@@ -2274,10 +2589,16 @@ export class SinkFilterPass {
|
|
|
2274
2589
|
}
|
|
2275
2590
|
const sinkLineText = sourceLines[sink.line - 1] ?? '';
|
|
2276
2591
|
// 8a. Conditional-allowlist guard: if (allowed.includes(x)) res.redirect(x);
|
|
2592
|
+
// The guard must test a value the sink uses: a check on an unrelated
|
|
2593
|
+
// variable (`if (name.includes(' '))`) no longer drops the sink. When the
|
|
2594
|
+
// sink's argument names no value (the call is not found on the line),
|
|
2595
|
+
// any guard in the window still drops it, as before.
|
|
2596
|
+
const sinkValues = jsSinkArgumentValues(sinkLineText, sink.method);
|
|
2277
2597
|
const startLine = Math.max(0, sink.line - 7);
|
|
2278
2598
|
for (let i = startLine; i < sink.line - 1; i++) {
|
|
2279
2599
|
const line = sourceLines[i] ?? '';
|
|
2280
|
-
if (/\bif\s*\(/.test(line) && guardPatterns.test(line)
|
|
2600
|
+
if (/\bif\s*\(/.test(line) && guardPatterns.test(line)
|
|
2601
|
+
&& (sinkValues.length === 0 || guardTestsValue(line, sinkValues))) {
|
|
2281
2602
|
return false;
|
|
2282
2603
|
}
|
|
2283
2604
|
}
|
|
@@ -3018,6 +3339,45 @@ export class SinkFilterPass {
|
|
|
3018
3339
|
return !FETCH_MEMBER_RECEIVER_RE.test(sinkLineText);
|
|
3019
3340
|
});
|
|
3020
3341
|
}
|
|
3342
|
+
// Stage 15f3 — JS/TS: `.get` / `.all` / `.run` / `.each` / `.iterate` /
|
|
3343
|
+
// `.pluck` on a prepared statement take bound parameters, not SQL. The
|
|
3344
|
+
// `Connection` rows (sqlite3's `db.get(sql, …)`) also matched
|
|
3345
|
+
// `db.prepare(sql).get(...params)` (better-sqlite3, sqlite3's Statement),
|
|
3346
|
+
// so a request value passed as a `?` binding was a critical sql_injection
|
|
3347
|
+
// (dogfood 2026-11-01: circle-pack findings store). The receiver is a
|
|
3348
|
+
// statement when the call chains off `.prepare(…)` or is a variable
|
|
3349
|
+
// assigned from `.prepare(…)` in the file. The SQL text itself is the
|
|
3350
|
+
// argument of `prepare`, which this stage does not touch.
|
|
3351
|
+
if (['javascript', 'typescript'].includes(language)) {
|
|
3352
|
+
const lines = ctx.code.split('\n');
|
|
3353
|
+
const STATEMENT_METHODS = new Set(['get', 'all', 'run', 'each', 'iterate', 'pluck']);
|
|
3354
|
+
let statementVars = null;
|
|
3355
|
+
const isStatementVar = (name) => {
|
|
3356
|
+
if (statementVars === null) {
|
|
3357
|
+
statementVars = new Set();
|
|
3358
|
+
for (const m of ctx.code.matchAll(/(?:\b(?:const|let|var)\s+|\bthis\s*\.\s*|^\s*)([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+)?[\w$.]*\.\s*prepare\s*\(/gm))
|
|
3359
|
+
statementVars.add(m[1]);
|
|
3360
|
+
}
|
|
3361
|
+
return statementVars.has(name);
|
|
3362
|
+
};
|
|
3363
|
+
filtered = filtered.filter(sink => {
|
|
3364
|
+
if (sink.type !== 'sql_injection' || !STATEMENT_METHODS.has(sink.method ?? ''))
|
|
3365
|
+
return true;
|
|
3366
|
+
const method = sink.method;
|
|
3367
|
+
// The statement from the sink line until it ends and contains the call (a chain may span lines).
|
|
3368
|
+
const callRe = new RegExp(`\\.\\s*${method}\\s*\\(`);
|
|
3369
|
+
let stmt = lines[sink.line - 1] ?? '';
|
|
3370
|
+
for (let k = 0; k < 6 && !(callRe.test(stmt) && /[;)]\s*$/.test(stmt.replace(/\/\/.*$/, ''))); k++)
|
|
3371
|
+
stmt += ' ' + (lines[sink.line + k] ?? '').trim();
|
|
3372
|
+
// `….prepare( … ).get(` — the prepare call's parentheses balanced across one nesting level.
|
|
3373
|
+
if (new RegExp(`\\.\\s*prepare\\s*\\((?:[^()]|\\((?:[^()]|\\([^()]*\\))*\\))*\\)\\s*\\.\\s*${method}\\s*\\(`).test(stmt))
|
|
3374
|
+
return false;
|
|
3375
|
+
const recv = new RegExp(`(?:\\bthis\\s*\\.\\s*)?([A-Za-z_$][\\w$]*)\\s*\\.\\s*${method}\\s*\\(`).exec(stmt);
|
|
3376
|
+
if (recv && isStatementVar(recv[1]))
|
|
3377
|
+
return false;
|
|
3378
|
+
return true;
|
|
3379
|
+
});
|
|
3380
|
+
}
|
|
3021
3381
|
// Stage 15f2 — JS/TS: spawn / spawnSync / execFile / execFileSync with a
|
|
3022
3382
|
// fixed program (`process.execPath` or a string literal that is not a
|
|
3023
3383
|
// shell), no `shell: true`, and no node `-e`/`--eval`/`-p`: the arguments
|
|
@@ -3038,7 +3398,8 @@ export class SinkFilterPass {
|
|
|
3038
3398
|
return true;
|
|
3039
3399
|
const program = call[1].trim();
|
|
3040
3400
|
const literal = /^(['"`])([^'"`$]*)\1$/.exec(program);
|
|
3041
|
-
const fixed = program === 'process.execPath'
|
|
3401
|
+
const fixed = program === 'process.execPath'
|
|
3402
|
+
|| (literal !== null && !SHELL_PROGRAM.test(literal[2]) && !runsArgvAsCommand(literal[2])); // #1066
|
|
3042
3403
|
if (!fixed)
|
|
3043
3404
|
return true;
|
|
3044
3405
|
if (/\bshell\s*:\s*(?!false\b)/.test(stmt))
|
|
@@ -3096,6 +3457,25 @@ export class SinkFilterPass {
|
|
|
3096
3457
|
return !ORM_BUILDER_KEY_RE.test(sinkLineText);
|
|
3097
3458
|
});
|
|
3098
3459
|
}
|
|
3460
|
+
// Stage 15h2 — JS/TS nosql: string type reject-guard. (cognium-dev#1172)
|
|
3461
|
+
// `if (typeof req.body.id !== 'string') { …; return }` before
|
|
3462
|
+
// `coll.update({ _id: req.body.id }, …)` rules out an operator object
|
|
3463
|
+
// (`{ $ne: … }`), the NoSQL injection itself. Drop the sink only when every
|
|
3464
|
+
// request-derived reference in the filter argument is guarded that way.
|
|
3465
|
+
if (['javascript', 'typescript'].includes(language)) {
|
|
3466
|
+
const sourceLines = ctx.code.split('\n');
|
|
3467
|
+
filtered = filtered.filter(sink => {
|
|
3468
|
+
if (sink.type !== 'nosql_injection' || !sink.method)
|
|
3469
|
+
return true;
|
|
3470
|
+
const arg0 = jsCallFirstArgText(sourceLines, sink.line, sink.method);
|
|
3471
|
+
if (arg0 === null)
|
|
3472
|
+
return true;
|
|
3473
|
+
const refs = [...new Set([...arg0.matchAll(/\b(?:req|request)(?:\.[A-Za-z_$][\w$]*)+/g)].map(m => m[0]))];
|
|
3474
|
+
if (refs.length === 0)
|
|
3475
|
+
return true;
|
|
3476
|
+
return !refs.every(ref => jsTypeofStringRejectGuarded(sourceLines, sink.line, ref));
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3099
3479
|
// Stage 15j — JS/TS ssrf: client-component file. (cognium-ai#279 R-3)
|
|
3100
3480
|
// A fetch/axios call in a browser-rendered client component is not SSRF.
|
|
3101
3481
|
// Gated on ext + positive client signal + no server signal (zero-FN).
|
|
@@ -3162,6 +3542,11 @@ export class SinkFilterPass {
|
|
|
3162
3542
|
// A constant pattern can still backtrack on a tainted subject.
|
|
3163
3543
|
return NESTED_QUANTIFIER_RE.test(pattern);
|
|
3164
3544
|
});
|
|
3545
|
+
filtered = filtered.filter(sink => {
|
|
3546
|
+
if (sink.type !== 'redos')
|
|
3547
|
+
return true;
|
|
3548
|
+
return !jsRegexpPatternOnlyViaEscapeHelper(ctx.code, sourceLines, sink.line);
|
|
3549
|
+
});
|
|
3165
3550
|
}
|
|
3166
3551
|
// Stage 15f — JS/TS ssrf: anchored host allow-list reject-guard.
|
|
3167
3552
|
// (skillsregistry#49b) A URL pinned to a fixed host set by an anchored
|
|
@@ -3932,6 +4317,64 @@ function argumentIdentifiers(expression) {
|
|
|
3932
4317
|
}
|
|
3933
4318
|
return out;
|
|
3934
4319
|
}
|
|
4320
|
+
/** Split a Java string concat on top-level `+` (outside literals and parens). */
|
|
4321
|
+
function topLevelConcatOperands(expression) {
|
|
4322
|
+
const parts = [];
|
|
4323
|
+
let depth = 0;
|
|
4324
|
+
let quote = null;
|
|
4325
|
+
let escaped = false;
|
|
4326
|
+
let start = 0;
|
|
4327
|
+
for (let i = 0; i < expression.length; i++) {
|
|
4328
|
+
const c = expression[i];
|
|
4329
|
+
if (quote) {
|
|
4330
|
+
if (escaped) {
|
|
4331
|
+
escaped = false;
|
|
4332
|
+
continue;
|
|
4333
|
+
}
|
|
4334
|
+
if (c === '\\') {
|
|
4335
|
+
escaped = true;
|
|
4336
|
+
continue;
|
|
4337
|
+
}
|
|
4338
|
+
if (c === quote)
|
|
4339
|
+
quote = null;
|
|
4340
|
+
continue;
|
|
4341
|
+
}
|
|
4342
|
+
if (c === '"' || c === "'") {
|
|
4343
|
+
quote = c;
|
|
4344
|
+
continue;
|
|
4345
|
+
}
|
|
4346
|
+
if (c === '(')
|
|
4347
|
+
depth++;
|
|
4348
|
+
else if (c === ')')
|
|
4349
|
+
depth--;
|
|
4350
|
+
else if (c === '+' && depth === 0) {
|
|
4351
|
+
parts.push(expression.slice(start, i));
|
|
4352
|
+
start = i + 1;
|
|
4353
|
+
}
|
|
4354
|
+
}
|
|
4355
|
+
parts.push(expression.slice(start));
|
|
4356
|
+
return parts;
|
|
4357
|
+
}
|
|
4358
|
+
function concatOperandVariableNames(expr, sanitizers, sinkType) {
|
|
4359
|
+
const out = [];
|
|
4360
|
+
for (const operand of topLevelConcatOperands(expr)) {
|
|
4361
|
+
const trimmed = operand.trim();
|
|
4362
|
+
if (isStringLiteralExpression(trimmed))
|
|
4363
|
+
continue;
|
|
4364
|
+
let ids = argumentIdentifiers(trimmed);
|
|
4365
|
+
if (sanitizers && sanitizers.length > 0 && sinkType) {
|
|
4366
|
+
ids = ids.filter(varName => {
|
|
4367
|
+
const wrappedOnly = identifierOutsideSanitizerCallsInConcatOperand(varName, trimmed, sanitizers, sinkType);
|
|
4368
|
+
return wrappedOnly !== false;
|
|
4369
|
+
});
|
|
4370
|
+
}
|
|
4371
|
+
for (const id of ids) {
|
|
4372
|
+
if (!out.includes(id))
|
|
4373
|
+
out.push(id);
|
|
4374
|
+
}
|
|
4375
|
+
}
|
|
4376
|
+
return out;
|
|
4377
|
+
}
|
|
3935
4378
|
function isStringLiteralExpression(expr) {
|
|
3936
4379
|
const trimmed = expr.trim();
|
|
3937
4380
|
if (trimmed.length < 2)
|
|
@@ -3983,7 +4426,7 @@ function filterCleanArraySinks(sinks, calls, taintedArrayElements, symbols) {
|
|
|
3983
4426
|
return true;
|
|
3984
4427
|
});
|
|
3985
4428
|
}
|
|
3986
|
-
export function filterCleanVariableSinks(sinks, calls, taintedVars, symbols, dfg, sanitizedVars, synchronizedLines, language, sanitizedVarUncovered) {
|
|
4429
|
+
export function filterCleanVariableSinks(sinks, calls, taintedVars, symbols, dfg, sanitizedVars, synchronizedLines, language, sanitizedVarUncovered, sanitizers) {
|
|
3987
4430
|
const fieldNames = new Set();
|
|
3988
4431
|
if (dfg) {
|
|
3989
4432
|
for (const def of dfg.defs) {
|
|
@@ -4041,11 +4484,36 @@ export function filterCleanVariableSinks(sinks, calls, taintedVars, symbols, dfg
|
|
|
4041
4484
|
// Java only. The same `+` test on other languages kept sinks in
|
|
4042
4485
|
// minified scripts (a numeric add whose first identifier is a
|
|
4043
4486
|
// constant). #627 is the Java `exec(cmd + tainted)` shape.
|
|
4044
|
-
const
|
|
4045
|
-
|
|
4487
|
+
const rawConcatNames = language === 'java' && isStringConcat(expr)
|
|
4488
|
+
? concatOperandVariableNames(expr, sanitizers, sink.type)
|
|
4489
|
+
: [];
|
|
4490
|
+
if (language === 'java' && isStringConcat(expr) && rawConcatNames.length === 0)
|
|
4491
|
+
continue;
|
|
4492
|
+
const names = rawConcatNames.length > 0 ? rawConcatNames : [arg.variable];
|
|
4493
|
+
const concatOperandCheck = rawConcatNames.length > 0;
|
|
4046
4494
|
let argClean = true;
|
|
4047
4495
|
for (const varName of names) {
|
|
4048
4496
|
const scopedName = methodName ? `${methodName}:${varName}` : varName;
|
|
4497
|
+
if (concatOperandCheck &&
|
|
4498
|
+
sanitizers &&
|
|
4499
|
+
sanitizers.length > 0 &&
|
|
4500
|
+
sink.type &&
|
|
4501
|
+
!taintedVars.has(scopedName) &&
|
|
4502
|
+
!taintedVars.has(varName) &&
|
|
4503
|
+
!sanitizedVars?.has(scopedName) &&
|
|
4504
|
+
!sanitizedVars?.has(varName)) {
|
|
4505
|
+
let outsideOnly = null;
|
|
4506
|
+
for (const operand of topLevelConcatOperands(expr)) {
|
|
4507
|
+
const trimmed = operand.trim();
|
|
4508
|
+
if (!trimmed.includes(varName))
|
|
4509
|
+
continue;
|
|
4510
|
+
outsideOnly = identifierOutsideSanitizerCallsInConcatOperand(varName, trimmed, sanitizers, sink.type);
|
|
4511
|
+
if (outsideOnly !== null)
|
|
4512
|
+
break;
|
|
4513
|
+
}
|
|
4514
|
+
if (outsideOnly === true)
|
|
4515
|
+
continue;
|
|
4516
|
+
}
|
|
4049
4517
|
if (fieldNames.has(varName) && !isInSynchronizedBlock) {
|
|
4050
4518
|
argClean = false;
|
|
4051
4519
|
break;
|
|
@@ -4204,4 +4672,78 @@ function isXPathQuoteEscapedOnLine(lineText, varName) {
|
|
|
4204
4672
|
}
|
|
4205
4673
|
return seen > 0;
|
|
4206
4674
|
}
|
|
4675
|
+
/**
|
|
4676
|
+
* cognium-dev#1172 — text of the first argument of the call to `method` that
|
|
4677
|
+
* starts on 1-based `line` (it may span lines), or null if it can't be read.
|
|
4678
|
+
*/
|
|
4679
|
+
function jsCallFirstArgText(lines, line, method) {
|
|
4680
|
+
const text = lines.slice(line - 1, line + 11).join('\n');
|
|
4681
|
+
const at = text.search(new RegExp(`\\b${method.replace(/\$/g, '\\$')}\\s*\\(`));
|
|
4682
|
+
if (at < 0)
|
|
4683
|
+
return null;
|
|
4684
|
+
let i = text.indexOf('(', at) + 1;
|
|
4685
|
+
const start = i;
|
|
4686
|
+
let depth = 0;
|
|
4687
|
+
let str = null;
|
|
4688
|
+
for (; i < text.length; i++) {
|
|
4689
|
+
const ch = text[i];
|
|
4690
|
+
if (str) {
|
|
4691
|
+
if (ch === '\\')
|
|
4692
|
+
i++;
|
|
4693
|
+
else if (ch === str)
|
|
4694
|
+
str = null;
|
|
4695
|
+
continue;
|
|
4696
|
+
}
|
|
4697
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
4698
|
+
str = ch;
|
|
4699
|
+
continue;
|
|
4700
|
+
}
|
|
4701
|
+
if (ch === '(' || ch === '{' || ch === '[')
|
|
4702
|
+
depth++;
|
|
4703
|
+
else if (ch === ')' || ch === '}' || ch === ']') {
|
|
4704
|
+
if (depth === 0)
|
|
4705
|
+
return text.slice(start, i);
|
|
4706
|
+
depth--;
|
|
4707
|
+
}
|
|
4708
|
+
else if (ch === ',' && depth === 0)
|
|
4709
|
+
return text.slice(start, i);
|
|
4710
|
+
}
|
|
4711
|
+
return null;
|
|
4712
|
+
}
|
|
4713
|
+
/**
|
|
4714
|
+
* cognium-dev#1172 — true when, within the 40 lines before `sinkLine`, an
|
|
4715
|
+
* `if (… typeof <ref> !== 'string' …)` whose condition is only that check or
|
|
4716
|
+
* an `||` of checks rejects with return / throw / a `res.status(…)` reply.
|
|
4717
|
+
*/
|
|
4718
|
+
function jsTypeofStringRejectGuarded(lines, sinkLine, ref) {
|
|
4719
|
+
const esc = ref.replace(/[.$]/g, m => '\\' + m);
|
|
4720
|
+
const guardRe = new RegExp(`\\bif\\s*\\((?:[^()]*\\|\\|\\s*)?typeof\\s+${esc}\\s*!==?\\s*(['"])string\\1\\s*(?:\\|\\|[^()]*)?\\)`);
|
|
4721
|
+
const terminator = /\b(?:return|throw)\b|\bres\s*\.\s*status\s*\(/;
|
|
4722
|
+
for (let i = Math.max(0, sinkLine - 41); i < sinkLine - 1; i++) {
|
|
4723
|
+
if (!guardRe.test(lines[i] ?? ''))
|
|
4724
|
+
continue;
|
|
4725
|
+
const after = (lines[i] ?? '').slice((lines[i] ?? '').search(/\)\s*(?:\{|$|[^\s])/));
|
|
4726
|
+
if (terminator.test(after))
|
|
4727
|
+
return true;
|
|
4728
|
+
// block body: scan to the closing brace for a terminator
|
|
4729
|
+
let depth = 0;
|
|
4730
|
+
let started = false;
|
|
4731
|
+
for (let j = i; j < Math.min(lines.length, i + 15, sinkLine - 1); j++) {
|
|
4732
|
+
const ln = j === i ? after : (lines[j] ?? '');
|
|
4733
|
+
if (j > i && terminator.test(ln))
|
|
4734
|
+
return true;
|
|
4735
|
+
for (const ch of ln) {
|
|
4736
|
+
if (ch === '{') {
|
|
4737
|
+
depth++;
|
|
4738
|
+
started = true;
|
|
4739
|
+
}
|
|
4740
|
+
else if (ch === '}')
|
|
4741
|
+
depth--;
|
|
4742
|
+
}
|
|
4743
|
+
if (started && depth <= 0)
|
|
4744
|
+
break;
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
return false;
|
|
4748
|
+
}
|
|
4207
4749
|
//# sourceMappingURL=sink-filter-pass.js.map
|