Partial path traversal vulnerability

Proprietary

Replaces dir.getCanonicalPath().startsWith(parent.getCanonicalPath(), which is vulnerable to partial path traversal attacks, with the more secure dir.getCanonicalFile().toPath().startsWith(parent.getCanonicalFile().toPath()).

To demonstrate this vulnerability, consider "/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.

org.openrewrite.java.security.PartialPathTraversalVulnerability
mod run . --recipe=org.openrewrite.java.security.PartialPathTraversalVulnerability

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.