Skip to content

Fix: Skip sandbox line in MariaDB dump files during import #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

iamsandeepdahiya
Copy link

Summary

This PR addresses a compatibility issue introduced by a recent MariaDB security fix (MDEV-21178), which causes wp db import to fail when importing SQL dump files generated by newer versions of MariaDB.


Background

To mitigate a serious security vulnerability, MariaDB added a new "sandbox mode" that disables potentially dangerous client-side commands. This mode is triggered by placing the following directive at the top of a dump file:

/*!999999\ - enable the sandbox mode */

While this is safe for newer MariaDB clients, it breaks compatibility with:

  • Older MariaDB clients
  • All versions of MySQL clients
  • WP-CLI's wp db import command

This directive causes a SQL syntax error when encountered during import:

ERROR 1064 (42000): You have an error in your SQL syntax...

This problem is being tracked in #258.

Solution

This patch introduces a safeguard into the import() method:

  • It reads the first line of the SQL dump.
  • If the line contains the sandbox directive (/*!999999), it creates a temporary file that skips the first line.
  • The modified file is then passed into the SOURCE command for import.
  • If the directive is not found, import proceeds as normal.

@iamsandeepdahiya iamsandeepdahiya requested a review from a team as a code owner July 23, 2025 10:09
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 12.50000% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/DB_Command.php 12.50% 14 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mrsdizzie
Copy link
Member

I don't think it should be the responsibility of wp cli to modify these files directly. Also we can't create temporary files of unknown size -- I regularly come across dump files that are many GB. This is very easy to address outside of wp cli if you are importing dump files across incompatible versions of MariaDB (just remove the incompatible line or strip it when exporting).

@mrsdizzie mrsdizzie closed this Jul 23, 2025
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.

2 participants