Skip to content

fix(env): use safe tar extract on env pull - #789

Open
crazywriter1 wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
crazywriter1:fix/env-pull-safe-tar-extract
Open

fix(env): use safe tar extract on env pull#789
crazywriter1 wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
crazywriter1:fix/env-pull-safe-tar-extract

Conversation

@crazywriter1

@crazywriter1 crazywriter1 commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • Use _safe_tar_extract in prime env pull (same path used by private install / Lab cache)
  • Reject archives with .., absolute paths, symlinks, or hardlinks before writing files
  • Add pull regression tests for traversal/symlink rejection and safe extraction

Test plan

  • uv run pytest packages/prime/tests/test_env_pull_path.py packages/prime/tests/test_private_env_install.py -q

Note

Medium Risk
Changes untrusted archive extraction and push tarball format; security-hardening with aligned tests, but any bug could break pull/push or block legitimate archives.

Overview
Hardens environment package handling so downloaded archives cannot write outside the target directory and pushed source tarballs stay compatible with the same safe extractor used on install.

prime env pull now calls _safe_tar_extract instead of raw extractall, matching private install / Lab cache behavior: members with .., absolute paths, symlinks, or hardlinks are rejected before anything is written. ValueError from that check is surfaced as a failed extract with exit code 1.

On prime env push, source archives no longer use tar.add() for collected files. New _add_file_to_archive always stores regular file bytes (REGTYPE), because tar.add() can emit hardlink members that _safe_tar_extract would refuse on pull. Collect-time behavior for symlinks is unchanged (still skipped); hardlinked workspace files are still included, just not as LNKTYPE in the tarball.

Regression tests cover pull rejection of traversal/symlink archives, successful safe extraction, and push archives that remain extractable after hardlinks on disk.

Reviewed by Cursor Bugbot for commit 6cfdff4. Bugbot is set up for automated code reviews on this repo. Configure here.

Align prime env pull with private install by rejecting path traversal,
absolute paths, and links via _safe_tar_extract.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84b3114222

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/commands/env.py
tar.add can emit LNKTYPE for shared inodes, which _safe_tar_extract rejects
on pull. Write REGTYPE content instead so push/pull stay compatible.
@crazywriter1

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 6cfdff4ac6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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