Repository navigation
Add safe-links handling and tests - #1132
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut depth: i64 = 0; | ||
| for component in link_relative.components() { | ||
| match component { | ||
| Component::ParentDir => depth = 0, | ||
| Component::CurDir => {} | ||
| Component::Normal(_) => depth += 1, | ||
| Component::RootDir | Component::Prefix(_) => depth = 0, | ||
| } | ||
| } | ||
|
|
||
| for component in target.components() { | ||
| match component { | ||
| Component::ParentDir => { | ||
| depth -= 1; | ||
| if depth < 0 { | ||
| return false; | ||
| } | ||
| } | ||
| Component::CurDir => {} | ||
| Component::Normal(_) => depth += 1, | ||
| Component::RootDir | Component::Prefix(_) => return false, | ||
| } | ||
| } |
There was a problem hiding this comment.
Safe-links allows '../' symlinks to escape root
The safety check bases its starting depth on link_relative.components() including the symlink file name. For a link at the transfer root (link_relative = "link") that points to ../etc/passwd, depth starts at 1, the single ParentDir never drives it negative, and symlink_target_is_safe returns true. The caller therefore copies the symlink even though --safe-links should skip it because it points outside the destination tree. Any symlink in a subdirectory with exactly one extra .. component is also misclassified as safe. The depth should be computed from the link’s parent directory, not including the file name, so that a single .. from the root triggers an unsafe result.
Useful? React with 👍 / 👎.
Summary
--safe-linksflag through the CLI configuration and remote fallback argumentsTesting