dir.getCanonicalPath().startsWith(parent.getCanonicalPath()
, which is vulnerable to partial path traversal attacks, with the more secure dir.getCanonicalFile().toPath().startsWith(parent.getCanonicalFile().toPath())
."/usr/outnot".startsWith("/usr/out")
. The check is bypassed although /outnot
is not under the /out
directory. It's important to understand that the terminating slash may be removed when using various String
representations of the File
object. For example, on Linux, println(new File("/var"))
will print /var
, but println(new File("/var", "/")
will print /var/
; however, println(new File("/var", "/").getCanonicalPath())
will print /var
._-Drewrite.activeRecipesorg.openrewrite.java.security.PartialPathTraversalVulnerability