Skip to content

rewrite_host sends two Host headers to HTTP/1.1 backends #1908

Closed

Description

@Shine-neko

With rewrite_host set on an HTTP frontend, the request forwarded to an HTTP/1.1 backend carries two Host headers. Servers that reject duplicate Host headers (Go's net/http, for instance) answer 400 Bad Request.

Reproduction (sozu 2.3.3)

worker_count = 1
activate_listeners = true

[[listeners]]
protocol = "http"
address = "127.0.0.1:18080"

[clusters.backend]
protocol = "http"
frontends = [
  { address = "127.0.0.1:18080", hostname = "client.example", rewrite_host = "backend.example" },
]
backends = [ { address = "127.0.0.1:18081" } ]
printf 'HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok' | nc -l 127.0.0.1 18081 &
sozu start -c config.toml &
curl -H "Host: client.example" http://127.0.0.1:18080/x

Request received by the backend:

GET /x HTTP/1.1
Host: backend.example
User-Agent: curl/8.18.0
Accept: */*
X-Forwarded-For: 127.0.0.1
Forwarded: proto=http;for="127.0.0.1:33884";by=127.0.0.1
X-Forwarded-Port: 18080
X-Forwarded-Proto: http
X-Request-Id: 01M5PT3YGMY469ES6N0P5C5KXM
Sozu-Id: 01M5PT3YGMY469ES6N0P5C5KXM
Host: backend.example
X-Forwarded-Host: client.example

Expected

A single Host: backend.example.

Cause

apply_request_rewrites_and_headers (lib/src/protocol/mux/router.rs) rewrites the status-line authority, drops the existing Host header blocks, then inserts a synthetic Host block. The H1 converter (kawa::protocol::h1::converter) already writes Host: <authority> right after the request line, from the authority just rewritten, so the synthetic block duplicates it. Its doc comment states the wire never carries two Host headers, which does not hold for H1 backends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions