Skip to content

Commit da43a61

Browse files
committed
Convert dataflow configuration to using new module-configuration
1 parent eeb9a88 commit da43a61

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

java/ql/lib/semmle/code/java/security/ArbitraryApkInstallationQuery.qll

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ private import semmle.code.java.security.ArbitraryApkInstallation
1010
* A dataflow configuration for flow from an external source of an APK to the
1111
* `setData[AndType][AndNormalize]` method of an intent.
1212
*/
13-
class ApkConfiguration extends DataFlow::Configuration {
14-
ApkConfiguration() { this = "ApkConfiguration" }
13+
private module ApkConf implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node node) { node instanceof ExternalApkSource }
1515

16-
override predicate isSource(DataFlow::Node node) { node instanceof ExternalApkSource }
17-
18-
override predicate isSink(DataFlow::Node node) {
16+
predicate isSink(DataFlow::Node node) {
1917
exists(MethodAccess ma |
2018
ma.getMethod() instanceof SetDataMethod and
2119
ma.getArgument(0) = node.asExpr() and
@@ -28,6 +26,23 @@ class ApkConfiguration extends DataFlow::Configuration {
2826
}
2927
}
3028

29+
module ApkConfiguration = DataFlow::Make<ApkConf>;
30+
31+
// class ApkConfiguration extends DataFlow::Configuration {
32+
// ApkConfiguration() { this = "ApkConfiguration" }
33+
// override predicate isSource(DataFlow::Node node) { node instanceof ExternalApkSource }
34+
// override predicate isSink(DataFlow::Node node) {
35+
// exists(MethodAccess ma |
36+
// ma.getMethod() instanceof SetDataMethod and
37+
// ma.getArgument(0) = node.asExpr() and
38+
// (
39+
// any(PackageArchiveMimeTypeConfiguration c).hasFlowToExpr(ma.getQualifier())
40+
// or
41+
// any(InstallPackageActionConfiguration c).hasFlowToExpr(ma.getQualifier())
42+
// )
43+
// )
44+
// }
45+
// }
3146
/**
3247
* A dataflow configuration tracking the flow from the `android.content.Intent.ACTION_INSTALL_PACKAGE`
3348
* constant to either the constructor of an intent or the `setAction` method of an intent.

java/ql/src/Security/CWE/CWE-094/ArbitraryApkInstallation.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ import java
1414
import semmle.code.java.security.ArbitraryApkInstallationQuery
1515
import DataFlow::PathGraph
1616

17-
from DataFlow::PathNode source, DataFlow::PathNode sink, ApkConfiguration config
18-
where config.hasFlowPath(source, sink)
17+
from DataFlow::PathNode source, DataFlow::PathNode sink
18+
where ApkConfiguration::hasFlowPath(source, sink)
1919
select sink.getNode(), source, sink, "Arbitrary Android APK installation."

java/ql/test/query-tests/security/CWE-094/ApkInstallationTest.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class HasApkInstallationTest extends InlineExpectationsTest {
1010

1111
override predicate hasActualResult(Location location, string element, string tag, string value) {
1212
tag = "hasApkInstallation" and
13-
exists(DataFlow::Node sink, ApkConfiguration conf | conf.hasFlowTo(sink) |
13+
exists(DataFlow::Node sink | ApkConfiguration::hasFlowTo(sink) |
1414
sink.getLocation() = location and
1515
element = sink.toString() and
1616
value = ""

0 commit comments

Comments
 (0)