Go 1.27 Adds MaxHeaderValueCount to http.Server to Cap Header Value CountsBrief · digest for November 26
Brief≈ 1 min

Go 1.27 Adds MaxHeaderValueCount to http.Server to Cap Header Value Counts

Previously, http.Server only capped the combined byte size of headers and the request line via MaxHeaderBytes (1 MiB by default, excluding the request body). Teams often raise that limit for large tokens or SSO cookies, which lets an attacker flood the server with hundreds of tiny headers while staying under the byte cap.

Go 1.27 adds an item-count limit: MaxHeaderValueCount. If left unset, DefaultMaxHeaderValueCount = 500 applies automatically:

srv := &http.Server{
    Addr: ":8080",
    // 1 MiB for headers and request line
    MaxHeaderBytes: 1 << 20,
    // Limit by number of values (128 is an example; default is 500)
    MaxHeaderValueCount: 128,
}

A line like X-Tag: a, b counts as one value, whereas two separate X-Tag lines count as two. The exception is Trailer (which declares headers sent after the body): its comma-separated entries count individually so one line can't bypass the limit. Check traffic from your proxies, WAF, and CDN before lowering the cap below 500—and once you upgrade to Go 1.27, the default kicks in on its own.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 3