object/file: reject object keys that escape the filestore root - #7402
Closed
carfeii wants to merge 3 commits into
Closed
object/file: reject object keys that escape the filestore root#7402carfeii wants to merge 3 commits into
carfeii wants to merge 3 commits into
Conversation
filestore builds each operation's target path by joining an object key directly onto the configured root, with no validation. Since juicefs sync <source> file:///local/destination/ is a documented, ordinary usage pattern, and the object keys enumerated during a sync come from the source backend's own listing (which, unlike a real local filesystem walk, has no character restrictions), a key containing ../ segments causes data to be written outside the intended local destination directory. Add safePath, wrapping the existing path helper with a containment check (using filepath.Rel against the storage root, or the root's parent directory when root is used as a flat-namespace prefix rather than a directory, matching both of path's existing modes). Update all 8 call sites (Put, Get, Head, Delete, Chmod, Chown, Symlink, Readlink) to use it. Adds a regression test (TestFilestoreRejectsKeyPathTraversal).
Route filestore path resolution through one checked helper so Chtimes and future callers reject keys that escape the storage root. Also reject escaping List prefixes before opening local directories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Gogs seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Move the new filestore traversal coverage into file_test.go and update the new test file header year to match the repository license format. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Hi @carfeii please sign the cla. |
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.
Fixes #7401.
filestore builds each operation's target path by joining an object key directly onto the configured root, with no validation. Since
juicefs sync <source> file:///local/destination/is a documented, ordinary usage pattern, and the object keys enumerated during a sync come from the source backend's own listing (which, unlike a real local filesystem walk, has no character restrictions), a key containing../segments causes data to be written outside the intended local destination directory.Adds
safePath, wrapping the existingpathhelper with a containment check (usingfilepath.Relagainst the storage root, or the root's parent directory when root is used as a flat-namespace prefix rather than a directory, matching both ofpath's existing modes). Updates all 8 call sites (Put,Get,Head,Delete,Chmod,Chown,Symlink,Readlink) to use it.Adds a regression test (
TestFilestoreRejectsKeyPathTraversal).Verified against a scratch store: a key of
../outside/pwned.txtwritten viaPutescaped the configured root before this fix, confirmed via direct filesystem inspection; after the fix, the same call is rejected with a clear error and no file escapes.go test ./pkg/object/... ./pkg/sync/...all pass.