Repository navigation
fix(nginx): redirect to https, so none drops to http - #1146
Merged
Merged
Conversation
TLS ends before nginx, so $scheme is always http and every redirect to this site sent browsers to http first. Redirect to https://$host/... instead: one hop, never http. Paths, query handling and statuses are unchanged. Co-Authored-By: Claude Opus 5.5 <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.
Problem
TLS ends before nginx (Cloudflare → Envoy Gateway → plain http on :80), so
$schemeis alwayshttp. Every redirect to this site was built as$scheme://$http_host/.... As a result,https://thegraph.com/docs/→ 301http://thegraph.com/docs/en/→ (Cloudflare "Always Use HTTPS") →https://thegraph.com/docs/en/. That is an extra hop and a downgrade to http.Change
All 194
$scheme://$http_host/...targets innginx.confbecomehttps://$host/...: the normalisation rules, the locale rules, every permanent (301) redirect and the two temporary (302) ones. Paths, query-string handling (rewritestill appends args exactly as before) and statuses are unchanged. No other file changes.Why absolute, not relative: we tried relative redirects (
absolute_redirect off). They turn/\evilintoLocation: /\evil/, and browsers read/\as//, which makes it an open redirect to another site. An absolutehttps://<host>/target pins the host.Why
$hostand not$http_host:$hostis the name nginx matched for the request (lowercased, port stripped), not the raw header. Behind Cloudflare it is alwaysthegraph.comor the staging host.thegraph.com:8443now giveshttps://thegraph.com/..., not a port on https. The server block has noserver_name, so it is the catch-all: a direct request with a foreignHost(evil.example) still getshttps://evil.example/..., as it gothttp://evil.example/...before. Only the client that sends that header sees it, so it cannot redirect someone else's browser. The existingX-Forwarded-Proto→ https rule is kept as is.Tested (nginx:1.16.0-alpine, this conf, minimal static tree,
Host: thegraph.com)/docs/http://thegraph.com/docs/en/https://thegraph.com/docs/en//docshttp://…/docs/https://…/docs//docs/enhttp://…/docs/en/https://…/docs/en//docs/eshttp://…/docs/es/https://…/docs/es//docs/en//docs/en/subgraphs/http://…/docs/en/subgraphs/overview/https://…/docs/en/subgraphs/overview//docs/en/subgraphs/?a=1http://…/subgraphs/overview/?a=1https://…/subgraphs/overview/?a=1/docs/es/subgraphs/?a=1http://…/docs/en/subgraphs/?a=1https://…/docs/en/subgraphs/?a=1/docs/en/billing/http://…/subgraphs/providers/graph-foundation/overview/https://…/subgraphs/providers/graph-foundation/overview//docs/en/cookbook/grafting/?x=yhttp://…/best-practices/grafting/?x=yhttps://…/best-practices/grafting/?x=y/docs/en/resources/delegating/undelegating/http://…/resources/delegating/#how-to-undelegate-on-the-graphhttps://…(same path)/docs/en/supported-networks/btc/http://…/supported-networks/bitcoin/https://…/supported-networks/bitcoin//docs/en/querying/graph-client/http://…/graph-client/README/https://…/graph-client/README//docs/en/hypergraph/(external)https://github.com/graphprotocol/hypergraph/docs/_next/a.js/docs/en/no-such-page//nope.txt/\evil,/%5Cevilhttp://thegraph.com/\evil/https://thegraph.com/\evil///evil,/%2F%2Fevilhttp://thegraph.com/evilhttps://thegraph.com/evil/docs//evilhttp://thegraph.com/docs/evilhttps://thegraph.com/docs/evilHost: thegraph.com:8443/docs/http://thegraph.com:8443/docs/en/https://thegraph.com/docs/en/Host: evil.example/docs/http://evil.example/docs/en/https://evil.example/docs/en/The full 28-path matrix (plus slash-normalisation cases) matches line for line: the same status and the same path and query on every row. The only differences are
http→httpsand the$hostnormalisation. NoLocationis protocol-relative.Expected live result:
https://thegraph.com/docs/→ 301https://thegraph.com/docs/en/→ 200. One hop, never http.Release safety
When this PR was opened,
mainwas identical tov2.1.16(compare/v2.1.16...main: ahead_by 0). Tag the release at this PR's merge commit. Staging followslatest(built from main byimage.yml). Production only moves on avX.Y.ZGitHub release, whose tagrelease.ymlcopies from the main build's image.🤖 Generated with Claude Code