Skip to content

fix(profiles): validate tar archive member paths on import - #4318

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-99d28812
Mar 31, 2026
Merged

fix(profiles): validate tar archive member paths on import#4318
teknium1 merged 1 commit into
mainfrom
hermes/hermes-99d28812

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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.txt to write files outside ~/.hermes/profiles/.

E2E verified: the old code writes /tmp/escape.txt when 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)
  • Replaces shutil.unpack_archive() with the safe extraction path
  • 2 regression tests (traversal + absolute path attacks)

Closes #3959

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>
@teknium1
teknium1 merged commit 0f2ea20 into main Mar 31, 2026
4 of 5 checks passed
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