CVE-2021-31525: Panic due to large headers in net/http and golang.org/x/net/http/httpguts

stdlib Updated 02 Oct 2025

Summary

15/07/2022
Yes i
Unrated
Not published

CVE-2021-31525: Panic due to large headers in net/http and golang.org/x/net/http/httpguts. Affects stdlib across 2 version ranges.

< 1.15.12 >= 1.16.0-0, < 1.16.4

Fixed in 1.15.12 or 1.16.4, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-31525 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

The package under scrutiny is the Go standard library (stdlib) and the golang.org/x/net package. The stdlib package provides a collection of packages for building HTTP servers and clients, while the golang.org/x/net package contains additional networking libraries. These packages are widely used in Go applications for handling HTTP requests and responses. However, a vulnerability has been discovered that allows a malicious HTTP server or client to cause a panic in the net/http client or server. This vulnerability affects the Transport and Client components and can lead to a program crash. The Server component is not vulnerable by default, but can be if the default max header size is overridden. The golang.org/x/net/http2/h2c package and the HeaderValuesContainsToken function in golang.org/x/net/http/httpguts are also affected.

Vulnerability Detail

The vulnerability arises when the net/http client or server attempts to read a very large header. If the header size exceeds a certain threshold (over 7MB on 64-bit architectures or over 4MB on 32-bit ones), an unrecoverable panic occurs. This can be exploited by a malicious server to crash the client or a malicious client to crash the server. The panic occurs in the ReadRequest and ReadResponse functions of the net/http package. The golang.org/x/net/http2/h2c package and the HeaderValuesContainsToken function in golang.org/x/net/http/httpguts are also susceptible to this vulnerability. The impact of this vulnerability is a denial-of-service (DoS) condition, where the affected program crashes and becomes unresponsive.

How To Fix

Latest published version: go1.25.5 as of 22 Oct 2026

go get stdlib@vgo1.25.5

Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.

If you can't move to the latest

The minimum fixed version depends on the release line you run.

  • < 1.15.12 1.15.12
    go get stdlib@v1.15.12
  • >= 1.16.0-0, < 1.16.4 1.16.4
    go get stdlib@v1.16.4

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

If updating to the latest versions is not immediately feasible, a workaround can be implemented by limiting the maximum header size in the affected components. For the net/http package, the maximum header size can be set using the Server.MaxHeaderBytes configuration option. By setting this value to a lower limit, such as 1MB, the program can be protected from crashing due to large headers. However, it is important to note that this workaround may impact the functionality of the application if legitimate requests require larger headers. Therefore, it is recommended to update to the latest versions as soon as possible.

Conclusion

In conclusion, the CVE-2021-31525 vulnerability in the net/http and golang.org/x/net/http/httpguts packages can be exploited by a malicious server or client to cause a panic in the affected components. This can lead to a denial-of-service condition where the program crashes. To mitigate this vulnerability, it is recommended to update to the latest versions of the Go standard library and its dependencies. Additionally, setting a lower limit for the maximum header size in the affected components can serve as a temporary workaround. Regularly updating the Go standard library and staying informed about security vulnerabilities is crucial for maintaining the security of Go applications.

See every vulnerability recorded for stdlib →

Share this vulnerability

FAQ

The impact of this vulnerability is a denial-of-service (DoS) condition, where the affected program crashes and becomes unresponsive.

The net/http client and server components, as well as the golang.org/x/net/http2/h2c package and the HeaderValuesContainsToken function in golang.org/x/net/http/httpguts, are affected by this vulnerability.

Yes, a malicious server can exploit this vulnerability to crash the net/http client.

Yes, a malicious client can exploit this vulnerability to crash the net/http server if the Server.MaxHeaderBytes configuration option is set to a higher value.

No, the net/http server is not vulnerable by default. However, if the Server.MaxHeaderBytes configuration option is overridden with a higher value, the server can become vulnerable.

Related vulnerabilities

Recent vulnerabilities recorded for stdlib.

How To Fix

Latest published version: go1.25.5 as of 22 Oct 2026

go get stdlib@vgo1.25.5

Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.

If you can't move to the latest

The minimum fixed version depends on the release line you run.

  • < 1.15.12 1.15.12
    go get stdlib@v1.15.12
  • >= 1.16.0-0, < 1.16.4 1.16.4
    go get stdlib@v1.16.4

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback