Use `MapMutation` instead of `MethodCall`

This commit is contained in:
Ed Minnix 2023-12-19 15:20:19 -05:00
Родитель e14be0e971
Коммит a528db8958
1 изменённых файлов: 2 добавлений и 11 удалений

Просмотреть файл

@ -5,13 +5,6 @@ private import semmle.code.java.dataflow.FlowSources
private import semmle.code.java.Maps private import semmle.code.java.Maps
private import semmle.code.java.JDK private import semmle.code.java.JDK
private class MapUpdateWithKeyOrValue extends MethodCall {
MapUpdateWithKeyOrValue() {
this.getMethod() instanceof MapMethod and
this.getMethod().getName().matches(["put%", "remove", "replace"])
}
}
private module ProcessBuilderEnvironmentConfig implements DataFlow::ConfigSig { private module ProcessBuilderEnvironmentConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { predicate isSource(DataFlow::Node source) {
exists(MethodCall mc | mc = source.asExpr() | exists(MethodCall mc | mc = source.asExpr() |
@ -19,9 +12,7 @@ private module ProcessBuilderEnvironmentConfig implements DataFlow::ConfigSig {
) )
} }
predicate isSink(DataFlow::Node sink) { predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(MapMutation mm).getQualifier() }
sink.asExpr() = any(MapUpdateWithKeyOrValue mm).getQualifier()
}
} }
private module ProcessBuilderEnvironmentFlow = DataFlow::Global<ProcessBuilderEnvironmentConfig>; private module ProcessBuilderEnvironmentFlow = DataFlow::Global<ProcessBuilderEnvironmentConfig>;
@ -43,7 +34,7 @@ module ExecTaintedEnvironmentConfig implements DataFlow::ConfigSig {
sinkNode(sink, "environment-injection") sinkNode(sink, "environment-injection")
or or
// sink is a key or value added to a `ProcessBuilder::environment` map. // sink is a key or value added to a `ProcessBuilder::environment` map.
exists(MapUpdateWithKeyOrValue mm | mm.getAnArgument() = sink.asExpr() | exists(MapMutation mm | mm.getAnArgument() = sink.asExpr() |
ProcessBuilderEnvironmentFlow::flowToExpr(mm.getQualifier()) ProcessBuilderEnvironmentFlow::flowToExpr(mm.getQualifier())
) )
} }