Skip to content

Commit b3b5c2c

Browse files
committed
Java: Refactor UnsafeContentUriResolution.
1 parent 4b814ec commit b3b5c2c

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.UnsafeContentUriResolution
77

8-
/** A taint-tracking configuration to find paths from remote sources to content URI resolutions. */
9-
class UnsafeContentResolutionConf extends TaintTracking::Configuration {
8+
/**
9+
* DEPRECATED: Use `UnsafeContentUriResolutionFlow` instead.
10+
*
11+
* A taint-tracking configuration to find paths from remote sources to content URI resolutions.
12+
*/
13+
deprecated class UnsafeContentResolutionConf extends TaintTracking::Configuration {
1014
UnsafeContentResolutionConf() { this = "UnsafeContentResolutionConf" }
1115

1216
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
@@ -21,3 +25,20 @@ class UnsafeContentResolutionConf extends TaintTracking::Configuration {
2125
any(ContentUriResolutionAdditionalTaintStep s).step(node1, node2)
2226
}
2327
}
28+
29+
private module UnsafeContentResolutionConf implements DataFlow::ConfigSig {
30+
predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
31+
32+
predicate isSink(DataFlow::Node sink) { sink instanceof ContentUriResolutionSink }
33+
34+
predicate isBarrier(DataFlow::Node sanitizer) {
35+
sanitizer instanceof ContentUriResolutionSanitizer
36+
}
37+
38+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
39+
any(ContentUriResolutionAdditionalTaintStep s).step(node1, node2)
40+
}
41+
}
42+
43+
/** Taint-tracking flow to find paths from remote sources to content URI resolutions. */
44+
module UnsafeContentResolutionFlow = TaintTracking::Make<UnsafeContentResolutionConf>;

java/ql/src/Security/CWE/CWE-441/UnsafeContentUriResolution.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
import java
1616
import semmle.code.java.security.UnsafeContentUriResolutionQuery
17-
import DataFlow::PathGraph
17+
import UnsafeContentResolutionFlow::PathGraph
1818

19-
from DataFlow::PathNode src, DataFlow::PathNode sink
20-
where any(UnsafeContentResolutionConf c).hasFlowPath(src, sink)
19+
from UnsafeContentResolutionFlow::PathNode src, UnsafeContentResolutionFlow::PathNode sink
20+
where UnsafeContentResolutionFlow::hasFlowPath(src, sink)
2121
select sink.getNode(), src, sink,
2222
"This ContentResolver method that resolves a URI depends on a $@.", src.getNode(),
2323
"user-provided value"

java/ql/test/query-tests/security/CWE-441/UnsafeContentUriResolutionTest.ql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ import java
22
import TestUtilities.InlineFlowTest
33
import semmle.code.java.security.UnsafeContentUriResolutionQuery
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
8-
95
class Test extends InlineFlowTest {
10-
override DataFlow::Configuration getValueFlowConfig() { none() }
6+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
117

12-
override TaintTracking::Configuration getTaintFlowConfig() {
13-
result instanceof UnsafeContentResolutionConf
8+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) {
9+
UnsafeContentResolutionFlow::hasFlow(src, sink)
1410
}
1511
}

0 commit comments

Comments
 (0)