Skip to content

Fix path traversal check in tar extraction to use path-aware comparison#42

Merged
rilma merged 3 commits intofeatures/upgrade-ci-cdfrom
copilot/sub-pr-40-again
Feb 21, 2026
Merged

Fix path traversal check in tar extraction to use path-aware comparison#42
rilma merged 3 commits intofeatures/upgrade-ci-cdfrom
copilot/sub-pr-40-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

os.path.commonprefix is string-based and can be bypassed — /tmp/dir_evil shares the prefix /tmp/dir, incorrectly passing the traversal check. Replaces it with os.path.commonpath, which compares at directory boundaries.

Changes

  • is_within_directory: Replace os.path.commonprefix with os.path.commonpath([abs_directory, abs_target]) == abs_directory to correctly enforce path containment
  • Error handling: Catch ValueError from os.path.commonpath (raised on Windows when paths span different drives) and return False — path is not within directory
  • Exception type: Raise ValueError instead of bare Exception on traversal detection
# Before — bypassable
prefix = os.path.commonprefix([abs_directory, abs_target])
return prefix == abs_directory  # /tmp/dir_evil falsely matches /tmp/dir

# After — path-aware
try:
    return os.path.commonpath([abs_directory, abs_target]) == abs_directory
except ValueError:
    return False  # different drives on Windows → not within directory

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 21, 2026 21:00
…rror

Co-authored-by: rilma <14822065+rilma@users.noreply.github.com>
Co-authored-by: rilma <14822065+rilma@users.noreply.github.com>
Copilot AI changed the title [WIP] Update CI/CD pipeline based on review feedback Fix path traversal check in tar extraction to use path-aware comparison Feb 21, 2026
Copilot AI requested a review from rilma February 21, 2026 21:02
@rilma rilma marked this pull request as ready for review February 21, 2026 21:03
@rilma rilma merged commit e18b276 into features/upgrade-ci-cd Feb 21, 2026
@rilma rilma deleted the copilot/sub-pr-40-again branch February 21, 2026 21:03
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