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

Aperta
#1,225 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
46/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, security

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Go
Stelle
326
Fork
165
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ipfs/boxo

Tutte le issue di ipfs/boxo

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.