Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/ql/lib/semmle/code/java/security/PathSanitizer.qll
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private predicate exactPathMatchGuard(Guard g, Expr e, boolean branch) {
t instanceof StringsKt or
t instanceof FilesKt
|
e = getVisualQualifier(ma).getUnderlyingExpr() and
e = [getVisualQualifier(ma).getUnderlyingExpr(), getVisualArgument(ma, 0)] and
ma.getMethod().getDeclaringType() = t and
ma = g and
getSourceMethod(ma.getMethod()).hasName(["equals", "equalsIgnoreCase"]) and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The sanitizer for the path injection queries has been improved to handle more cases where `equals` is used to check an exact path match.
7 changes: 7 additions & 0 deletions java/ql/test/library-tests/pathsanitizer/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public void exactPathMatchGuard() throws Exception {
else
sink(source); // $ hasTaintFlow
}
{
String source = (String) source();
if ("/safe/path".equals(source))
sink(source); // Safe
else
sink(source); // $ hasTaintFlow
}
{
URI source = (URI) source();
if (source.equals(new URI("http://safe/uri")))
Expand Down
7 changes: 7 additions & 0 deletions java/ql/test/library-tests/pathsanitizer/TestKt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class TestKt {
else
sink(source) // $ hasTaintFlow
}
run {
val source = source() as String?
if ("/safe/path".equals(source))
sink(source) // Safe
else
sink(source) // $ hasTaintFlow
}
run {
val source = source() as URI?
if (source!!.equals(URI("http://safe/uri")))
Expand Down