Skip to content

fix(install): reject archive with path traversal before extraction (#1250)#1368

Open
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1250
Open

fix(install): reject archive with path traversal before extraction (#1250)#1368
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1250

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Summary

Fixes #1250 — CWE-22 path traversal in install.sh.

  • install.sh now lists archive contents with tar -tzf before extraction and rejects any entry that starts with / or contains a .. path component.
  • The check is POSIX-compliant and adds negligible overhead (the RTK release tarball ships a single binary).
  • Covered by a new scripts/test-install.sh that exercises one safe archive and four crafted malicious archives (leading ../, absolute path, mid-path .., trailing ..), plus a regression guard that fails if the check is removed from install.sh.

Test plan

  • bash scripts/test-install.sh — all 6 cases pass (1 safe, 4 malicious rejected, 1 regression guard).
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — 1590 pass / 0 fail / 6 ignored (unchanged from baseline).
  • Manual sanity: tar -tzf pipeline verified against hand-crafted tarballs containing ../etc/evil, /tmp/abs, rtk/../../../etc/x, rtk/.. — all correctly rejected; rtk, ./rtk, ..hidden, rtk/subdir/bin correctly accepted.

…tk-ai#1250)

The installer previously ran `tar -xzf` on the downloaded archive with no
pre-extraction verification. A malicious mirror could ship a tarball with
`../` components or absolute paths and write files anywhere on the user's
filesystem (CWE-22).

Add a pre-extraction check that lists archive contents with `tar -tzf`
and rejects any entry whose name starts with `/` or contains a `..` path
component. The check is POSIX-compliant and adds negligible overhead for
the single-binary RTK release tarball.

Covered by scripts/test-install.sh, which exercises one safe archive
and four crafted malicious archives (leading `..`, absolute path,
mid-path `..`, trailing `..`) plus a regression guard that ensures the
check remains in install.sh.

Co-Authored-By: Claude <noreply@anthropic.com>
@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Apr 17, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Adds a path traversal guard to install.sh that lists archive contents with tar -tzf before extraction and rejects any entry containing absolute paths or .. components (CWE-22). Includes a comprehensive test script covering safe and malicious archive scenarios plus a regression guard.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1250


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants