소스 검색

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 <Jonathan.Leitschuh@gmail.com>
Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>

Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/13

Co-authored-by: Moderne <team@moderne.io>
pull/12556/head
Jonathan Leitschuh 1 년 전
부모
커밋
94aeb9e32f
No account linked to committer's email address
1개의 변경된 파일1개의 추가작업 그리고 2개의 파일을 삭제
  1. 1
    2
      compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java

+ 1
- 2
compatibility-server/src/main/java/com/vaadin/v7/data/util/FilesystemContainer.java 파일 보기

@@ -376,8 +376,7 @@ public class FilesystemContainer implements Container.Hierarchical {
// Try to match all roots
for (File root : roots) {
try {
val |= ((File) itemId).getCanonicalPath()
.startsWith(root.getCanonicalPath());
val |= ((File) itemId).getCanonicalFile().toPath().startsWith(root.getCanonicalFile().toPath());
} catch (final IOException e) {
// Exception ignored
}

Loading…
취소
저장