Skip to content

Show error on copied file above context directory in build#2149

Merged
rhatdan merged 1 commit intocontainers:masterfrom
TomSweeneyRedHat:dev/tsweeney/upperescape
Feb 11, 2020
Merged

Show error on copied file above context directory in build#2149
rhatdan merged 1 commit intocontainers:masterfrom
TomSweeneyRedHat:dev/tsweeney/upperescape

Conversation

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

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

@vrothberg
Copy link
Copy Markdown
Member

[+0056s] ** ERROR: dangling whitespace found in these files: **

Didn't try locally but ** isn't very informative.

Copy link
Copy Markdown
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 10, 2020

A couple of small nits, but CI system seems to be hosed up.

// directory. Also raise an error if the src escapes
// the context directory.
contextSrc, err := securejoin.SecureJoin(contextDir, src)
if strings.HasPrefix(src, "../") && err == nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should reverse order and check if err == nil first, for speed, although maybe compiler is smart enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touched up here and line 445

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@TomSweeneyRedHat
Copy link
Copy Markdown
Member Author

Happy green test buttons

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 11, 2020

bors r+

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Feb 11, 2020

👎 Rejected by too few approved reviews

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 11, 2020

bors retry

bors bot added a commit that referenced this pull request Feb 11, 2020
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>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Feb 11, 2020

Build failed

  • cirrus-ci/success

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 11, 2020

Bors seems to be acting out, for no reason. Manually merging.

@rhatdan rhatdan merged commit 80b6a26 into containers:master Feb 11, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants