Skip to content

Commit 469ac80

Browse files
committed
Refactor PartialPathTraversal
1 parent f8e26f1 commit 469ac80

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import semmle.code.java.dataflow.TaintTracking
77
import semmle.code.java.dataflow.FlowSources
88

99
/**
10+
* DEPRECATED: Use `PartialPathTraversalFromRemoteFlow` instead.
11+
*
1012
* A taint-tracking configuration for unsafe user input
1113
* that is used to validate against path traversal, but is insufficient
1214
* and remains vulnerable to Partial Path Traversal.
1315
*/
14-
class PartialPathTraversalFromRemoteConfig extends TaintTracking::Configuration {
16+
deprecated class PartialPathTraversalFromRemoteConfig extends TaintTracking::Configuration {
1517
PartialPathTraversalFromRemoteConfig() { this = "PartialPathTraversalFromRemoteConfig" }
1618

1719
override predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
@@ -20,3 +22,20 @@ class PartialPathTraversalFromRemoteConfig extends TaintTracking::Configuration
2022
any(PartialPathTraversalMethodAccess ma).getQualifier() = node.asExpr()
2123
}
2224
}
25+
26+
/**
27+
* A taint-tracking configuration for unsafe user input
28+
* that is used to validate against path traversal, but is insufficient
29+
* and remains vulnerable to Partial Path Traversal.
30+
*/
31+
private module PartialPathTraversalFromRemoteConfig implements DataFlow::ConfigSig {
32+
predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
33+
34+
predicate isSink(DataFlow::Node node) {
35+
any(PartialPathTraversalMethodAccess ma).getQualifier() = node.asExpr()
36+
}
37+
}
38+
39+
/** Tracks flow of unsafe user input that is used to validate against path traversal, but is insufficient and remains vulnerable to Partial Path Traversal. */
40+
module PartialPathTraversalFromRemoteFlow =
41+
TaintTracking::Global<PartialPathTraversalFromRemoteConfig>;

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalFromRemote.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
*/
1212

1313
import semmle.code.java.security.PartialPathTraversalQuery
14-
import DataFlow::PathGraph
14+
import PartialPathTraversalFromRemoteFlow::PathGraph
1515

16-
from DataFlow::PathNode source, DataFlow::PathNode sink
17-
where any(PartialPathTraversalFromRemoteConfig config).hasFlowPath(source, sink)
16+
from
17+
PartialPathTraversalFromRemoteFlow::PathNode source,
18+
PartialPathTraversalFromRemoteFlow::PathNode sink
19+
where PartialPathTraversalFromRemoteFlow::flowPath(source, sink)
1820
select sink.getNode(), source, sink,
1921
"Partial Path Traversal Vulnerability due to insufficient guard against path traversal from $@.",
2022
source, "user-supplied data"
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import java
2-
import TestUtilities.InlineFlowTest
2+
import TestUtilities.InlineExpectationsTest
33
import semmle.code.java.security.PartialPathTraversalQuery
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
8-
95
class TestRemoteSource extends RemoteFlowSource {
106
TestRemoteSource() { this.asParameter().hasName(["dir", "path"]) }
117

128
override string getSourceType() { result = "TestSource" }
139
}
1410

15-
class Test extends InlineFlowTest {
16-
override DataFlow::Configuration getValueFlowConfig() { none() }
11+
class Test extends InlineExpectationsTest {
12+
Test() { this = "PartialPathTraversalFromRemoteTest" }
13+
14+
override string getARelevantTag() { result = "hasTaintFlow" }
1715

18-
override TaintTracking::Configuration getTaintFlowConfig() {
19-
result instanceof PartialPathTraversalFromRemoteConfig
16+
override predicate hasActualResult(Location location, string element, string tag, string value) {
17+
tag = "hasTaintFlow" and
18+
exists(DataFlow::Node sink | PartialPathTraversalFromRemoteFlow::flowTo(sink) |
19+
sink.getLocation() = location and
20+
element = sink.toString() and
21+
value = ""
22+
)
2023
}
2124
}

0 commit comments

Comments
 (0)