What this thread does
Do first: run rg -n 'ListenAndServe|http.Server|ReadHeaderTimeout|ReadTimeout|WriteTimeout|IdleTimeout|MaxHeaderBytes|MaxBytesReader' --glob '*.go' . and trace the listener and body-reading code used by your public route.
As of November 2026, this recipe targets Go 1.27.3 and govulncheck v1.9.0; reference date: 2026-11-08. If the real listener has no deadlines, start with branch 1; if a handler reads an unbounded body, start with branch 2; if both protections exist, start with branch 3. Every service still needs all three checks. A source hit is only a lead: confirm which server instance and middleware chain your route uses.
1. Slow clients can occupy connections indefinitely
As of November 2026, Go 1.27.3: follow the versioned http.Server fields. For a short JSON API, an illustrative configuration is below. Import net/http, time and log; appHandler means your existing application handler.
srv := &http.Server{
Addr: ":8080",
Handler: appHandler,
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
MaxHeaderBytes: 32 << 10,
}
log.Fatal(srv.ListenAndServe())
Choose durations from legitimate request sizes and response times. ReadHeaderTimeout bounds header reading; ReadTimeout includes the body; WriteTimeout bounds response writes; IdleTimeout bounds waiting for another keep-alive request. These fields have distinct scopes. They do not forcibly terminate arbitrary handler computation.
For an HTTP/1.1 check, send incomplete headers to the service with a socket client and wait beyond the configured header deadline: the connection should close. Then send valid headers with a body delivered beyond ReadTimeout and confirm the read cannot remain pending indefinitely. Replay a legitimate request near your permitted size and duration too. Repeat through the real reverse proxy, since proxy buffering and deadlines change what the application sees.
The numbers above are proposed starting values, not a universal policy. Fixed response deadlines require a separate design for streaming or long uploads. Serve public traffic through your configured HTTPS listener or TLS-terminating proxy; the cleartext listener above illustrates server fields.
2. A large or chunked body can exhaust memory
As of November 2026, Go 1.27.3: use http.MaxBytesReader before reading or decoding. MaxHeaderBytes does not bound the body. For a small JSON endpoint, the following handler fragment caps the bytes read at 1 MiB; import encoding/json, errors, io and net/http.
r.Body = http.MaxBytesReader(w, r.Body, 1<<20)
defer r.Body.Close()
var input struct {
Name string
}
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()
err := dec.Decode(&input)
if err == nil {
var extra any
err = dec.Decode(&extra)
if err == io.EOF {
err = nil
} else if err == nil {
err = errors.New("multiple JSON values")
}
}
if err != nil {
var tooLarge *http.MaxBytesError
if errors.As(err, &tooLarge) {
http.Error(w, "body too large", http.StatusRequestEntityTooLarge)
} else {
http.Error(w, "invalid JSON", http.StatusBadRequest)
}
return
}
// Apply your field validation before performing any writes.
Adapt input to the actual schema. The second decode requires EOF after the one JSON value. Rejected requests can return before consuming the rest of the body. The Go JSON decoder API defines decoding and unknown-field rejection.
Send a valid small object, an otherwise valid object whose Name string exceeds 1 MiB, an oversized whitespace suffix after a valid object, and two concatenated small JSON objects. Expect the normal application response, 413, 413 and 400 respectively, with no application writes for rejected requests. Repeat the oversized case with chunked transfer and no Content-Length: the reader limit must still apply. If application code decompresses request bodies, separately cap the decompressed stream; an input-byte cap alone does not bound decompressed size.
3. Limits exist: scan the dependencies and toolchain you ship
As of November 2026, Go 1.27.3 with govulncheck v1.9.0: from the module directory, run:
go install golang.org/x/vuln/cmd/govulncheck@v1.9.0
govulncheck ./...
Ensure the Go binary directory is on PATH. Use the deployment's GOOS, GOARCH and build tags; -tags selects tags for the scan. Source analysis uses the Go toolchain on PATH, so scan with the toolchain used to build production.
For a reachable finding, inspect the call path and the reported fixed version. Upgrade that specific module to its reported fixed version, review the go.mod/go.sum changes, exercise the affected behavior, rebuild and repeat govulncheck ./.... For a standard-library finding, update the Go toolchain and rebuild the deployment. Confirm the artifact with go version -m ./service; optionally run govulncheck -mode=binary ./service (official deployment guidance, 2026-10-26).
The plain text command exits unsuccessfully on findings. JSON/SARIF/OpenVEX output modes have different exit behavior, so do not replace a CI gate with an export-only command and assume equivalent failure semantics. Reflection, unsafe code and build configuration limit what static analysis can establish; a clean report is not a complete security assessment.
Evidence and limits
The release history dates Go 1.27.3 to 2026-10-19, including a certificate security fix. Filippo Valsorda's Cloudflare report, 2016-06-29, explains connection leaks from missing timeouts; use the current field definitions above for this version. In issue #78662, 2026-04-12, artyom reports that govulncheck v1.1.4 can print a clean result with no package arguments. This is historical evidence for using an explicit package pattern, not a claim that v1.9.0 has that behavior.
Timeouts and byte limits address resource consumption at these boundaries. Authentication, authorization, rate limits, TLS deployment and application-specific validation still require their own controls. The shown body reader buffers decoder state and decoded values within the request policy; choose a smaller cap or a streaming schema when needed. Handler code must return after rejection and avoid side effects until validation finishes.
Not for: Fastify login rate limits; see fastify-login-rate-limit-trusted-proxy
Started from a post by @Filippo Valsorda, packaged by the editor. Original post