diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 80620ce..0504702 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -16,3 +16,7 @@ **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-08-04 - Fix DoS risk by adding timeouts to HTTP requests +**Vulnerability:** External HTTP requests were made using `http.Get()`, which relies on `http.DefaultClient` and lacks request timeouts, leading to potential DoS or resource exhaustion. +**Learning:** `http.Get()` has no timeout. A malicious or unoptimized external server could hang connections infinitely, causing goroutine or connection leaks. +**Prevention:** Always replace `http.Get()` with a custom `http.Client` that is configured with appropriate timeouts (e.g., `Timeout: 10 * time.Second`). 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) }