Skip to content

Commit fc71ca7

Browse files
committed
Java: Track taint through java.io.File::toPath & java.nio.file.Path::toFile
1 parent b49aa67 commit fc71ca7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

java/ql/src/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,13 @@ private predicate taintPreservingQualifierToMethod(Method m) {
377377
m.getDeclaringType().hasQualifiedName("java.nio", "ByteBuffer") and
378378
m.hasName("get")
379379
or
380-
m.getDeclaringType().hasQualifiedName("java.io", "File") and
380+
m.getDeclaringType() instanceof TypeFile and
381+
m.hasName("toPath")
382+
or
383+
m.getDeclaringType() instanceof TypePath and
384+
m.hasName("toFile")
385+
or
386+
m.getDeclaringType() instanceof TypeFile and
381387
m.hasName("toURI")
382388
or
383389
m.getDeclaringType().hasQualifiedName("java.net", "URI") and

java/ql/test/library-tests/dataflow/taint/B.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ public static void maintest() {
132132
// Tainted file path and URI
133133
sink(new java.io.File(s).toURI().toURL());
134134

135+
// Tainted file to Path
136+
sink(new java.io.File(s).toPath());
137+
138+
// Tainted File to Path to File
139+
sink(new java.io.File(s).toPath().toFile());
140+
135141
return;
136142
}
137143

java/ql/test/library-tests/dataflow/taint/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
| B.java:15:21:15:27 | taint(...) | B.java:128:10:128:22 | taintedArray2 |
3535
| B.java:15:21:15:27 | taint(...) | B.java:130:10:130:22 | taintedArray3 |
3636
| B.java:15:21:15:27 | taint(...) | B.java:133:10:133:44 | toURL(...) |
37+
| B.java:15:21:15:27 | taint(...) | B.java:136:10:136:37 | toPath(...) |
38+
| B.java:15:21:15:27 | taint(...) | B.java:139:10:139:46 | toFile(...) |
3739
| MethodFlow.java:7:22:7:28 | taint(...) | MethodFlow.java:8:10:8:16 | tainted |
3840
| MethodFlow.java:9:31:9:37 | taint(...) | MethodFlow.java:10:10:10:17 | tainted2 |
3941
| MethodFlow.java:11:35:11:41 | taint(...) | MethodFlow.java:12:10:12:17 | tainted3 |

0 commit comments

Comments
 (0)