Show error on copied file above context directory in build#2149
Show error on copied file above context directory in build#2149rhatdan merged 1 commit intocontainers:masterfrom
Conversation
|
Didn't try locally but |
|
A couple of small nits, but CI system seems to be hosed up. |
imagebuildah/stage_executor.go
Outdated
| // directory. Also raise an error if the src escapes | ||
| // the context directory. | ||
| contextSrc, err := securejoin.SecureJoin(contextDir, src) | ||
| if strings.HasPrefix(src, "../") && err == nil { |
There was a problem hiding this comment.
nit: Should reverse order and check if err == nil first, for speed, although maybe compiler is smart enough.
There was a problem hiding this comment.
touched up here and line 445
There was a problem hiding this comment.
just reversed here and at line 445
| @@ -0,0 +1,3 @@ | |||
| This is a text file to be used in Buildah testing. | |||
| This will be used to ensure that a file from above the context | |||
| directory can not be copied during the buildh phase. | |||
There was a problem hiding this comment.
apparently a rogue space at the end of this line caused tests to be unhappy. Also touched up the "buildh" typo
When a COPY command in a Container file looked like "../file.txt"
SecureJoin would secure the file by lopping off the "../".
However, the code would then append that file name to the passed in
context directory and look for the file. That would fail as in most
cases there was no `{context-dir}/file.txt`, rather the file was at
`{context-dir}/../file.txt`. Using a relative directory like this
outside of the context directory can be a security risk. Docker
doesn't allow it nor should we.
This change now errors out when a file that starts with `../` is
presented as a copy from target.
Addresses: containers/podman#5035
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
dc9b5fc to
13dcf6d
Compare
|
Happy green test buttons |
|
bors r+ |
|
👎 Rejected by too few approved reviews |
|
bors retry |
2149: Show error on copied file above context directory in build r=rhatdan a=TomSweeneyRedHat
When a COPY command in a Container file looked like "../file.txt"
SecureJoin would secure the file by lopping off the "../".
However, the code would then append that file name to the passed in
context directory and look for the file. That would fail as in most
cases there was no `{context-dir}/file.txt`, rather the file was at
`{context-dir}/../file.txt`. Using a relative directory like this
outside of the context directory can be a security risk. Docker
doesn't allow it nor should we.
This change now errors out when a file that starts with `../` is
presented as a copy from target.
Addresses: containers/podman#5035
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Co-authored-by: TomSweeneyRedHat <tsweeney@redhat.com>
Build failed
|
|
Bors seems to be acting out, for no reason. Manually merging. |
When a COPY command in a Container file looked like "../file.txt"
SecureJoin would secure the file by lopping off the "../".
However, the code would then append that file name to the passed in
context directory and look for the file. That would fail as in most
cases there was no
{context-dir}/file.txt, rather the file was at{context-dir}/../file.txt. Using a relative directory like thisoutside of the context directory can be a security risk. Docker
doesn't allow it nor should we.
This change now errors out when a file that starts with
../ispresented as a copy from target.
Addresses: containers/podman#5035
Signed-off-by: TomSweeneyRedHat tsweeney@redhat.com