fix: prevent path traversal in DownloadActionOutputs and validate symlink targets#650
Open
mohammadmseet-hue wants to merge 1 commit into
Open
Conversation
…ownloadOutputs Two path traversal variants were found in the download path: 1. DownloadActionOutputs passes dir.Path from the ActionResult proto directly to os.RemoveAll via filepath.Join, without validating it through getAbsPath. A malicious remote server could set dir.Path to "../../important_data" to delete arbitrary directories on the client. 2. DownloadOutputs creates symlinks without validating that the symlink target stays within the output directory. A malicious remote server could set SymlinkTarget to "/etc/shadow" or "../../../../etc/passwd" to create symlinks pointing outside the output directory, enabling arbitrary file read/write through symlink following. Both fixes use the same getAbsPath validation introduced in the previous path traversal fix, ensuring all server-controlled paths are validated before use.
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
Two additional path traversal vectors were found in the download code path, both variants of the issue previously fixed in
getAbsPath:1.
DownloadActionOutputs:os.RemoveAllwith unvalidateddir.PathDownloadActionOutputspassesdir.Pathfrom theActionResultproto directly toos.RemoveAllviafilepath.Join, bypassinggetAbsPathvalidation. A malicious remote execution server could setOutputDirectories[].Pathto../../important_datato delete arbitrary directories on the client filesystem.The deletion happens at line 525 before
DownloadOutputs(which validates paths viagetAbsPath) is called at line 529.2.
DownloadOutputs: Symlink target not validated for containmentWhen creating symlinks from remote server output, the symlink placement path (
out.Path) is validated viagetAbsPath, but the symlink target (out.SymlinkTarget) is used directly from the proto without any validation. A malicious server can setSymlinkTargetto/etc/shadowor../../../../etc/passwd, creating symlinks inside the output directory that point to arbitrary locations on the filesystem.Fixes
getAbsPathvalidation inDownloadActionOutputsbeforeos.RemoveAllDownloadOutputsusing the same separator-aware prefix check asgetAbsPath