π Derive the URL scheme from APP_URL, not APP_ENV - #27
Merged
Conversation
The self-hosted Docker stack sets APP_ENV=production and serves plain HTTP on localhost, so forcing https on any production environment pointed every asset URL at a port nothing listens on. A default install rendered its admin shell fine and then failed to load a single script or stylesheet, which the browser reports as a CORS error. APP_URL already states how the instance is reached, so the scheme comes from there now. Behind a TLS terminating proxy the operator sets an https APP_URL and the forcing still applies, including when TRUSTED_PROXIES is unset and X-Forwarded-Proto is therefore not believed. EnsureRevision had the same defect: it passed the environment as redirect()'s $secure argument, which is an absolute override rather than a hint, so the delivery API's rv redirect went to https on a plain HTTP self-host and to plain http under TLS whenever APP_ENV was not production. Verified against a locally built image on the repo's own compose stack: all 52 asset URLs on the served page flip from https to http, and an https APP_URL still yields https over a plain HTTP hop. Fixes #26 Co-Authored-By: Claude Opus 5 (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.
A default self-hosted Docker install serves plain HTTP on
localhost:8000but generates every URL ashttps://, so the admin UI loads its HTML and then fails to fetch a single script or stylesheet. The browser reports that as a CORS error. Reported in #26.The cause is using
APP_ENVas a stand-in for "is this served over TLS". It isn't one:docker-compose.ymlpinsAPP_ENV=productionwhilescripts/install.shwritesAPP_URL=http://localhost:8000, andAppServiceProviderforced https on any production environment.APP_URLalready states how the instance is reached, so the scheme comes from there now. Behind a TLS terminating proxy the operator sets an httpsAPP_URLand the forcing still applies β including whenTRUSTED_PROXIESis unset andX-Forwarded-Protois therefore not believed.EnsureRevisionhad the same defect. It passed the environment asredirect()'s$secureargument, which is an absolute override rather than a hint, so the delivery API'srvredirect went to https on a plain HTTP self-host and to plain http under TLS wheneverAPP_ENVwas not production. It now leaves the argument out and inherits the same decision.Verified
Built the image from this branch and ran the repo's own compose stack on OrbStack,
APP_ENV=productionandAPP_URL=http://localhost:8123like the installer writes:https://localhost:8123http://localhost:8123Before the fix,
curlon one of those asset URLs fails the TLS handshake with no HTTP status. After it, the same asset serves200 text/javascript, 753 KB. Restarting the fixed image withAPP_URL=https://cms.example.comover a plain HTTP hop still yields https for all 52.Hosted production is unaffected: both ECS task definitions set
APP_URL=https://app.b10cks.com.Two unit tests cover both directions, and both fail against the old code.
Fixes #26