fix(unikontainers): secure container state paths - #973
Open
tagadearpit wants to merge 1 commit into
Open
Conversation
Replace filepath.Join with SecureJoin for container state directories so symlinks cannot redirect state access outside the configured root. Add regression coverage for Get and harden the delete fallback path. Fixes: urunc-dev#791 Signed-off-by: tagadearpit <[email protected]>
✅ Deploy Preview for urunc canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a symlink-based escape in container-state path construction tracked by #791.
New,Get, and the delete-command fallback previously usedfilepath.Join(rootDir, containerID). Although container IDs reject traversal characters, a valid ID can still name a symlink that points outsiderootDir. State reads and cleanup operations could then follow that symlink outside the configured container-state directory.This change uses the existing
github.com/cyphar/filepath-securejoindependency for all three path-construction sites and returns a resolution error before reading or removing state. It also addsTestGetRejectsContainerDirSymlink, which creates a symlinked container directory and verifies thatGetcannot access the outside state file. The authenticated contributor is included in.github/contributors.yamlas required by the project contribution guide.Related issues
How was this tested?
The following checks pass:
A full
go test ./...run reaches the external e2e suites but cannot complete in this environment becausectr,nerdctl,docker, andcrictlare unavailable. The repository-wide compile-only test pass succeeds.LLM usage
This pull request was prepared with assistance from OpenAI GPT-5. The contributor reviewed the generated changes, reproduced the reported behavior, and ran the relevant tests and static checks.
Checklist
make lint); the repository’s container-based linter is unavailable in this environment.make test_ctr,make test_nerdctl,make test_docker,make test_crictl); the required external tools are unavailable in this environment.