Security Implications of net/textproto.Reader Misuse
The Go net/textproto.Reader reads an unbounded line into memory, and net/http.Request.FormValue uses it without a proper limit, so an attacker can send a request with a huge Content-Length and an endless multipart header to exhaust memory and crash the server.
Published on nowotarski.info
In September 2023 I discovered an issue in Golang’s net/textproto.Reader. In one of its internal methods (readLineSlice), the code (in an infinite loop) reads data from bufio.Reader and concatenates to line: previously read data.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the textproto reader concatenates data in a loop until a newline arrives, and callers such as net/http do not wrap the input in a size-limiting reader, so the Content-Length value is trusted without a cap.
Impact
A remote attacker could cause an out-of-memory crash of a Go HTTP server that calls FormValue on multipart requests, and the issue was fixed in Go 1.21.8 and 1.22.1.
What the attacker needed
Server calls FormValue on multipart data; attacker can send HTTP requests; no size limit on the request body
How it was found
- Send an HTTP request with a very large Content-Length value.
- Use a multipart/form-data body with a single part.
- Give the part a header name that never ends, so no newline is sent.
- The server keeps reading the header into memory until it crashes.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Some Go code reads a line of text from a network connection without any maximum size. If an attacker keeps sending data and never sends a newline, the program keeps storing it in memory until the machine runs out of memory and crashes. This is called a denial of service: the attacker does not steal data, they just stop the service from working.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.