net/http: reject control characters in Response.Write#79161
net/http: reject control characters in Response.Write#79161DhruvilK7 wants to merge 1 commit intogolang:masterfrom
Conversation
Response.Write did not validate the Status field for control characters before writing it to the wire. A crafted Status value containing \r\n could inject arbitrary headers into the response. Add a stringContainsCTLByte check on the status text, mirroring the existing validation for Request.URL in Request.Write. Also convert respWriteTest entries to use named fields and add a WantError field to the test struct so future error-case tests can be added as table entries. Fixes golang#78774
|
This PR (HEAD: 71e05ec) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/773420. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/773420. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/773420. |
Summary
Fixes #78774.
Problem
Response.Write did not validate the Status field for control characters before writing it to the wire. A crafted Status value containing \r\n could inject arbitrary headers into the HTTP response, enabling response splitting attacks.
Solution
Add a stringContainsCTLByte check on the status text in Response.Write, mirroring the existing validation for Request.URL in Request.Write. Return an error if control characters are detected.
Changes