Change path breakout detection logic in archive package
Fixes #9375 Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
This commit is contained in:
parent
4e3563a9b6
commit
2ebf95a81e
2 changed files with 13 additions and 8 deletions
|
@ -530,10 +530,13 @@ loop:
|
|||
}
|
||||
}
|
||||
|
||||
// Prevent symlink breakout
|
||||
path := filepath.Join(dest, hdr.Name)
|
||||
if !strings.HasPrefix(path, dest) {
|
||||
return breakoutError(fmt.Errorf("%q is outside of %q", path, dest))
|
||||
rel, err := filepath.Rel(dest, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.HasPrefix(rel, "..") {
|
||||
return breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest))
|
||||
}
|
||||
|
||||
// If path exits we almost always just want to remove and replace it
|
||||
|
|
|
@ -92,12 +92,14 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
|
|||
}
|
||||
|
||||
path := filepath.Join(dest, hdr.Name)
|
||||
base := filepath.Base(path)
|
||||
|
||||
// Prevent symlink breakout
|
||||
if !strings.HasPrefix(path, dest) {
|
||||
return breakoutError(fmt.Errorf("%q is outside of %q", path, dest))
|
||||
rel, err := filepath.Rel(dest, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.HasPrefix(rel, "..") {
|
||||
return breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest))
|
||||
}
|
||||
base := filepath.Base(path)
|
||||
|
||||
if strings.HasPrefix(base, ".wh.") {
|
||||
originalBase := base[len(".wh."):]
|
||||
|
|
Loading…
Reference in a new issue