Skip to content

Constrain tar driver paths to image root#555

Open
fsabiu wants to merge 1 commit intoGoogleContainerTools:mainfrom
fsabiu:fix/root-confine-tar-driver-paths
Open

Constrain tar driver paths to image root#555
fsabiu wants to merge 1 commit intoGoogleContainerTools:mainfrom
fsabiu:fix/root-confine-tar-driver-paths

Conversation

@fsabiu
Copy link
Copy Markdown

@fsabiu fsabiu commented May 3, 2026

This change adds root-confined path resolution for tar-backed image filesystem paths.

It treats absolute image paths as absolute inside the extracted image root, resolves symlink targets using image-root semantics, rejects traversal above that root, and applies the helper to tar extraction plus tar-driver StatFile, ReadFile, and ReadDir.

Tests added cover:

  • rejecting tar entries, symlinks, and hardlinks that escape the extraction root
  • preserving symlink resolution for valid image-root paths
  • rejecting tar-driver file operations that escape the image root

Local validation:

  • go test ./internal/pkgutil ./pkg/drivers -count=1

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a secure path resolution utility, ResolvePathInRoot, designed to prevent path traversal and ensure all file operations remain within a specified root directory. This utility is integrated into the tar unpacking logic and the TarDriver to safely handle symlinks and hard links. A review comment identifies a bug in hard link creation where symlinks are incorrectly followed; it is recommended to set followFinalSymlink to false for tar.TypeLink entries to ensure the link points to the entry itself rather than its target.

Comment thread internal/pkgutil/tar_utils.go Outdated
@fsabiu fsabiu force-pushed the fix/root-confine-tar-driver-paths branch from 693053b to 2abf6c4 Compare May 3, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant