feat(multisite): per-site config isolation for headless settings (#114)#140
Merged
Conversation
Fix a multi-tenant isolation defect and add safe cross-site reads in the headless mu-plugin's per-site settings path. - is_enabled() cached the per-site flavian_headless_mode option in a request static that was not keyed by blog id, so after switch_to_blog() one site served another site's headless config. Replaced it with current_settings(), a request cache keyed by get_current_blog_id(); is_enabled(), frontend_url() and preview_secret() now read through it, isolating each tenant. - Added settings_for_blog(): switch_to_blog() -> read per-site options -> restore_current_blog(), cached in a per-blog site transient and invalidated on update_option_flavian_headless_*. The preview secret is excluded from cross-site reads. - The network dashboard widget now shows each site's headless status via that isolated accessor (guarded headless_badge()), so no config leaks between rows. Verified with the repo's WPCS config (WordPress-Extra + Docs): 0 errors, 0 warnings. Redence-Proof-Token: RDNC-EUS2VY Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Closes #114.
Real per-tenant (per-site) isolation on a concrete settings path — the headless
mu-plugin's per-site config — in WordPress Multisite.
The defect
is_enabled()cached the per-siteflavian_headless_modeoption in a requeststatic that wasn't keyed by blog id. The option is per-blog, but the static
cache froze the first site's value for the whole request, so after
switch_to_blog()a second site served the first site's headless config — agenuine cross-tenant config leak.
The fix (
mu-plugins/flavian-headless.php)current_settings()— a request cache keyed byget_current_blog_id();is_enabled()/frontend_url()/preview_secret()read through it, so eachtenant is isolated.
settings_for_blog( $blog_id )— safe cross-site reads viaswitch_to_blog()→ per-siteget_option()→restore_current_blog(), cachedin a per-blog site transient and invalidated on
update_option_flavian_headless_*. The preview secret is excluded fromcross-site reads.
Real consumer (
mu-plugins/flavian-multisite.php)The network dashboard widget now shows each site's headless status through that
isolated accessor (guarded
headless_badge()), so one site's config never leaksinto another's row.
Checks
Ran the repo's WPCS config (WordPress-Extra + WordPress-Docs) on both files:
0 errors, 0 warnings. No PHP behavior outside the headless/multisite settings
path is touched.
(The Redence Multi-tenant proof token is included in the commit message per the
issue.)
🤖 Generated with Claude Code