Skip to content

common: fix path containment corner cases in passdriver#854

Open
caxu-rh wants to merge 1 commit into
containers:mainfrom
caxu-rh:passdriver-path-containment
Open

common: fix path containment corner cases in passdriver#854
caxu-rh wants to merge 1 commit into
containers:mainfrom
caxu-rh:passdriver-path-containment

Conversation

@caxu-rh
Copy link
Copy Markdown
Contributor

@caxu-rh caxu-rh commented May 18, 2026

With the current implementation of getPath, it's possible to return a path outside the root directory, matching a sibling directory instead through a crafted/specific id.

For example: with a root directory of /tmp/root, an id of ../rootx/foo could yield an invalid path of /tmp/rootx/foo.

id is random/not user-controlled (as far as I can tell), so I consider this more to be for the benefit of hardening/correctness (arguably, if we trust id, we don't need the strings.HasPrefix check either, since we just constructed it).

@github-actions github-actions Bot added the common Related to "common" package label May 18, 2026
@packit-as-a-service
Copy link
Copy Markdown

Packit jobs failed. @containers/packit-build please check.

Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment thread common/pkg/secrets/passdriver/passdriver.go Outdated
Comment thread common/pkg/secrets/passdriver/passdriver.go Outdated
Comment thread common/pkg/secrets/passdriver/passdriver_test.go Outdated
With the current implementation of getPath, it's possible
to return a path outside the root directory, matching
a sibling directory instead through a crafted/specific id.

Signed-off-by: Caleb Xu <caxu@redhat.com>
@caxu-rh caxu-rh force-pushed the passdriver-path-containment branch from 8c11bfb to 709c573 Compare May 18, 2026 18:10
Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

gpghomedir := filepath.Join(tmpdir, "gpg")
require.NoError(t, os.MkdirAll(base, 0o755))
require.NoError(t, os.MkdirAll(sibling, 0o755))
require.NoError(t, os.MkdirAll(gpghomedir, 0o755))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(It would have been simpler to leave this as t.TempDir().)

Copy link
Copy Markdown
Contributor Author

@caxu-rh caxu-rh May 18, 2026

Choose a reason for hiding this comment

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

I could move gpghomedir into its own t.TempDir(), but sibling needs to be named after base. It helps to have the base name well-known as well, so that the key can just be ../storex/... rather than needing to dynamically build the key based on the t.TempDir() name. I also wanted to make sure sibling gets cleaned up, hence not putting just manually mkdir'ing sibling after the t.TempDir() creation.

(Then again, I don't think any of the tests actually depend on sibling dir to exist, so maybe we could just skip the creation altogether, but oh well. Happy to simplify once more, if you think its worth it.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m sorry, I did mean the gpghomedir one only.

Anyway, this is fine as is, let’s wait for a second reviewer.

@caxu-rh
Copy link
Copy Markdown
Contributor Author

caxu-rh commented May 18, 2026

Thanks for the feedback. Yes, I was hoping to also cover the non-absolute/symlink root cases hence the more convoluted fix. Switched to the simpler approach since it sounds like that's not a concern for now.

I tried to combine the test setup logic so that the individual cases can be covered in the other tests in that file. Might be a bit clunky, let me know if you'd prefer that to be handled differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants