Skip to content

Validate version format and escape tar command arguments - #131

Merged
swissspidy merged 1 commit into
mainfrom
fix/version-handling
Aug 3, 2026
Merged

Validate version format and escape tar command arguments#131
swissspidy merged 1 commit into
mainfrom
fix/version-handling

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 3, 2026

Copy link
Copy Markdown
Member

Applying some slight hardening to validate version strings extracted from style.css, PHP files, and composer.json to ensure they conform to valid version characters and prevent argument injection into GNU tar commands. Also use Utils\esc_cmd to safely quote parameters passed to tar and git log commands.

Summary by CodeRabbit

  • Bug Fixes
    • Improved archive creation to prevent malicious metadata from injecting commands during tarball generation.
    • Added validation for theme, plugin, and Composer version information, safely ignoring invalid values.
    • Restricted Git commit identifiers to valid seven-character hexadecimal hashes before including them in archive metadata.
  • Tests
    • Added acceptance coverage confirming that crafted metadata cannot execute commands and that archives are still generated successfully.

Validate version strings extracted from style.css, PHP files, and composer.json to ensure they conform to valid version characters and prevent argument injection into GNU tar commands. Also use Utils\esc_cmd to safely quote parameters passed to tar and git log commands.
@swissspidy swissspidy added this to the 3.2.3 milestone Aug 3, 2026
@swissspidy
swissspidy requested a review from a team as a code owner August 3, 2026 07:43
Copilot AI review requested due to automatic review settings August 3, 2026 07:43
@swissspidy swissspidy added the command:dist-archive Related to 'dist-archive' command label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Archive input safety

Layer / File(s) Summary
Command and version validation
src/Dist_Archive_Command.php
Tar paths are escaped before command construction. Theme, plugin, Composer, and Git-derived versions are validated before use.
Malicious metadata acceptance tests
features/dist-archive.feature
Acceptance scenarios verify archive creation with malicious theme, plugin, and Composer version metadata. The theme scenario also checks that no injected proof file is created.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: version validation and escaping arguments used in the tar command.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/version-handling

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Dist_Archive_Command.php 81.25% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens dist-archive against command/argument injection by validating extracted version strings and safely escaping parameters passed to external commands (notably GNU tar and git).

Changes:

  • Use WP_CLI\Utils\esc_cmd() when building tar commands to safely quote archive paths and directory arguments.
  • Validate version strings read from style.css, plugin PHP headers, and composer.json against a strict allowed-character set, and validate appended git short-hash format.
  • Add Behat acceptance tests covering malicious Version: header payloads intended to inject GNU tar arguments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Dist_Archive_Command.php Escapes tar/git command arguments and rejects invalid version strings to prevent injection into archive filenames.
features/dist-archive.feature Adds scenarios asserting successful archive creation when Version: headers contain tar-flag injection attempts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread features/dist-archive.feature

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Dist_Archive_Command.php`:
- Around line 320-323: Update the version handling around $composer_obj->version
to require is_string() before trimming or casting and applying the existing
preg_match validation. Only assign $version for valid string values, safely
ignoring array or object values without triggering PHP 8 errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: befcf445-302f-4f72-ab75-71351e11b254

📥 Commits

Reviewing files that changed from the base of the PR and between 13528a2 and 65bc96a.

📒 Files selected for processing (2)
  • features/dist-archive.feature
  • src/Dist_Archive_Command.php

Comment thread src/Dist_Archive_Command.php
@swissspidy
swissspidy merged commit 8fc93c6 into main Aug 3, 2026
75 of 77 checks passed
@swissspidy
swissspidy deleted the fix/version-handling branch August 3, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:dist-archive Related to 'dist-archive' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants