diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 000000000..8ffb226ec --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2026-08-13 - [CWE-400 Slowloris Prevention] +**Vulnerability:** Missing `ReadHeaderTimeout` in `http.Server` initialization. +**Learning:** The default `http.Server` lacks a read header timeout, leading to potential Slowloris Denial of Service attacks when exposing the server. This often gets flagged as G112 by gosec. +**Prevention:** Always configure `ReadHeaderTimeout` when creating a new `http.Server` instance. diff --git a/internal/mcp/oauth.go b/internal/mcp/oauth.go index 678d58045..4722a5817 100644 --- a/internal/mcp/oauth.go +++ b/internal/mcp/oauth.go @@ -409,6 +409,7 @@ func Login(ctx context.Context, options LoginOptions) (StoredToken, error) { } resultChan := make(chan callbackResult, 1) server := &http.Server{ + ReadHeaderTimeout: 5 * time.Second, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/callback" { http.NotFound(w, r) diff --git a/internal/oauth/loopback.go b/internal/oauth/loopback.go index 6b29e0f27..d075d64ca 100644 --- a/internal/oauth/loopback.go +++ b/internal/oauth/loopback.go @@ -50,7 +50,10 @@ func NewLoopbackListenerOnPort(state string, port int) (*LoopbackListener, error state: state, result: make(chan callbackResult, 1), } - l.server = &http.Server{Handler: http.HandlerFunc(l.handle)} + l.server = &http.Server{ + ReadHeaderTimeout: 5 * time.Second, + Handler: http.HandlerFunc(l.handle), + } go func() { _ = l.server.Serve(ln) }() return l, nil } diff --git a/internal/provideroauth/openrouter.go b/internal/provideroauth/openrouter.go index 8a99b3148..d11d6e13d 100644 --- a/internal/provideroauth/openrouter.go +++ b/internal/provideroauth/openrouter.go @@ -79,26 +79,29 @@ func OpenRouterLogin(ctx context.Context, opts OpenRouterOptions) (string, error codeCh := make(chan string, 1) errCh := make(chan error, 1) - server := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/callback" { - http.NotFound(w, r) - return - } - if code := strings.TrimSpace(r.URL.Query().Get("code")); code != "" { - _, _ = io.WriteString(w, "OpenRouter authorization complete. You may close this window.") + server := &http.Server{ + ReadHeaderTimeout: 5 * time.Second, + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/callback" { + http.NotFound(w, r) + return + } + if code := strings.TrimSpace(r.URL.Query().Get("code")); code != "" { + _, _ = io.WriteString(w, "OpenRouter authorization complete. You may close this window.") + select { + case codeCh <- code: + default: + } + return + } + w.WriteHeader(http.StatusBadRequest) + _, _ = io.WriteString(w, "Authorization failed. You may close this window.") select { - case codeCh <- code: + case errCh <- errors.New("provideroauth: callback missing authorization code"): default: } - return - } - w.WriteHeader(http.StatusBadRequest) - _, _ = io.WriteString(w, "Authorization failed. You may close this window.") - select { - case errCh <- errors.New("provideroauth: callback missing authorization code"): - default: - } - })} + }), + } go func() { _ = server.Serve(listener) }() defer func() { shutdownCtx, cancelShutdown := context.WithTimeout(context.Background(), time.Second) diff --git a/internal/tools/bash_tool_test.go b/internal/tools/bash_tool_test.go index 297f9816a..8d03f22cb 100644 --- a/internal/tools/bash_tool_test.go +++ b/internal/tools/bash_tool_test.go @@ -69,6 +69,7 @@ func runBashToolHelper(command string) { } fmt.Println("listening", listener.Addr().String()) server := &http.Server{ + ReadHeaderTimeout: 5 * time.Second, Handler: http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { _, _ = response.Write([]byte("zero-server-ok")) }),