Skip to content

Commit c4e24c5

Browse files
committed
fix: add timeouts to HTTP server
- Added ReadHeaderTimeout, ReadTimeout, and IdleTimeout to HTTP server for improved security and reliability
1 parent 78eed25 commit c4e24c5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pkg/adapter/adapter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ func (l *listener) Start(ctx context.Context) error {
9393

9494
mux.HandleFunc("/", l.handleEvent(ctx))
9595

96-
//nolint: gosec
9796
srv := &http.Server{
9897
Addr: ":" + adapterPort,
9998
Handler: http.TimeoutHandler(mux,
10099
httpTimeoutHandler, "Listener Timeout!\n"),
100+
ReadHeaderTimeout: 5 * time.Second,
101+
ReadTimeout: 10 * time.Second,
102+
IdleTimeout: 30 * time.Second,
101103
}
102104

103105
enabled, tlsCertFile, tlsKeyFile := l.isTLSEnabled()

pkg/cmd/tknpac/bootstrap/web.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net/http"
99
"path/filepath"
10+
"time"
1011

1112
"github.com/openshift-pipelines/pipelines-as-code/pkg/cli/browser"
1213
"github.com/openshift-pipelines/pipelines-as-code/pkg/cli/info"
@@ -19,7 +20,13 @@ import (
1920
func startWebServer(ctx context.Context, opts *bootstrapOpts, run *params.Run, jeez string) error {
2021
m := http.NewServeMux()
2122
//nolint: gosec
22-
s := http.Server{Addr: fmt.Sprintf(":%d", opts.webserverPort), Handler: m}
23+
s := http.Server{
24+
Addr: fmt.Sprintf(":%d", opts.webserverPort),
25+
Handler: m,
26+
ReadHeaderTimeout: 5 * time.Second,
27+
ReadTimeout: 10 * time.Second,
28+
IdleTimeout: 30 * time.Second,
29+
}
2330
codeCh := make(chan string)
2431
m.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
2532
code := r.URL.Query().Get("code")

0 commit comments

Comments
 (0)