[deckhouse-cli] Reject tar entries escaping the target directory in mirror bundle unpack - #474
Draft
Fkuloff wants to merge 2 commits into
Draft
[deckhouse-cli] Reject tar entries escaping the target directory in mirror bundle unpack#474Fkuloff wants to merge 2 commits into
Fkuloff wants to merge 2 commits into
Conversation
…irror bundle unpack Signed-off-by: Artem Kuleshov <artem.kuleshov@flant.com>
Signed-off-by: Artem Kuleshov <artem.kuleshov@flant.com>
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
bundle.Unpack(used byd8 mirror push) built the on-disk path of every archive entry withfilepath.Join(targetPath, "tmp", filepath.Clean(hdr.Name)).Cleankeeps a leading.., so an entry named../../xwas written outside the target directory. The same loop dereferenced the tar header before checking a non-EOF error fromtar.Reader.Next, which panics on a corrupt archive.Problem
d8 mirror push <bundle>unpacks every.tarit is given before anything is pushed; an entry with..segments escapes the unpack directory and creates or truncates a file on the operator's hostd8with a nil-pointer dereference instead of an errorFix
safeJoin(root, name), private to the bundle package like the guards in the other extractors: joins and rejects a result that leavesroot(filepath.Relcheck, as in deckhouse-controller); the check is lexical, andUnpackmaterializes regular files only, so no symlink can redirect itUnpackresolves the write path through it and fails the whole archive on the first escaping entry, before anything is writtentar.Reader.Nexterrors other thanio.EOFare returnedtmpDir) instead of three timesBefore / After
Real binaries built from
mainand from this branch, one-entry bundle with../../../../../ESCAPED/pwn, local registry:Tests
TestSafeJoin— accepted:a/b,dir/foo..bar,a/../b,/abs/x; rejected:..,../x,a/../../xTestUnpackRejectsPathTraversal— the archive fails and nothing is written inside or outside the unpack directoryTestUnpackRejectsCorruptArchive— garbage input returns an errormakeIndexTarnow delegates its tar-writing tail to the newmakeFileTar; existing tests unchangedNotes
tar.NewReaderusers in the CLI compare entry names or read entries into memory and never write an entry path to disk;internal/packagecmd/.../imagefsandinternal/cr/.../imagefskeep the guards they already havefilepath.Joinplaces them under the target directory