fix tar extraction add path validation to prevent escape from destination #4020
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.
Description
This fixes addresses path traversal vulnerabilities in tar archive extraction within the
kindcodebase. Without proper validation, specially crafted tar entries could escape the intended extraction directory and overwrite arbitrary files on the host system. This PR introduces safeguards to ensure that extracted files remain confined to the target directory.kind/pkg/cluster/internal/logs/logs.go
Lines 77 to 97 in f20102c
Issue: Tar archive entries are written to paths derived directly from the archive without validation. Attackers could craft entries with
..or absolute paths to escape the destination directory.filepath.Absandfilepath.Clean.os.Create,os.MkdirAll).kind/pkg/build/nodeimage/internal/kube/tar.go
Lines 44 to 49 in f20102c
untar, the function does not validatehdr.Name, allowing malicious tar entries to escape the intended destination.hdr.Namewith the target directory, normalize the path usingfilepath.Clean...segments that lead outside the extraction directory.strings.HasPrefix(cleanedPath, cleanedDestDir + string(os.PathSeparator))to enforce confinement.Notes Refferences
filepath,os, andstringspackages.