Skip to content

Commit 0c70be1

Browse files
committed
Track taint through java.io.File constructor and #toURI; URI#toURL
1 parent c8cacb9 commit 0c70be1

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ private predicate constructorStep(Expr tracked, ConstructorCall sink) {
234234
or
235235
//a URI constructed from a tainted string is tainted.
236236
s = "java.net.URI" and argi = 0 and sink.getNumArgument() = 1
237+
or
238+
//a File constructed from a tainted string is tainted.
239+
s = "java.io.File" and argi = 0
240+
or
241+
s = "java.io.File" and argi = 1
237242
)
238243
or
239244
exists(RefType t | t.getQualifiedName() = "java.lang.Number" |
@@ -372,6 +377,12 @@ private predicate taintPreservingQualifierToMethod(Method m) {
372377
m.getDeclaringType().hasQualifiedName("java.nio", "ByteBuffer") and
373378
m.hasName("get")
374379
or
380+
m.getDeclaringType().hasQualifiedName("java.io", "File") and
381+
m.hasName("toURI")
382+
or
383+
m.getDeclaringType().hasQualifiedName("java.net", "URI") and
384+
m.hasName("toURL")
385+
or
375386
m = any(GuiceProvider gp).getAnOverridingGetMethod()
376387
or
377388
m = any(ProtobufMessageLite p).getAGetterMethod()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public static void maintest() {
129129
String[][][] taintedArray3 = new String[][][] { { { s } } };
130130
sink(taintedArray3);
131131

132+
// Tainted file path and URI
133+
sink(new java.io.File(s).toURI().toURL());
134+
132135
return;
133136
}
134137

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| B.java:15:21:15:27 | taint(...) | B.java:126:10:126:21 | taintedArray |
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 |
36+
| B.java:15:21:15:27 | taint(...) | B.java:133:10:133:44 | toURL(...) |
3637
| MethodFlow.java:7:22:7:28 | taint(...) | MethodFlow.java:8:10:8:16 | tainted |
3738
| MethodFlow.java:9:31:9:37 | taint(...) | MethodFlow.java:10:10:10:17 | tainted2 |
3839
| MethodFlow.java:11:35:11:41 | taint(...) | MethodFlow.java:12:10:12:17 | tainted3 |

0 commit comments

Comments
 (0)