Repository navigation
Conversation
Sanitize and validate relative item paths in LocalDestination::path to prevent directory traversal attacks when restoring snapshots. Previously, LocalDestination::path concatenated item paths via self.path.join(item) (or self.path.join directly in create_dir). If a snapshot or archive contained absolute paths or traversal components (such as '..' or leading '/'), the resolved path escaped the destination root directory, allowing arbitrary file creation, truncation, permission modifications, or writes outside the intended restore location. Changes: - Added LocalDestinationErrorKind::ItemPathEscapesDestination(PathBuf). - Validated item components in LocalDestination::path fail-closed against Prefix, RootDir, and ParentDir components. - Hardened create_dir, write_at, hard_link, set_length, metadata helpers, and restore.rs call sites. - Added unit tests for path sanitization and traversal rejection. Reported-by: BS.ehlas.cz
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
LocalDestination::pathincrates/core/src/backend/local_destination.rsjoins relative item paths viaself.path.join(item)without sanitization (andcreate_dirwas previously doingself.path.join(item)directly).In Rust's
Path::join, ifitemcontains path traversal components (..) or is an absolute path (leading/or Windows drive prefix), the resulting path escapesself.path. When restoring an archive or snapshot containing crafted or malformed tree node paths, this allows writing, directory creation, truncating, hardlinking, and metadata modifications outside the intended destination directory.Fix
LocalDestinationErrorKind::ItemPathEscapesDestination(PathBuf).LocalDestination::pathto returnLocalDestinationResult<PathBuf>and inspect path components fail-closed: rejectsPrefix,RootDir, andParentDircomponents.create_dirto route throughself.path(item)?instead of uncheckedself.path.join(item).LocalDestinationandrestore.rsto propagate errors cleanly.Tests
test_path_sanitization: verifies valid relative paths succeed, while../escaped,../../etc/passwd,a/../../b, and/absolute/pathreturnItemPathEscapesDestination.test_operations_reject_traversal: verifiescreate_dir,write_at,read_at, andget_matching_filereject traversal paths without filesystem writes outside destination.cargo test -p rustic_core --test integration restore) passes.Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.