Skip to content

feat(multisite): per-site config isolation for headless settings (#114)#140

Merged
PAMulligan merged 1 commit into
mainfrom
114-multitenant-per-site-isolation
Jun 21, 2026
Merged

feat(multisite): per-site config isolation for headless settings (#114)#140
PAMulligan merged 1 commit into
mainfrom
114-multitenant-per-site-isolation

Conversation

@PAMulligan

Copy link
Copy Markdown
Collaborator

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-site flavian_headless_mode option in a request
static 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 — a
genuine cross-tenant config leak.

The fix (mu-plugins/flavian-headless.php)

  • current_settings() — a request cache keyed by get_current_blog_id();
    is_enabled() / frontend_url() / preview_secret() read through it, so each
    tenant is isolated.
  • settings_for_blog( $blog_id ) — safe cross-site reads via
    switch_to_blog() → per-site get_option()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.

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 leaks
into 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

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>
@PAMulligan PAMulligan self-assigned this Jun 21, 2026
@PAMulligan PAMulligan merged commit 092f9e8 into main Jun 21, 2026
16 checks passed
@PAMulligan PAMulligan deleted the 114-multitenant-per-site-isolation branch June 21, 2026 07:06
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.

[Redence verify] Multi-tenant architecture — add per-site config isolation for Multisite

1 participant