gateway: a client-supplied X-Forwarded-Host picks which PublicGateways rules apply, with no way to turn the trust off

Open
#1,225 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
46/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend, security

Research direction

Read gateway/hostname.go and gateway/handler.go, especially NewHostnameHandler and isDeserializedResponsePossible; the issue gives the relevant code paths and an example configuration. First inspect how gateway Config is defined and how Kubo configures it, then check the gateway tests for hostname routing and trustless responses. Done means the trust in forwarded host and proto can be controlled as described, with the example no longer bypassing the configured per-host rules.

Written by the indexing model from the issue text.

Description

The gateway honours a client-supplied X-Forwarded-Host on every request, with no setting to turn it on or off. That header is what selects the PublicGateways entry, and with it the per-hostname rules. So a client talking to the gateway directly can choose which rules apply to its own request, including "none": the global defaults.

Where (at 3d6ac39):

  • The hostname handler: NewHostnameHandler replaces r.Host with the header (gateway/hostname.go L46–L51). It then uses that value for the known-gateway match, the subdomain match and the DNSLink fallback (L54–L217).
  • The trustless check: isDeserializedResponsePossible lets the header override everything when it picks the entry whose DeserializedResponses applies (gateway/handler.go L375–L397). That function decides whether a non-trustless request is refused (L293–L298).

Example, on a gateway exposed without a proxy:

  • The setup: PublicGateways has "trustless.example.com": {"Paths": ["/ipfs"], "NoDNSLink": true, "DeserializedResponses": false}. The global settings are Kubo's defaults (Gateway.DeserializedResponses: true, Gateway.NoDNSLink: false).
  • The request: GET /ipns/<name>/index.html, sent to trustless.example.com with X-Forwarded-Host: other.invalid.
  • The routing: the hostname handler finds no entry for other.invalid and falls through to plain path handling (L219–L220). So /ipns is served although the entry allows only /ipfs.
  • The trustless check: other.invalid isn't a key in PublicGateways, so the global DeserializedResponses: true applies, and the client gets a deserialized response from a hostname configured as trustless-only.
  • DNSLink: with X-Forwarded-Host naming a DNSLink domain instead, the global NoDNSLink: false applies, and that domain's DNSLink site is served (L212–L216), whatever NoDNSLink says for trustless.example.com.

Scope: only the requester's own response changes; a browser can't set this header on a navigation. This assumes nothing in front of the gateway caches responses without X-Forwarded-Host in the cache key. A cache that passes a client's header through, and doesn't key on it, would hand the chosen response to everyone.

Context: the subdomain-gateway spec lists X-Forwarded-Host as an optional request header for gateways behind a reverse proxy (spec), and boxo's AGENTS.md names the trust placed in it. So honouring it is intended. What isn't there is a way to restrict it to the deployments that have such a proxy.

Suggested fix:

  • Make trust in X-Forwarded-Host (and X-Forwarded-Proto) opt-in in Config, for example a flag or a list of trusted proxy addresses, defaulting off for new users. Kubo can turn it on for its existing behaviour.
  • Alternatively, honour the header only when its value is itself a configured PublicGateways hostname, so it can't select the global defaults or an arbitrary DNSLink name.

Filed in public because this is specified behaviour, and its effect is limited to the requester's own responses. If you'd rather handle it through [email protected], I'm glad to move it there.

🤖 Generated with Claude Code

Dominant language
Go
Stars
326
Forks
165
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ipfs/boxo

All issues in ipfs/boxo

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.