1 Star 0 Fork 4

deshengwu/testng

forked from OpenCloudOS Stream/testng 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0003-vuln-fix-Zip-Slip-Vulnerability.patch 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
deshengwu 提交于 2024-06-07 10:23 . fix CVE-2022-4065
commit 47afa2c8a29e2cf925238af1ad7c76fba282793f
Author: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
Date: Mon Oct 3 21:21:05 2022 +0000
vuln-fix: Zip Slip Vulnerability
This fixes a Zip-Slip vulnerability.
This change does one of two things. This change either
1. Inserts a guard to protect against Zip Slip.
OR
2. 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())`.
For number 2, 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: High
CVSSS: 7.4
Detection: CodeQL (https://codeql.github.com/codeql-query-help/java/java-zipslip/) & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.ZipSlip)
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/16
Co-authored-by: Moderne <team@moderne.io>
diff --git a/testng-core/src/main/java/org/testng/JarFileUtils.java b/testng-core/src/main/java/org/testng/JarFileUtils.java
index 87237dfd..ff0cf32b 100644
--- a/testng-core/src/main/java/org/testng/JarFileUtils.java
+++ b/testng-core/src/main/java/org/testng/JarFileUtils.java
@@ -76,6 +76,9 @@ class JarFileUtils {
if (Parser.canParse(jeName.toLowerCase())) {
InputStream inputStream = jf.getInputStream(je);
File copyFile = new File(file, jeName);
+ if (!copyFile.toPath().normalize().startsWith(file.toPath().normalize())) {
+ throw new IOException("Bad zip entry");
+ }
copyFile.getParentFile().mkdirs();
Files.copy(inputStream, copyFile.toPath());
if (matchesXmlPathInJar(je)) {
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dedewu/testng.git
git@gitee.com:dedewu/testng.git
dedewu
testng
testng
master

搜索帮助

Cb406eda 1850385 E526c682 1850385