Skip to content

fix: add checksum verification and harden archive extraction in CLI self-update#7575

Closed
fresh3nough wants to merge 1 commit intoblock:mainfrom
fresh3nough:fix/update-checksum-verification-7552
Closed

fix: add checksum verification and harden archive extraction in CLI self-update#7575
fresh3nough wants to merge 1 commit intoblock:mainfrom
fresh3nough:fix/update-checksum-verification-7552

Conversation

@fresh3nough
Copy link
Copy Markdown
Contributor

Summary

Replace the shell-out-to-curl-and-bash self-update mechanism with a native Rust implementation that adds SHA-256 checksum verification and hardens archive extraction against path traversal attacks (zip-slip/tar-slip).

Checksum verification:

  • After downloading the release archive, the update command now computes its SHA-256 digest and attempts to download a corresponding <asset>.sha256 file from the same release
  • If the checksum file exists, the digest is verified and the update aborts on mismatch
  • If no checksum file is published yet (current state), a warning is printed and the update proceeds gracefully
  • The CI pipeline (build-cli.yml) now generates .sha256 files alongside each archive, and release.yml/canary.yml upload them as release assets

Extraction hardening:

  • Tar extraction (tar.bz2, tar.gz) now iterates entries individually, validating each path rejects absolute paths and .. components before unpacking
  • Zip extraction uses enclosed_name() for path sanitization and iterates entries individually instead of using bulk extract()

Format flexibility:

  • Added flate2 dependency and extract_tar_gz() to support .tar.gz/.tgz archives alongside the existing .tar.bz2 and .zip formats
  • The extract_archive() dispatcher selects the correct extractor based on file extension

Type of Change

  • Security fix
  • Bug fix
  • Tests
  • Build / Release

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

  • 15 unit tests added covering:
    • SHA-256 digest computation
    • Path traversal rejection (absolute paths, .. components)
    • Safe path acceptance
    • tar.gz extraction round-trip
    • tar.bz2 path traversal rejection with raw crafted malicious archive
    • Archive format dispatch (unsupported format error)
    • Binary location in various archive layouts
    • Binary replacement
  • All tests pass: cargo test -p goose-cli -- update (15/15)
  • cargo clippy --all-targets -- -D warnings passes clean
  • cargo fmt applied

Steps to reproduce the fix:

source bin/activate-hermit
cargo build -p goose-cli
cargo test -p goose-cli -- update
cargo clippy -p goose-cli --all-targets -- -D warnings

Related Issues

Closes #7552

Copy link
Copy Markdown

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

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: cfd1604ba5

ℹ️ 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".

@fresh3nough fresh3nough force-pushed the fix/update-checksum-verification-7552 branch from cfd1604 to b79c0f8 Compare February 27, 2026 18:10
Copy link
Copy Markdown

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

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: b79c0f8473

ℹ️ 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".

…elf-update

Addresses block#7552: CLI self-update lacked signature/checksum verification
and archive extraction was vulnerable to path traversal.

Changes:
- Replace shell-out update with native Rust implementation
- Add SHA-256 checksum verification against <asset>.sha256 files
  (graceful fallback when no checksum file is published)
- Harden tar extraction: iterate entries individually with path
  validation to prevent zip-slip/tar-slip attacks
- Harden zip extraction: use enclosed_name() for path sanitization
- Add tar.gz/tgz support via flate2 for format flexibility
- Generate SHA-256 checksum files in CI build pipeline
- Upload checksum files alongside release archives
- Add comprehensive tests for all new functionality

Signed-off-by: fresh3nough <[email protected]>
@fresh3nough fresh3nough force-pushed the fix/update-checksum-verification-7552 branch from b79c0f8 to 43705cf Compare February 27, 2026 19:59
@jamadeo
Copy link
Copy Markdown
Collaborator

jamadeo commented Mar 11, 2026

hey @fresh3nough, thanks for this. #7148 moved the update to a rust implementation, but the digest proposal from your PR is still relevant. #7097 adds what we need on the build side, so we should probably go with those signatures. I'll close this PR, but the goal here is good and if you're interested, maybe you could look into verifying these using the https://github.com/sigstore/sigstore-rs crate?

@jamadeo jamadeo closed this Mar 11, 2026
@fresh3nough
Copy link
Copy Markdown
Contributor Author

@jamadeo thanks, yes sir, i will take a look fs

@fresh3nough
Copy link
Copy Markdown
Contributor Author

Hey @tlongwell-block (and thanks for the thoughtful close!),

Opened a new PR with the exact direction you suggested: #7818

Happy to iterate!

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.

CLI self-update lacks signature/checksum verification; archive extraction should be hardened

2 participants