Skip to content

Serve WordPress from the alios share host in wordpress-dev images - #5

Closed
michaelaguiar wants to merge 1 commit into
mainfrom
alios-share-wordpress
Closed

michaelaguiar wants to merge 1 commit into
mainfrom
alios-share-wordpress

Conversation

@michaelaguiar

Copy link
Copy Markdown
Member

Why

alios share (new in alios-cli) exposes a local project through a Cloudflare Tunnel. WordPress stores its URL in the database, so a shared WordPress site redirects every visitor back to https://<project>.test. Editing the project's wp-config.php from the CLI was rejected: a leftover edit could get committed, and trusting the request host in production allows password-reset and cache poisoning. This PR puts the fix in the dev image instead.

What

The wordpress-dev variant (8.2–8.5) gets an auto_prepend_file, /usr/local/lib/php/alios-share.php. It only acts on requests carrying X-Alios-Share: 1. The alios share Caddy vhost sets that header itself, so tunnel visitors can't forge or strip it.

For marked requests it:

  • filters option_home / option_siteurl to the forwarded public host, keeping any path (Bedrock /wp). The filter is registered through WordPress's pre-initialized $wp_filter hooks at priority 9999, after core's _config_wp_home, so it also overrides WP_HOME / WP_SITEURL defines.
  • rewrites the site's stored host(s) to the public host in text responses (HTML/JSON/JS/CSS/XML, including JSON-escaped URLs) and in Location headers, upgrading http:// to https://.
  • ignores a forwarded host that isn't a plain hostname.

Unmarked requests (every normal .test request, WP-CLI) return immediately. Nothing is written to the project, and the production wordpress variant is unchanged.

The PHP is inlined as a Dockerfile heredoc because CI change detection only watches the Dockerfiles. A separate file wouldn't trigger a rebuild when edited.

Testing

I built 8.4-frankenphp-wordpress-dev locally and ran it against a real stock-WordPress site (code mounted read-only, committed wp-config.php):

Request Result
Host: <project>.test (no marker) 200, all 103 links https://<project>.test (unchanged)
Public host, no marker 301 → https://<project>.test/ (existing behaviour)
Public host + X-Alios-Share: 1 200, all 103 links on the public host
/wp-admin/ + marker 302 → public-host wp-login.php with public-host redirect_to
/wp-json/ + marker all 67 escaped URLs on the public host
Malformed X-Forwarded-Host + marker ignored, plain response

The 8.2 variant also builds, and php -l passes on the prepend file. The 8.3 and 8.5 files are identical to 8.4 apart from FROM.

Caveats

  • A project that sets its own auto_prepend_file (e.g. Wordfence's WAF) would override this one. That's unlikely in local dev.
  • The output rewrite buffers the full response. That's fine for dev, but it's why this lives only in the dev image.

🤖 Generated with Claude Code

WordPress stores its URL in the database, so a site reached through an
`alios share` tunnel redirects visitors back to https://<project>.test.
The wordpress-dev variant now ships an auto_prepend_file that, only for
requests the alios share vhost marks with `X-Alios-Share: 1`, filters
home/siteurl to the forwarded public host (via pre-initialized hooks,
so it also wins over WP_HOME/WP_SITEURL) and rewrites the stored host
in text responses and Location headers. Normal .test requests and
WP-CLI are untouched, nothing is written to the project, and the
production wordpress variant is unchanged.

The PHP is inlined as a Dockerfile heredoc so editing it triggers this
variant's CI rebuild (change detection only watches the Dockerfiles).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant