Skip to content

handle the Host header case-insensitively - #678

Merged
firefart merged 1 commit into
OJ:devfrom
protonnegativo:fix/host-header-case
Oct 28, 2026
Merged

firefart merged 1 commit into
OJ:devfrom
protonnegativo:fix/host-header-case

Conversation

@protonnegativo

Copy link
Copy Markdown

A Host header passed with -H is only used when the name is spelled exactly Host. Any other casing is silently dropped, so the requests go out with the Host from the URL.

$ gobuster dir -u http://127.0.0.1:19600 -w words -H 'host: target.local'
# server receives Host: 127.0.0.1:19600   (expected target.local)

$ gobuster dir -u http://127.0.0.1:19600 -w words -nch -H 'host: target.local'
# server receives two Host headers: 127.0.0.1:19600 and target.local

NewHTTPClient compares h.Name == "Host", while header names are matched case-insensitively everywhere else (fuzz mode already uses http.CanonicalHeaderKey for this). With --no-canonicalize-headers the lowercase name also goes into req.Header as is, and net/http only filters the canonical Host key, so it is written as an extra header.

This uses http.CanonicalHeaderKey for the check and skips the Host entry when copying the custom headers, since it is already applied through req.Host.

Testing:

  • Added TestRequestHostHeader in libgobuster/http_test.go (the host, HOST and -nch cases fail without the change)
  • go vet ./..., go test -race -cover ./..., gofumpt -l ., golangci-lint run ./...
  • Manual check against a local server with dir and fuzz mode: Host is target.local for host:, HOST: and -nch -H 'host: ...'

A Host header passed via -H was only applied when the name was exactly
"Host". Any other casing (e.g. -H 'host: example.com') was silently
ignored, and with --no-canonicalize-headers it was sent as a second Host
header next to the one derived from the URL.
@firefart
firefart merged commit d74730c into OJ:dev Oct 28, 2026
@firefart

Copy link
Copy Markdown
Collaborator

thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants