Validate version format and escape tar command arguments - #131
Conversation
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.
📝 WalkthroughWalkthroughChangesArchive input safety
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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 buildingtarcommands to safely quote archive paths and directory arguments. - Validate version strings read from
style.css, plugin PHP headers, andcomposer.jsonagainst 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.
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
features/dist-archive.featuresrc/Dist_Archive_Command.php
Applying some slight hardening to validate version strings extracted from
style.css, PHP files, andcomposer.jsonto ensure they conform to valid version characters and prevent argument injection into GNU tar commands. Also useUtils\esc_cmdto safely quote parameters passed to tar and git log commands.Summary by CodeRabbit