diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 80620ce..3106f12 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -16,3 +16,8 @@ **Vulnerability:** Writing fully buffered in-memory data to temporary disk files solely for parsing. **Learning:** This increases attack surface, risks disk exhaustion, and violates the principle of least privilege. **Prevention:** Refactor parsing functions to accept byte slices or `io.Reader` directly to process data in memory. + +## 2024-05-30 - Prevent DoS via Missing HTTP Request Timeouts +**Vulnerability:** The application used `http.Get()` for fetching external plugins, which relies on `http.DefaultClient`. This default client has no timeout configured, allowing malicious or unresponsive servers to hang the connection indefinitely, potentially leading to Denial of Service (DoS) through resource exhaustion (e.g., file descriptors, goroutines). +**Learning:** In Go, `http.DefaultClient` should never be used for external or untrusted requests because it lacks timeouts by default. +**Prevention:** Always use a custom `http.Client` with an explicit `Timeout` configured (e.g., `Timeout: 10 * time.Second`) when making HTTP requests to external or untrusted endpoints to ensure connections are eventually closed. diff --git a/internal/plugin/manager.go b/internal/plugin/manager.go index 7aad027..e39a83b 100644 --- a/internal/plugin/manager.go +++ b/internal/plugin/manager.go @@ -410,7 +410,8 @@ func (m *Manager) addScriptPlugin(owner, repo, pluginName string) error { fmt.Printf("Fetching script from: %s\n", rawURL) - resp, err := http.Get(rawURL) + client := &http.Client{Timeout: 10 * time.Second} + resp, err := client.Get(rawURL) if err != nil { return fmt.Errorf("failed to fetch plugin: %w", err) } @@ -468,7 +469,8 @@ func (m *Manager) addFromDirectURL(rawURL string) error { return fmt.Errorf("unsupported URL scheme: %s", parsedURL.Scheme) } - resp, err := http.Get(parsedURL.String()) + client := &http.Client{Timeout: 10 * time.Second} + resp, err := client.Get(parsedURL.String()) if err != nil { return fmt.Errorf("failed to fetch plugin: %w", err) }