feat: Synchronize the V20 security vulnerability fix to V25#411
Conversation
Reviewer's GuideSynchronizes previously implemented security hardening for archive extraction into the V25 branch by tightening path validation, normalizing extracted filenames, and enabling stricter libarchive extraction flags to prevent directory traversal and symlink escape vulnerabilities. Sequence diagram for secured path validation in LibzipPlugin::extractEntrysequenceDiagram
participant LibzipPlugin as LibzipPlugin::extractEntry
participant Common as extractPathIsWithinTarget
participant QFile as QFile
LibzipPlugin->>LibzipPlugin: build strDestFileName
LibzipPlugin->>Common: extractPathIsWithinTarget(options.strTargetPath, strDestFileName)
alt [path is within target]
Common-->>LibzipPlugin: true
LibzipPlugin->>QFile: QFile(strDestFileName)
LibzipPlugin->>QFile: open(QIODevice::WriteOnly)
QFile-->>LibzipPlugin: write handle
LibzipPlugin->>LibzipPlugin: write extracted data
else [symlink escape or invalid path]
Common-->>LibzipPlugin: false
LibzipPlugin->>LibzipPlugin: return ET_FileWriteError
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
strFileNamesanitization inLibminizipPlugin::extractEntryrepeatedly replacing"../"substrings is quite ad-hoc and may mangle legitimate names (e.g.".../file"); consider usingQDir::cleanPathon a normalized, forward-slash-only path and then rejecting any cleaned path that starts with"../"or is absolute instead of textually stripping components. - In
extractPathIsWithinTarget, it would be safer to normalize bothrootCanonand the candidate path (e.g. removing trailing separators, normalizing case where relevant) before thestartsWithcomparison to avoid edge cases around paths like/tmp/rootvs/tmp/root2or paths with trailing slashes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `strFileName` sanitization in `LibminizipPlugin::extractEntry` repeatedly replacing `"../"` substrings is quite ad-hoc and may mangle legitimate names (e.g. `".../file"`); consider using `QDir::cleanPath` on a normalized, forward-slash-only path and then rejecting any cleaned path that starts with `"../"` or is absolute instead of textually stripping components.
- In `extractPathIsWithinTarget`, it would be safer to normalize both `rootCanon` and the candidate path (e.g. removing trailing separators, normalizing case where relevant) before the `startsWith` comparison to avoid edge cases around paths like `/tmp/root` vs `/tmp/root2` or paths with trailing slashes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
TAG Bot New tag: 6.5.28 |
Resolve symlink escape checks against real filesystem paths by validating the first existing path component with canonical resolution. This closes a bypass where lexical path checks could be fooled by pre-existing symlinks while keeping extraction behavior and performance stable. log: fix cnnvd Bug: https://pms.uniontech.com/bug-view-353989.html https://pms.uniontech.com/bug-view-353985.html
…file writes (linuxdeepin#381) - Remove strict validation during symlink creation to allow legitimate symlinks to system paths - Keep path validation during file writes using canonicalFilePath() to resolve symbolic links - Remove symlinkTargetIsWithinTarget function to simplify security check logic - Fix over-blocking issue while preventing Zip Slip attacks Before fix: lib.so -> /usr/lib/xxx was incorrectly rejected After fix: Symlink creation succeeds, writing to system files via symlinks is blocke Bug:https://pms.uniontech.com/bug-view-356233.html
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review这份代码的主要目的是修复解压缩时的路径遍历和符号链接逃逸漏洞,这是一个非常关键的安全修复。整体思路是正确的:在底层库层面增加安全标志,在业务代码层面增加路径校验。 但在代码逻辑、安全性和性能方面存在一些需要改进的地方。以下是详细的审查意见: 1. 语法与逻辑问题 1.1:
问题 1.2:
2. 代码安全问题 2.1:
问题 2.2:跨平台路径分隔符处理不一致
问题 2.3:版权声明修改
3. 代码性能问题 3.1:
💡 改进后的代码建议1.
|
|
/merge |
cherry-pick
0116e20 fix(security): allow symlink creation, check path escape only during file writes (#381)
e3f6b70 fix(security): harden symlink target validation during extraction
task: https://pms.uniontech.com/task-view-389585.html
Summary by Sourcery
Harden archive extraction security to prevent path traversal and symlink-based escapes from the extraction root.
Bug Fixes:
Enhancements: