Fix path traversal in download_external_data containment guard - #2486
Open
lollinng wants to merge 1 commit into
Open
Fix path traversal in download_external_data containment guard#2486lollinng wants to merge 1 commit into
lollinng wants to merge 1 commit into
Conversation
Contributor
|
Thanks for the contribution! Can you sign CLA (link above). Also, can you clarify how you came about this issue? Specifically, how are you using |
Author
|
signed |
The guard computed path = data_dir / item.local_data_path and rejected it only if data_dir not in path.parents. pathlib does not normalize "..", so "../evil.bin" yields "/data/../evil.bin" which still has data_dir in .parents and passes -- yet the download paths below call .resolve() and write to "/evil.bin", outside data_dir. Resolve before the containment check. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lollinng
force-pushed
the
fix/external-data-path-traversal
branch
from
June 5, 2026 20:55
70ef985 to
5a25515
Compare
Contributor
|
Can you clarify how you came about this issue? Specifically, how are you using truss and this utility today? |
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 (path traversal)
download_external_datavalidates each external-data item before downloading:pathlibdoes not normalize.., so forlocal_data_path = "../evil.bin":path = data_dir / "../evil.bin"→Path("/data/../evil.bin")path.parentsstill containsdata_dir(/data), so the guard passes.But the actual download paths resolve first —
_download_external_data_using_b10cpand_download_external_data_using_requestsboth compute(data_dir / item.local_data_path).resolve()— which for../evil.binis/evil.bin, outsidedata_dir. So a malicious/compromised model config can write arbitrary files outside the data directory.Repro (CPU)
model.bin/data/model.bin../evil.bin/evil.bin../../etc/passwd/private/etc/passwdFix
Resolve the path before the containment check and compare against the resolved
data_dir:After the fix,
../evil.binand../../etc/passwdare correctly rejected whilemodel.bin,a/b/model.bin,./x.binstill pass.ruff check/ruff formatclean.