Avoid writing new mu-plugins if old ones are still accessible - #3403
Merged
fredrikekelund merged 7 commits intoMay 13, 2026
Conversation
Collaborator
📊 Performance Test ResultsComparing 180e41b vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
1 task
This reverts commit ffe41e7.
…nescaping' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
bcotrim
approved these changes
May 12, 2026
bcotrim
left a comment
Contributor
There was a problem hiding this comment.
Worked as described, nice improvement!
LGTM 👍
fredrikekelund
added a commit
that referenced
this pull request
May 13, 2026
## Related issues <!-- Link a related issue to this PR. If the PR does not immediately resolve the issue, for example, it requires a separate deployment to production, avoid using the "Fixes" keyword and use "Related to" instead. --> - Fixes RSM-1691 - Builds on #3403 ## How AI was used in this PR <!-- Help reviewers understand what to look for and verify that you've reviewed the code yourself. --> Claude was used to verify the list of disabled PHP functions and to review the implementation as a whole, through several iterations. ## Proposed Changes Running code from third parties on your local machine is inherently risky. There's no sandbox with our native PHP runtime, so machines could be compromised in any number of ways (extracting secrets, running malicious code, etc). This PR applies some sane security defaults that reduce risk. We aim to strike a good balance between relatively secure defaults and still allowing most typical WordPress sites to function perfectly normally. 1. Always call `getDefaultPhpArgs` when invoking the PHP binaries. 2. Increase `memory_limit` to 512 MB. This has nothing to do with security, but I noticed that the default is 128 MB, which isn't enough for a site with a few plugins installed. 3. Optionally, apply an `open_basedir` restriction to the PHP binary. See [docs](https://www.php.net/manual/en/ini.core.php#ini.open-basedir). This is applied to the web server that runs the website. - Generating the `open_basedir` list is the most complex piece of logic in this PR, because we want symlinked plugins and themes to just work. To do this, we resolve any symlinks contained in the site directory and watch the `wp-content` directory for new symlinks added while the site is running. The symlink watcher triggers a PHP process restart. 5. Optionally, apply a `disable_functions` restriction to the PHP binary that prevents PHP from doing a bunch of things that malicious plugins could use to compromise the current machine. ## Testing Instructions <!-- Add as many details as possible to help others reproduce the issue and test the fix. "Before / After" screenshots can also be very helpful when the change is visual. --> 1. Run `STUDIO_RUNTIME=native-php npm start` 2. If you don't already have a site with `runtime: native-php`, create a new one 3. Start that site 4. Run `node apps/cli/dist/cli/main.mjs wp core version` and ensure it works (do this before testing wp-admin) 6. Ensure that uploading media works 7. Ensure that installing plugins work 8. Do some light smoke testing of the site and ensure that nothing is broken ## Pre-merge Checklist <!-- Complete applicable items on this checklist **before** merging into trunk. Inapplicable items can be left unchecked. Both the PR author and reviewer are responsible for ensuring the checklist is completed. --> - [ ] Have you checked for TypeScript, React or other console errors? --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
How AI was used in this PR
Codex implemented the first version, which I then tweaked – specifically to use JSON for stable string de-/serialization between JS and PHP.
Proposed Changes
With the
native-phpruntime, mu-plugins are loaded like so:wp-content/mu-plugins/99-studio-loader.phpfile to the site directory, with a path to the temporary directory from before.Previously, this process was executed not only when a server started, but also on every WP-CLI invocation. This is fine, but it's not very efficient.
This PR prepends the following steps to the previous process:
wp-content/mu-plugins/99-studio-loader.phpexists.If all assertions hold, we don't write anything to disk. If they don't, we run the setup process again.
Testing Instructions
STUDIO_RUNTIME=native-php npm startruntime: native-php, create a new onewp-content/mu-plugins/99-studio-loader.phpand take note of$studio_mu_plugins_dirnode apps/cli/dist/cli/main.mjs wp core versionwp-content/mu-plugins/99-studio-loader.phpand ensure that$studio_mu_plugins_diris the same as beforePre-merge Checklist