Skip to content

fix(unikontainers): validate containerID before path construction#773

Closed
Syedowais312 wants to merge 1 commit into
urunc-dev:mainfrom
Syedowais312:fix/validate-container-id
Closed

fix(unikontainers): validate containerID before path construction#773
Syedowais312 wants to merge 1 commit into
urunc-dev:mainfrom
Syedowais312:fix/validate-container-id

Conversation

@Syedowais312

Copy link
Copy Markdown

Description

Constructing a containerDir path from an unvalidated containerID before calling filepath.Join + os.RemoveAll is a path traversal risk. A malicious ID like ../../etc/cron.d passes through filepath.Join unchanged and escapes rootDir.

This PR adds ValidateID to pkg/unikontainers, mirroring runc's validateID in libcontainer/factory_linux.go. Allowed characters: a-z A-Z 0-9 _ + - .

Changes:

  • Add ValidateID and ErrInvalidContainerID to pkg/unikontainers/unikontainers.go
  • Call ValidateID at the top of New() and Get() where filepath.Join(rootDir, containerID) actually executes
  • Call ValidateID in the ErrNotExist fallback in delete.go the original bug site. This branch re-reads containerID from args and calls os.RemoveAll directly without going through New or Get
  • Add early-exit calls in getUnikontainer() and createUnikontainer() at the cmd layer for fast failure

session.go in the containerd-shim is intentionally not touched containerID there 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:

Screenshot from 2026-06-23 14-05-33

LLM usage

N/A

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (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.
  • If LLMs were used: I have read the llm policy.

@netlify

netlify Bot commented Jun 23, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 175fee5
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a3a4d3ad9d9a9000837267c

@Syedowais312

Syedowais312 commented Jun 23, 2026

Copy link
Copy Markdown
Author

Hey @cmainas,
Please take a look when you have time.

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>
@Syedowais312 Syedowais312 force-pushed the fix/validate-container-id branch from 4ebffce to 175fee5 Compare June 23, 2026 09:09
@cmainas cmainas added the duplicate This issue or pull request already exists label Jun 24, 2026
@cmainas

cmainas commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Duplicate with #726

@Syedowais312 Syedowais312 deleted the fix/validate-container-id branch June 24, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

we should probably validate containerID before constructing the containerDir path

2 participants