fix: prevent Zip Slip path traversal in backup restore#2205
Open
Marnie0415 wants to merge 1 commit into
Open
Conversation
The _restoreTask function joins the zip entry name directly to the restore directory path without validating that the resolved path stays within the target directory. A malicious backup file with entries like "../../etc/cron.d/backdoor" could write files outside the restore directory. Add path resolution check: normalize the full output path and verify it starts with the normalized restore directory before writing.
Marnie0415
force-pushed
the
fix/zip-slip-path-traversal
branch
from
July 10, 2026 18:28
fca32f5 to
640e432
Compare
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.
Problem
lib/common/task.dart:551joins zip entry names directly to the restore directory path without path traversal validation:posix.normalizeonly cleans up path syntax — it does not prevent..traversal. A malicious backup file with an entry named../../etc/cron.d/backdoorwould write outside the restore directory.Attack scenario
.zipbackup file with path traversal entriesThis is a well-known vulnerability class (Zip Slip, CWE-22).
Fix
Resolve the full output path and verify it stays within the restore directory:
Design decisions
Why
normalize()instead ofposix.normalize()?restoreDirPathis a platform-specific path (backslashes on Windows).posix.normalizeonly handles forward slashes and would produce incorrect results on Windows.normalize()frompackage:path/path.dartis platform-aware — it uses the OS path separator and correctly resolves..on all platforms.Why normalize both paths?
restoreDirPathcomes fromappPath.restoreDirPathwhich isjoin(homeDirPath, 'restore'). While it's already clean, normalizing both paths ensures consistency — ifhomeDirPathever contains..or redundant separators, the comparison still works correctly.Why
join()+normalize()instead of justjoin()?join()does not resolve..components.join('/restore', '../../etc')produces/restore/../../etc, which the OS would resolve to/etc.normalize()resolves this to/etcin Dart, so thestartsWithcheck catches the escape.Cross-platform behavior:
normalize('/home/user/restore/../../etc')→/etc— fails checknormalize('C:\\Users\\restore\\..\\..\\Windows')→C:\\Windows— fails checkjoin('C:\\restore', '../../etc')→C:\\restore\\..\\..\\etc→normalize→C:\\etc— fails check