Skip to content

Commit d6349ff

Browse files
vuln-fix: Partial Path Traversal Vulnerability
This fixes a partial path traversal vulnerability. 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`. Weakness: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') Severity: Medium CVSSS: 6.1 Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.PartialPathTraversalVulnerability) Reported-by: Jonathan Leitschuh <[email protected]> Signed-off-by: Jonathan Leitschuh <[email protected]> Bug-tracker: JLLeitschuh/security-research#13 Co-authored-by: Moderne <[email protected]>
1 parent 16e5593 commit d6349ff

File tree

1 file changed

+1
-1
lines changed
  • src/main/java/hudson/plugins/scm_sync_configuration/scms/customproviders/git/gitexe

1 file changed

+1
-1
lines changed

src/main/java/hudson/plugins/scm_sync_configuration/scms/customproviders/git/gitexe/ScmSyncGitUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void addTarget(Commandline cl, List<File> files) throws ScmExcepti
6262
String relativeFile = file.getPath();
6363
final String canonicalFile = file.getCanonicalPath();
6464

65-
if (canonicalFile.startsWith(canonicalWorkingDirectory)) {
65+
if (file.getCanonicalFile().toPath().startsWith(canonicalWorkingDirectory)) {
6666
relativeFile = canonicalFile.substring(canonicalWorkingDirectory.length());
6767
if (relativeFile.startsWith(File.separator)) {
6868
relativeFile = relativeFile.substring(File.separator.length());

0 commit comments

Comments
 (0)