fix(unikontainers): validate containerID before path construction#773
Closed
Syedowais312 wants to merge 1 commit into
Closed
fix(unikontainers): validate containerID before path construction#773Syedowais312 wants to merge 1 commit into
Syedowais312 wants to merge 1 commit into
Conversation
✅ Deploy Preview for urunc canceled.
|
Author
|
Hey @cmainas, Also for the securejoin improvement we discussed in the issue, would you prefer that as a separate PR after this one, since it would involve changes across multiple path construction sites? |
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
4ebffce to
175fee5
Compare
Contributor
|
Duplicate with #726 |
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.
Description
Constructing a
containerDirpath from an unvalidatedcontainerIDbefore callingfilepath.Join+os.RemoveAllis a path traversal risk. A malicious ID like../../etc/cron.dpasses throughfilepath.Joinunchanged and escapesrootDir.This PR adds
ValidateIDtopkg/unikontainers, mirroring runc'svalidateIDinlibcontainer/factory_linux.go. Allowed characters:a-z A-Z 0-9 _ + - .Changes:
ValidateIDandErrInvalidContainerIDtopkg/unikontainers/unikontainers.goValidateIDat the top ofNew()andGet()wherefilepath.Join(rootDir, containerID)actually executesValidateIDin theErrNotExistfallback indelete.gothe original bug site. This branch re-readscontainerIDfrom args and callsos.RemoveAlldirectly without going throughNeworGetgetUnikontainer()andcreateUnikontainer()at the cmd layer for fast failuresession.goin the containerd-shim is intentionally not touchedcontainerIDthere comes from the containerd API, not raw CLI input.Related issues
How was this tested?
Built two binaries from the same codebase one before and one after the patch and ran both against a malicious container ID:
LLM usage
N/A
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).My changes only add input validation before path construction and do not affect container execution logic, so e2e behavior is unchanged.