Merged
Conversation
- 修复Unzip类中的Zip Slip路径遍历漏洞(CWE-22) - 使用Java NIO Path API进行安全的路径规范化 - 添加绝对路径检查,防止路径注入攻击 - 使用Path.startsWith()替代字符串比较,更安全可靠 - 重构测试用例,动态生成ZIP文件,避免提交二进制文件 - 统一测试目录结构到src/test/resources/zip-slip-test/ - 添加自动清理机制,测试后删除所有临时文件 - 新增4个安全测试用例,覆盖多种路径遍历场景 - 多级父目录遍历攻击测试 - 绝对路径注入测试 - 路径中间遍历测试 - 安全嵌套路径正向测试 所有测试通过(15/15) ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 相关问题 / Related Issue
说明 / Note: 这是一个安全漏洞修复(Zip Slip - CVE),根据安全最佳实践,不需要提前创建公开Issue以避免漏洞被利用。
📋 变更类型 / Type of Change
📝 变更目的 / Purpose of the Change
修复
Unzip类中存在的 Zip Slip 路径遍历漏洞(CWE-22),该漏洞由 GitHub CodeQL 安全扫描检测发现(Alert #14)。漏洞危害:
..路径遍历或绝对路径,将文件写入到目标目录之外的任意位置修复方案:
Path.startsWith()替代字符串比较,基于路径段验证📋 主要变更 / Brief Changelog
安全修复
Unzip.getTarget()方法中的路径遍历漏洞/、\或驱动器字母开头的路径Path.normalize()规范化路径Path.startsWith()验证解压路径在目标目录内测试优化
src/test/resources/zip-slip-test/../../../../../../etc/passwd)/tmp/unauthorized-file.txt)subdir/../../../unauthorized.txt)🧪 验证变更 / Verifying this Change
测试步骤 / Test Steps
运行单元测试验证修复效果:
mvn test -Dtest=UnZipTest验证恶意ZIP文件被正确拦截:
# 测试会自动创建包含路径遍历的恶意ZIP,验证抛出SecurityException验证正常ZIP文件解压不受影响:
# 测试包含安全路径的正向测试用例测试覆盖 / Test Coverage
测试结果:
✅ 贡献者检查清单 / Contributor Checklist
基本要求 / Basic Requirements:
代码质量 / Code Quality:
测试要求 / Testing Requirements:
mvn -B clean package -Dmaven.test.skip=true/ Basic checks passmvn clean install/ Unit tests pass文档和兼容性 / Documentation and Compatibility:
📋 附加信息 / Additional Notes
安全影响
error级别Unzip类解压ZIP文件的代码兼容性说明
参考资料
审查者注意事项 / Reviewer Notes:
Unzip.java中getTarget()和getActualTarget()方法的路径验证逻辑UnZipTest确保所有安全测试用例通过