Skip to content

Update docker-image-extract.py#3457

Open
RuslanSemchenko wants to merge 2 commits intoJetBrains:masterfrom
RuslanSemchenko:master
Open

Update docker-image-extract.py#3457
RuslanSemchenko wants to merge 2 commits intoJetBrains:masterfrom
RuslanSemchenko:master

Conversation

@RuslanSemchenko
Copy link
Copy Markdown

@RuslanSemchenko RuslanSemchenko commented Mar 16, 2026

Added a security check to prevent Tar Slip by ensuring that all extracted files remain within the designated destination directory

Maybe need some fix idk


Note

Medium Risk
Changes the extraction logic of docker-image-extract.py by adding path-safety checks and broader error handling, which could alter what files get extracted or skipped. Low blast radius, but mistakes here could still lead to incomplete/failed layer extraction or missed edge cases with tar paths/symlinks.

Overview
Adds a safety guard to docker-image-extract.py to prevent tar path traversal (Tar Slip) by verifying each layer entry resolves within the destination directory and skipping unsafe paths.

Refactors the script into a main() with basic argument validation, creates the destination directory if needed, and adds error handling around opening the image, reading manifest.json, and extracting individual entries (while still skipping device files and replacing existing files/links).

Written by Cursor Bugbot for commit 960aab1. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

print(' --> skip device files')
def is_safe_path(basedir, path):
base = os.path.abspath(basedir)
target = os.path.abspath(path)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Symlink bypass defeats tar slip path traversal protection

High Severity

is_safe_path uses os.path.abspath which only performs string manipulation and does not resolve symlinks. A malicious tar layer can first extract a symlink (e.g., link/) inside the destination directory, then extract a file like link/etc/cron.d/evil. The os.path.abspath check sees the path as still within extracted_path, but layer_tar.extract follows the symlink and writes outside it. Using os.path.realpath instead of os.path.abspath for target would resolve already-extracted symlinks and correctly detect the traversal.

Additional Locations (1)
Fix in Cursor Fix in Web

dest = os.path.normpath(os.path.join(extracted_path, tarinfo.name))
if not is_safe_path(extracted_path, dest):
print(f" [!] SECURITY WARNING: Skipping unsafe file (Path Traversal): {tarinfo.name}")
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Link targets are never validated by security check

High Severity

The is_safe_path check only validates tarinfo.name (the entry's filesystem destination) but never inspects tarinfo.linkname (the target of symlink or hardlink entries). A malicious tar can include a hardlink with a safe-looking name but a linkname like ../../etc/shadow, causing tarfile.extract to create a hard link to a sensitive file outside the extraction directory. Similarly, a symlink entry can have linkname pointing to an arbitrary absolute path. This is a separate bypass from the abspath-vs-realpath issue and matches the pattern described in CVE-2025-4138.

Fix in Cursor Fix in Web

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 16, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

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.

2 participants