Skip to content

Commit f4c9052

Browse files
authored
Merge pull request #15622 from atorralba/atorralba/java/path-sanitizer-equals
Java: Expand ExactPathSanitizer to work on the argument of 'equals' too
2 parents a5e3643 + 90a9d82 commit f4c9052

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private predicate exactPathMatchGuard(Guard g, Expr e, boolean branch) {
5656
t instanceof StringsKt or
5757
t instanceof FilesKt
5858
|
59-
e = getVisualQualifier(ma).getUnderlyingExpr() and
59+
e = [getVisualQualifier(ma).getUnderlyingExpr(), getVisualArgument(ma, 0)] and
6060
ma.getMethod().getDeclaringType() = t and
6161
ma = g and
6262
getSourceMethod(ma.getMethod()).hasName(["equals", "equalsIgnoreCase"]) and
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The sanitizer for the path injection queries has been improved to handle more cases where `equals` is used to check an exact path match.

java/ql/test/library-tests/pathsanitizer/Test.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public void exactPathMatchGuard() throws Exception {
2525
else
2626
sink(source); // $ hasTaintFlow
2727
}
28+
{
29+
String source = (String) source();
30+
if ("/safe/path".equals(source))
31+
sink(source); // Safe
32+
else
33+
sink(source); // $ hasTaintFlow
34+
}
2835
{
2936
URI source = (URI) source();
3037
if (source.equals(new URI("http://safe/uri")))

java/ql/test/library-tests/pathsanitizer/TestKt.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class TestKt {
2525
else
2626
sink(source) // $ hasTaintFlow
2727
}
28+
run {
29+
val source = source() as String?
30+
if ("/safe/path".equals(source))
31+
sink(source) // Safe
32+
else
33+
sink(source) // $ hasTaintFlow
34+
}
2835
run {
2936
val source = source() as URI?
3037
if (source!!.equals(URI("http://safe/uri")))

0 commit comments

Comments
 (0)