Skip to content

Escape URL parameter in update-db and check-update-db network commands - #338

Merged
swissspidy merged 1 commit into
mainfrom
fix/check-update-db
Aug 3, 2026
Merged

Escape URL parameter in update-db and check-update-db network commands#338
swissspidy merged 1 commit into
mainfrom
fix/check-update-db

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 3, 2026

Copy link
Copy Markdown
Member

Apply some slight hardening

Summary by CodeRabbit

  • Bug Fixes
    • Improved multisite database checks and updates for site paths containing shell-special characters.
    • Prevented site URL content from being interpreted as command syntax during network operations.
    • Added coverage to verify successful execution without creating unintended files.

@swissspidy swissspidy added this to the 2.1.33 milestone Aug 3, 2026
@swissspidy
swissspidy requested a review from a team as a code owner August 3, 2026 07:42
Copilot AI review requested due to automatic review settings August 3, 2026 07:42
@swissspidy swissspidy added command:core-update-db Related to 'core update-db' command command:core-check-update-db Related to 'core check-update-db' command labels Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Network database check and update commands now escape site URLs before building nested WP-CLI commands. A multisite feature test covers site paths containing command-substitution characters.

Changes

Network database command safety

Layer / File(s) Summary
Escape site URLs in network commands
src/Core_Command.php, features/core-check-update-db.feature
check_update_db() and update_db() now use Utils\esc_cmd() for site URLs. The multisite test verifies that shell-special characters do not execute an embedded command.

Estimated code review effort: 3 (Moderate) | ~15–30 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 and concisely describes escaping the URL parameter in the affected network commands.
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/check-update-db

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.

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 wp core check-update-db --network and wp core update-db --network by safely escaping the per-site --url argument when invoking subcommands, and adds an acceptance test intended to catch command-injection regressions.

Changes:

  • Escape the --url argument via Utils\esc_cmd() when running core check-update-db for each network site.
  • Escape the --url argument via Utils\esc_cmd() when running core update-db for each network site (including --dry-run handling).
  • Add a Behat scenario attempting to ensure special characters in site domain/path don’t lead to shell execution during network check-update-db.

Reviewed changes

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

File Description
src/Core_Command.php Escapes --url when spawning network per-site check-update-db / update-db subcommands.
features/core-check-update-db.feature Adds a Behat scenario aimed at preventing command-injection regressions in check-update-db --network.

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

Comment on lines +104 to +105
And I run `wp db query "INSERT INTO wp_blogs (site_id, domain, path, registered, last_updated) VALUES (1, 'example.com', '/x\\\$(touch /tmp/wpcli_test_check_db_marker)/', NOW(), NOW());"`

Comment thread src/Core_Command.php
++$total;
$url = $blog->domain . $blog->path;
$cmd = "--url={$url} core update-db";
$cmd = Utils\esc_cmd( '--url=%s core update-db', $url );

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

🧹 Nitpick comments (1)
features/core-check-update-db.feature (1)

102-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise update-db in the regression test.

The scenario runs only wp core check-update-db --network at Line [106]. It does not execute the new update_db() path at Line [1631]. Add wp core update-db --network --dry-run and repeat the marker assertion.

Suggested test extension
+    When I run `wp core update-db --network --dry-run`
+    Then the return code should be 0
+    And the /tmp/wpcli_test_check_db_marker file should not exist
🤖 Prompt for 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.

In `@features/core-check-update-db.feature` around lines 102 - 109, Extend the
special-character multisite scenario after the existing check-update-db command
by running `wp core update-db --network --dry-run`, then repeat the assertion
that `/tmp/wpcli_test_check_db_marker` does not exist. Keep the current
return-code and marker checks for `check-update-db` unchanged.
🤖 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.

Nitpick comments:
In `@features/core-check-update-db.feature`:
- Around line 102-109: Extend the special-character multisite scenario after the
existing check-update-db command by running `wp core update-db --network
--dry-run`, then repeat the assertion that `/tmp/wpcli_test_check_db_marker`
does not exist. Keep the current return-code and marker checks for
`check-update-db` unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c8b8ad60-a760-4105-984f-7e5d18103682

📥 Commits

Reviewing files that changed from the base of the PR and between 82ec5d0 and 770c0cd.

📒 Files selected for processing (2)
  • features/core-check-update-db.feature
  • src/Core_Command.php

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
swissspidy merged commit 4ed325f into main Aug 3, 2026
67 of 68 checks passed
@swissspidy
swissspidy deleted the fix/check-update-db branch August 3, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:core-check-update-db Related to 'core check-update-db' command command:core-update-db Related to 'core update-db' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants