Stop ADD from following symlinks outside the context when passed as the first argument

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)

Docker-DCO-1.1-Signed-off-by: Tianon Gravi <admwiggin@gmail.com> (github: crosbymichael)
Upstream-commit: ad6983624745cbb7c8f5bd7fd22c68f190b42004
Component: engine
This commit is contained in:
Tianon Gravi
2014-01-11 05:46:11 -07:00
committed by Michael Crosby
parent 1b47d0f1c6
commit 5171dc92dc

View File

@ -287,6 +287,11 @@ func (b *buildFile) CmdVolume(args string) error {
func (b *buildFile) checkPathForAddition(orig string) error {
origPath := path.Join(b.contextPath, orig)
if p, err := filepath.EvalSymlinks(origPath); err != nil {
return err
} else {
origPath = p
}
if !strings.HasPrefix(origPath, b.contextPath) {
return fmt.Errorf("Forbidden path outside the build context: %s (%s)", orig, origPath)
}