Skip to content

Bound hostname length in parseHost before IDNA conversion - #162

Merged
alexwoz merged 1 commit into
google:masterfrom
Harbus2918:fix/host-length-limit
Nov 16, 2026
Merged

alexwoz merged 1 commit into
google:masterfrom
Harbus2918:fix/host-length-limit

Conversation

@Harbus2918

@Harbus2918 Harbus2918 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enforce a 4,096-byte upper bound on the unescaped hostname in parseHost (urls.go) before calling idna.ToASCII.

Details

parseHost currently passes hostnames of arbitrary length directly to idna.ToASCII. Since RFC 1035 caps DNS names at 253 octets, a 4,096-byte limit (applied after stripping userinfo@ and :port) generously accommodates valid pre-IDNA Unicode hostnames while rejecting malformed or oversized inputs early with "safebrowsing: host too long".

Changes

  • urls.go: Validate len(u) <= 4096 after unescape(host) in parseHost.
  • urls_test.go: Add TestParseHostMaxLength covering oversized raw/percent-encoded hostnames, boundary cases around 4,096 bytes, user:pass@host:port handling, and valid IDN hostnames.

Testing

  • go test -v -race -mod=vendor . ./cmd/... ./internal/... — unit tests pass (3 live-API system tests skipped without -apikey).
  • go build -mod=vendor ./... — succeeds.

@alexwoz
alexwoz merged commit 0257ee6 into google:master Nov 16, 2026
7 checks passed
@Harbus2918
Harbus2918 deleted the fix/host-length-limit branch November 16, 2026 20:16
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