fix(profiles): validate tar archive member paths on import - #4318
Merged
Conversation
Fixes a zip-slip path traversal vulnerability in hermes profile import. shutil.unpack_archive() on untrusted tar members allows entries like ../../escape.txt to write files outside ~/.hermes/profiles/. - Add _normalize_profile_archive_parts() to reject absolute paths (POSIX and Windows), traversal (..), empty paths, backslash tricks - Add _safe_extract_profile_archive() for manual per-member extraction that only allows regular files and directories (rejects symlinks) - Replace shutil.unpack_archive() with the safe extraction path - Add regression tests for traversal and absolute-path attacks Co-authored-by: Gutslabs <gutslabsxyz@gmail.com>
This was referenced Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #3959 by @Gutslabs — cherry-picked onto current main.
Summary
Fixes a zip-slip path traversal vulnerability in
hermes profile import.shutil.unpack_archive()on untrusted tar members allows entries like../../escape.txtto write files outside~/.hermes/profiles/.E2E verified: the old code writes
/tmp/escape.txtwhen given a malicious archive. The fix blocks traversal, absolute paths, Windows paths, symlinks, and edge cases while legit archives still extract correctly.Changes
_normalize_profile_archive_parts()— validates each member path (rejects absolute, traversal, Windows drive, empty)_safe_extract_profile_archive()— manual per-member extraction (files + dirs only, no symlinks)shutil.unpack_archive()with the safe extraction pathCloses #3959