Skip to content

Commit 0852717

Browse files
committed
panicweb: Set http.Server.ReadHeaderTimeout to 2s
This silences gosec G114 and fixes the slowloris DoS attack.
1 parent c95a0e4 commit 0852717

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

cmd/panicweb/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ func main() {
107107
w.Header().Set("Content-Type", "text/html; charset=utf-8")
108108
_, _ = w.Write(rootPage)
109109
})
110-
go http.Serve(ln, http.DefaultServeMux)
110+
srv := &http.Server{
111+
Handler: http.DefaultServeMux,
112+
ReadHeaderTimeout: 2 * time.Second,
113+
}
114+
go srv.Serve(ln)
111115

112116
// Start many clients.
113117
a := ln.Addr()

stack/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ func identifyPanicwebSignature(t *testing.T, b *Bucket, pwebDir string) panicweb
23522352
t.Fatal("expected Locked")
23532353
}
23542354
// This is a change detector on internal/main.go.
2355-
want := Stack{Calls: []Call{newCallLocal("main.main", Args{}, pathJoin(pwebDir, "main.go"), 141)}}
2355+
want := Stack{Calls: []Call{newCallLocal("main.main", Args{}, pathJoin(pwebDir, "main.go"), 145)}}
23562356
compareStacks(t, &b.Signature.CreatedBy, &want)
23572357
for i := range b.Signature.Stack.Calls {
23582358
if strings.HasPrefix(b.Signature.Stack.Calls[i].ImportPath, "github.com/mattn/go-colorable") {

0 commit comments

Comments
 (0)