fix(security): harden symlink target validation during extraction#371
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom Mar 23, 2026
Merged
Conversation
Reviewer's GuideHardens archive extraction security by canonicalizing paths and validating both extracted file locations and symlink targets against the real filesystem under the configured extraction root, and by enabling stricter libarchive security flags. Sequence diagram for LibminizipPlugin extraction with hardened path checkssequenceDiagram
actor Caller
participant LibminizipPlugin
participant ExtractionSecurityHelpers
Caller->>LibminizipPlugin: extractEntry(zipfile, file_info, options)
LibminizipPlugin->>LibminizipPlugin: normalize strFileName (strip ../, replace \)
LibminizipPlugin->>LibminizipPlugin: build strDestFileName
LibminizipPlugin->>LibminizipPlugin: compute cleanTargetPath, cleanDestPath
LibminizipPlugin-->>Caller: ET_FileWriteError (if cleanDestPath outside cleanTargetPath)
LibminizipPlugin->>ExtractionSecurityHelpers: extractPathIsWithinTarget(options.strTargetPath, strDestFileName)
ExtractionSecurityHelpers-->>LibminizipPlugin: allowed / rejected
LibminizipPlugin-->>Caller: ET_FileWriteError (if rejected)
LibminizipPlugin->>LibminizipPlugin: continue with file creation and data extraction
Sequence diagram for LibzipPlugin symlink creation with target validationsequenceDiagram
actor Caller
participant LibzipPlugin
participant ExtractionSecurityHelpers
participant zipFile
Caller->>LibzipPlugin: extractEntry(archive, index, options)
LibzipPlugin->>LibzipPlugin: compute strDestFileName under options.strTargetPath
LibzipPlugin->>ExtractionSecurityHelpers: extractPathIsWithinTarget(options.strTargetPath, strDestFileName)
ExtractionSecurityHelpers-->>LibzipPlugin: allowed / rejected
LibzipPlugin-->>Caller: ET_FileWriteError (if rejected)
LibzipPlugin->>zipFile: zip_fopen / zip_fread (symlink contents)
zipFile-->>LibzipPlugin: strBuf (symlinkTarget)
LibzipPlugin->>ExtractionSecurityHelpers: symlinkTargetIsWithinTarget(options.strTargetPath, strDestFileName, strBuf)
ExtractionSecurityHelpers-->>LibzipPlugin: allowed / rejected
LibzipPlugin-->>Caller: ET_FileWriteError (if rejected)
LibzipPlugin->>LibzipPlugin: QFile::link(strBuf, strDestFileName) (if allowed)
Class diagram for updated extraction security helpers and plugin usageclassDiagram
class LibminizipPlugin {
+ErrorType extractEntry(unzFile zipfile, unz_file_info file_info, const ExtractOptions &options)
}
class LibzipPlugin {
+ErrorType extractEntry(zip_t *archive, zip_int64_t index, const ExtractOptions &options)
}
class LibarchivePlugin {
+int extractionFlags() const
}
class ExtractionSecurityHelpers {
+bool extractPathIsWithinTarget(QString extractRoot, QString absoluteDestPath)
+bool symlinkTargetIsWithinTarget(QString extractRoot, QString symlinkFilePath, QString symlinkTarget)
}
LibminizipPlugin ..> ExtractionSecurityHelpers : uses
LibzipPlugin ..> ExtractionSecurityHelpers : uses
LibarchivePlugin ..> ExtractionSecurityHelpers : strengthened_flags
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
../stripping inLibminizipPlugin::extractEntryis a naive substring replacement that can mangle legitimate names containing"../"and doesn’t operate on path components; consider normalizing viaQDir::cleanPathor explicit component-wise filtering of".."segments instead. extractPathIsWithinTargetrelies oncanonicalFilePath()ofextractRootand returnsfalsewhen the root doesn’t exist yet, which may inadvertently break extracting into a not-yet-created directory; if that’s a valid use case, ensure the root directory is created/validated earlier or handle a non-existent root more explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `../` stripping in `LibminizipPlugin::extractEntry` is a naive substring replacement that can mangle legitimate names containing `"../"` and doesn’t operate on path components; consider normalizing via `QDir::cleanPath` or explicit component-wise filtering of `".."` segments instead.
- `extractPathIsWithinTarget` relies on `canonicalFilePath()` of `extractRoot` and returns `false` when the root doesn’t exist yet, which may inadvertently break extracting into a not-yet-created directory; if that’s a valid use case, ensure the root directory is created/validated earlier or handle a non-existent root more explicitly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
max-lvs
approved these changes
Mar 23, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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 |
Contributor
Author
|
/merge |
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.
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
Summary by Sourcery
Harden archive extraction to prevent path traversal and symlink-based escapes from the target directory across all supported backends.
Bug Fixes:
Enhancements: