Skip to content

Commit

Permalink
Update proxy_test for golang 1.20.6
Browse files Browse the repository at this point in the history
Starting in golang 1.20.6, the creation of requests with invalid
host headers returns an error prior to sending the request on the
wire to a server. To compensate, we now test with a raw TCP connection
instead of our HTTP request/response helpers.
  • Loading branch information
geofffranks committed Jul 12, 2023
1 parent 05f2266 commit 7c163e5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,14 +1598,19 @@ var _ = Describe("Proxy", func() {
})

It("responds to host with malicious script with 400", func() {
conn := dialProxy(proxyServer)
conn, err := net.Dial("tcp", proxyServer.Addr().String())
defer conn.Close()
Expect(err).NotTo(HaveOccurred())

req := test_util.NewRequest("GET", "<html><header><script>alert(document.cookie);</script></header><body/></html>", "/", nil)
conn.WriteRequest(req)
rawReq := "GET / HTTP/1.1\nHost: <html><header><script>alert(document.cookie);</script></header><body/></html>\n\n\n"

resp, body := conn.ReadResponse()
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
Expect(body).To(ContainSubstring("malformed Host header"))
conn.Write([]byte(rawReq))

resp, err := ioutil.ReadAll(conn)
Expect(err).ToNot(HaveOccurred())

Expect(string(resp)).To(ContainSubstring("HTTP/1.1 400 Bad Request")) // status header
Expect(string(resp)).To(ContainSubstring("400 Bad Request: malformed Host header")) // body
})

It("responds with 404 for a not found host name with only valid characters", func() {
Expand Down

0 comments on commit 7c163e5

Please sign in to comment.