fix(storage): block path traversal in file-download (GHSA-6px9-99p6-7j7g, 0.60.1) - #409
Merged
Conversation
`storage file-download` wrote the downloaded bytes to the Storage API's `file_detail["name"]` verbatim when --output was omitted. A malicious or compromised API response (e.g. a file in a shared/invited project) with a name like `../../../../.zshrc` -- or an absolute path -- could overwrite an arbitrary file on the user's machine with attacker-controlled content, a clean write-to-RCE primitive. Add `_safe_download_target()`: strip leading separators (an absolute name can no longer override the target), preserve legitimate nested subpaths, and assert the resolved path stays within the chosen directory (CWD or the --output dir) via resolve() + is_relative_to(), rejecting escapes with INVALID_ARGUMENT. Explicit `--output FILE` is unchanged (trusted user input). Private advisory GHSA-6px9-99p6-7j7g.
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.
Summary
Fixes a path-traversal arbitrary-file-write in
kbagent storage file-download— finding H2 from the 2026-06-12 security audit (private advisory GHSA-6px9-99p6-7j7g).When
--outputwas omitted, the downloaded bytes were written to the Storage API'sfile_detail["name"]verbatim (storage_service.py:1746/1770→client.download_filewhich doesout_path.parent.mkdir(parents=True)). A malicious or compromised API response (e.g. a file in a shared/invited project, wherenamelabels are loosely constrained) with a name like../../../../.zshrc— or an absolute path like/Users/victim/Library/LaunchAgents/x.plist— could overwrite an arbitrary file on the user's machine with fully attacker-controlled content. A clean write-to-RCE primitive.Fix
New
_safe_download_target(base, server_name)helper instorage_service:exports/2026/report.csvstill creates the subdir, as before);--outputdirectory) viaresolve()+is_relative_to(), rejecting escapes withINVALID_ARGUMENT.Explicit
--output FILEis unchanged — it is the user's own trusted choice. For honest file names behavior is identical to before; only..// absolute escapes are blocked, so no regression for legitimate use.Tests
New
TestDownloadFilePathTraversal(4 cases): rejects../escape with and without an--outputdirectory, neutralizes absolute names under CWD, and preserves benign nested names. Full suite green: 3959 passed, 132 skipped; lint/format/ty/changelog-check clean.Audit context
The other HIGH finding (auto-update artifact integrity, GHSA-3322-j9h9-mg9p) was accepted as residual risk by the repo owner (GitHub as trust root; silent auto-update retained as the patch-delivery channel) and closed won't-fix. The remaining MEDIUM/LOW advisories stay open as draft for separate triage.