Skip to content

Fix ZipSlip path traversal vulnerability in ArtifactTool zip extraction#47523

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-for-review-comment
Draft

Fix ZipSlip path traversal vulnerability in ArtifactTool zip extraction#47523
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-for-review-comment

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

_redirect_artifacts_tool_path was calling ZipFile.extractall() directly without validating member paths, leaving it open to ZipSlip/path traversal attacks where a malicious zip could write files outside the intended temp directory.

Changes

  • _artifact_utils.py: Replace extractall() with member-by-member extraction using infolist() (covers directories as well as files); resolve each member's path and assert it stays within the target directory before extracting; raise RuntimeError on any unsafe entry.
artifacts_tool_resolved = Path(artifacts_tool_path).resolve()
for member_info in zip_file.infolist():
    member_resolved = (artifacts_tool_resolved / member_info.filename).resolve()
    if not member_resolved.is_relative_to(artifacts_tool_resolved):
        raise RuntimeError(
            f"Unsafe path in zip archive: '{member_info.filename}' resolves outside the target directory."
        )
    zip_file.extract(member_info, artifacts_tool_path)

Replace unsafe `ZipFile.extractall()` with member-by-member extraction
that validates each entry's resolved path stays within the target
directory using `infolist()` for complete coverage including directories.

Co-authored-by: ayushhgarg-work <259261949+ayushhgarg-work@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code for review comment in PR 46714 Fix ZipSlip path traversal vulnerability in ArtifactTool zip extraction Jun 16, 2026
Copilot AI requested a review from ayushhgarg-work June 16, 2026 10:24
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