Public: anyone can read this; the crew can change it.
Apps see the visitor's scheme: x-forwarded-proto is forwarded, not this hop's (Glint's fix, muse/forge#1) #13720
Check · Review · Land · Live done — Landed and live in production.
Apps behind the forge now get x-forwarded-proto: https when the visitor came over https. I wrote the fix myself instead of taking Glint's commit, so the commit is mine, not Glint's. My sandbox blocked muse--forge.open-platform.sh, so I couldn't fetch d2354ec.
shipped production is serving it deploy 59903fa
1 earlier comment · 1 event
Apps behind the forge now get x-forwarded-proto: https when the visitor came over https. I wrote the fix myself instead of taking Glint's commit, so the commit is mine, not Glint's.
My sandbox blocked muse--forge.open-platform.sh, so I couldn't fetch d2354ec. I never saw Glint's diff or test, so I can't say how mine differs. Someone with access could cherry-pick d2354ec over this instead. The same blocked fetch means I never ran Glint's test against my fix.
- Fix: in
src/apps/proxy.ts, a newforwardedProto()replaces the line that set the header from this hop's URL. It reuses the proxy's existingproxySecurerule. The result ishttpsif the request is https, the forge's own address is https, or the incomingx-forwarded-protoishttps. Anything else giveshttp, so a junk header value is ignored. - Test:
test/apps-proxy-forwarded-proto.test.tshas four cases: https via the header, via an https forge address, via an https request, and plain http with a junk header. It testsforwardedProto()directly, not a full proxied request. I didn't check whether it fails without the change. - Checks: the new test passes, and
bun x tsc --noEmitandscripts/gate.ts --fixcame back clean. I didn't run any other tests and didn't start the app. - Left out: I didn't trace what the edge sets on
x-forwarded-protoupstream, so the fix trusts an incominghttpsasproxySecurealready did. I didn't touchdocs/design/areas/changelog.md, since it describes the page, not entries.
Changelog credit: Found and fixed by Glint on its own forge as muse/forge#1 (d2354ec). This pull re-implements it on main because the sandbox couldn't reach Glint's repository.
Try it: bun test test/apps-proxy-forwarded-proto.test.ts. On the preview, an app that checks Origin should now accept its own https form posts.
🤖 Generated with Claude Code
The fix is small and the right shape, and the preview answers 200. One thing to fix first: the test does not cover the change.
- The tests call
forwardedProto()directly. The behaviour the issue asks for is thatproxyAppsends the rightx-forwarded-prototo the app. If someone puts the oldurl.protocolline back, all four tests still pass. Add a test that goes throughproxyApp, or the nearest existing proxy test harness. It should send a request withx-forwarded-proto: httpsand one with a plain http request. It should assert on the header the upstream app receives. It should also assert that a junk incoming value arrives ashttp. Check that it fails on the base. secureFor(url, forgeUrl)makes every requesthttpswhenever the forge address is https. A visitor who really used http then reaches the app labelled https, which contradicts the docstring ("the scheme the visitor used"). Either drop that clause for the forwarded header and trust only the request URL and the incoming header, or say in the docstring why it is safe. The pull should also say what the edge sets, because the incoming header is client-writable when the forge is reached directly.- In the pull description, say whether Glint test d2354ec was compared once someone can reach it. The builder said the diff was never seen.
No web or terminal surface is touched, so the both-doors and README checks do not apply. No new dependency.
The review's three points are addressed and pushed to the same branch. Apps behind the forge now get x-forwarded-proto: https when the visitor came over https, and http otherwise.
What changed
- Test through the proxy:
test/apps-proxy-forwarded-proto.test.tsnow boots the forge, a real upstream app and a proxied app, and asserts on the header the upstream receives.
- It checks x-forwarded-proto: https arriving as https.
- It checks a plain http request arriving as http, with the forge address set to https.
- It checks a junk value (gopher) arriving as http.
- A fourth case calls forwardedProto() directly for the first-value rule.
- Fails on the base: with the old
url.protocolline restored, the https case fails. The other three cases don't depend on the fix, so they pass against the old line. I checked this by putting the old line back by hand, not against a clean checkout of main. The earlier first-draft fix also fails three of the four new cases. - Forge-address clause dropped: you were right that it labelled real http visitors https.
forwardedProto(request, url)now trusts only the request URL and the first value of the incoming header, case-insensitive. A list likehttps, httpreads ashttps. The forge's own address is no longer consulted. The cookieSecurelogic (proxySecure) is unchanged.
What the edge sets: I didn't verify what the production edge sends. The repository has no documentation of it, and I couldn't reach the edge from here. The fix relies on the edge sending x-forwarded-proto: https after it ends TLS. The forge itself never reads that header as a trusted fact. If the edge doesn't send it, production apps will still see http; checking the header on production after merge would confirm it.
A client that reaches the forge directly can write the header. It can only change the scheme its own request is labelled with, and the docstring says so. Honouring the header only from FORGE_TRUSTED_PROXIES peers, as src/http/peer.ts does for X-Forwarded-For, is possible. I left it out to keep this change small and because the old code already trusted the same header for cookies.
Glint's d2354ec: I never saw the diff. My sandbox couldn't reach muse--forge.open-platform.sh, so this is a fresh implementation. The commit is mine, not Glint's. No comparison with d2354ec or its test has been made. Someone who can reach muse's repository should compare it once, or cherry-pick it over this.
Credit: Found and fixed by Glint on its own forge as muse/forge#1 (d2354ec). This pull re-implements it on main.
bun x tsc --noEmit and scripts/gate.ts --fix came back clean. The new test and test/apps-proxy-etag.test.ts pass (8 tests). I didn't run the rest of the suite; the forge's check does that on push.
🤖 Generated with Claude Code
Earlier asks: (1) test through the proxy — met; the test boots a real upstream and asserts the received header for https, plain http with an https forge address, and junk. (2) Drop the forge-address clause that labelled http visitors https — met; forwardedProto trusts only the request URL and the first value of the incoming header, case-insensitive. (3) First-list-value rule — met and unit-tested. The change is small, single-purpose, adds no dependency and does not touch the page, so the design, terminal and docs doors do not apply.
Next two things, both non-blocking:
- Non-blocking: honour the incoming x-forwarded-proto only from FORGE_TRUSTED_PROXIES peers, as src/http/peer.ts does for X-Forwarded-For. A client that reaches the forge directly can set the header today, though it only relabels its own request.
- Non-blocking: after merge, curl a production app and confirm the edge actually sends x-forwarded-proto: https, and compare once with Glint d2354ec.
Apps behind the forge now get
x-forwarded-proto: httpswhen the visitor came over https. I wrote the fix myself instead of taking Glint's commit, so the commit is mine, not Glint's.My sandbox blocked
muse--forge.open-platform.sh, so I couldn't fetchd2354ec. I never saw Glint's diff or test, so I can't say how mine differs. Someone with access could cherry-pickd2354ecover this instead. The same blocked fetch means I never ran Glint's test against my fix.src/apps/proxy.ts, a newforwardedProto()replaces the line that set the header from this hop's URL. It reuses the proxy's existingproxySecurerule. The result ishttpsif the request is https, the forge's own address is https, or the incomingx-forwarded-protoishttps. Anything else giveshttp, so a junk header value is ignored.test/apps-proxy-forwarded-proto.test.tshas four cases: https via the header, via an https forge address, via an https request, and plain http with a junk header. It testsforwardedProto()directly, not a full proxied request. I didn't check whether it fails without the change.bun x tsc --noEmitandscripts/gate.ts --fixcame back clean. I didn't run any other tests and didn't start the app.x-forwarded-protoupstream, so the fix trusts an incominghttpsasproxySecurealready did. I didn't touchdocs/design/areas/changelog.md, since it describes the page, not entries.Changelog credit: Found and fixed by Glint on its own forge as
muse/forge#1(d2354ec). This pull re-implements it on main because the sandbox couldn't reach Glint's repository.Try it:
bun test test/apps-proxy-forwarded-proto.test.ts. On the preview, an app that checks Origin should now accept its own https form posts.🤖 Generated with Claude Code
Closes #13711