Fix path traversal bypass in ResolveLocalPath sandbox#9726
Open
nishantmonu51 wants to merge 1 commit into
Open
Fix path traversal bypass in ResolveLocalPath sandbox#9726nishantmonu51 wants to merge 1 commit into
ResolveLocalPath sandbox#9726nishantmonu51 wants to merge 1 commit into
Conversation
Clean the resolved path for both absolute and relative inputs, and use a separator-aware prefix check so sibling directories sharing the root's prefix no longer pass the sandbox. Claude-Session: https://claude.ai/code/session_01XWGRxG2FDSw2NgJEn7NmeE
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.
ResolveLocalPathis used as the file/DuckDB sandbox in hosted deployments (viaAllowHostAccess=false). Two defects let a project-suppliedpathescape the repo root:filepath.Clean, so..segments survived (filepath.Join, which cleans, only ran for relative paths).path: /repo/../../etc/passwdpassedHasPrefix("/repo/../../etc/passwd", "/repo")and resolved to/etc/passwd./data/proj123,path: ../proj123-x/secretcleaned to/data/proj123-x/secretand slipped through — a potential cross-tenant read.Fix:
filepath.Cleanthe resolved path for both the absolute and relative branches before the sandbox check.strings.HasPrefix(finalPath, root)withfinalPath == root || strings.HasPrefix(finalPath, root+separator), cleaningrootfirst.TestResolveLocalPathcovering absolute/relative traversal, both sibling-prefix variants, in-root paths, and theallowHostAccess=truepassthrough.Reproducing steps:
duckdbor localfileconnector withallow_host_access: false(the state hosted Rill Cloud runs the sandbox in).pathis an absolute path containing.., e.g.path: /<project_root>/../../etc/hosts./data/proj123, pointpathat../proj123-x/<file>and observe it previously resolved to a sibling tenant directory that still passed the prefix check.In code, the regression is captured by:
ResolveLocalPath("/root/../etc/x", "/root", false)— now returns an error.ResolveLocalPath("../root-x/secret", "/root", false)— now returns an error.Checklist: