Skip to content

Commit 1d57292

Browse files
dmitshurgopherbot
authored andcommitted
x509roots: check HTTP response status code and media type
The HTTP response status code is expected to be 200 OK, and the certdata.txt file media type is expected to be plain text. Check that it is before proceeding with parsing it. Might help avoid repeats of CL 535735. Change-Id: I1a7896b3e20d33a23fdc53c572ae9700c9eae1ef Reviewed-on: https://go-review.googlesource.com/c/crypto/+/536717 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Commit-Queue: Roland Shoemaker <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]>
1 parent 8779cbd commit 1d57292

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

x509roots/gen_fallback_bundle.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go/format"
1818
"io"
1919
"log"
20+
"mime"
2021
"net/http"
2122
"os"
2223
"sort"
@@ -86,6 +87,16 @@ func main() {
8687
log.Fatalf("failed to request %q: %s", *certDataURL, err)
8788
}
8889
defer resp.Body.Close()
90+
if resp.StatusCode != http.StatusOK {
91+
body, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<10))
92+
log.Fatalf("got non-200 OK status code: %v body: %q", resp.Status, body)
93+
} else if ct, want := resp.Header.Get("Content-Type"), `text/plain; charset="UTF-8"`; ct != want {
94+
if mediaType, _, err := mime.ParseMediaType(ct); err != nil {
95+
log.Fatalf("bad Content-Type header %q: %v", ct, err)
96+
} else if mediaType != "text/plain" {
97+
log.Fatalf("got media type %q, want %q", mediaType, "text/plain")
98+
}
99+
}
89100
certdata = resp.Body
90101
}
91102

0 commit comments

Comments
 (0)