Skip to content
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

Always use prefixed tables during runtime check requests #768

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

felixarntz
Copy link
Member

@felixarntz felixarntz commented Nov 5, 2024

Related to #597 (see 2nd point in the description, also see this doc comment).

While for the checks itself it's fine to only use the custom database prefix right when the checks are run, this poses some risks because certain parts of the environment (e.g. active plugins, active theme) are already filtered. This could lead to problematic side effects on the actual database tables depending on what plugins do - potentially disastrous, if it was a live site.

Therefore this PR sets the custom database prefix as part of overall runtime preparations (via Universal_Runtime_Preparation) so that it remains for the duration of more or less the entire request:

  • The relevant process of setting the prefix in the Abstract_Check_Runner::run() method has been removed as it is now unnecessary there.
  • This change led to the PHPUnit test AJAX_Runner_Tests::test_prepare_with_runtime_check() to fail, which however was exactly because of the problem this PR is fixing: The Use_Minimal_Theme_Preparation may modify the database with the custom theme root, and this would so far have updated the actual database. So the test now initially sets up the runtime environment, which is needed to execute runtime checks in any case, and the runtime preparations then operate on the "fake tables".
  • A similar fix needed to be added to Runtime_Check_UnitTestCase, which was also missing the runtime environment setup bit.

Additionally, it makes a few minor code improvements:

  • Move check whether runtime environment is set up into its own method on Runtime_Environment_Setup.
  • Improve PHPUnit tests to only clean up what is actually needed, rather than a "catch-all" cleanup, as the latter could lead to potential cleanup related problems to go unnoticed.

@felixarntz felixarntz added [Type] Bug An existing feature is broken Infrastructure Issues for the overall plugin infrastructure WP Admin Issues for the WP Admin screen WP-CLI Issues related to WP-CLI php Pull requests that update Php code labels Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: felixarntz <[email protected]>
Co-authored-by: ernilambar <[email protected]>
Co-authored-by: swissspidy <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@felixarntz felixarntz added this to the 1.3.0 milestone Nov 5, 2024
Copy link
Member

@ernilambar ernilambar left a comment

Choose a reason for hiding this comment

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

Nice.

@swissspidy swissspidy changed the title Fix potential runtime side effects on actual database tables by always using prefixed tables in those requests Always use prefixed tables during runtime check requests Nov 5, 2024
@swissspidy swissspidy merged commit 55b2f74 into trunk Nov 5, 2024
29 checks passed
@swissspidy swissspidy deleted the fix/potential-runtime-side-effects-real-tables branch November 5, 2024 09:50
Copy link
Member

@davidperezgar davidperezgar left a comment

Choose a reason for hiding this comment

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

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall plugin infrastructure php Pull requests that update Php code [Type] Bug An existing feature is broken WP Admin Issues for the WP Admin screen WP-CLI Issues related to WP-CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants