feat(security): security hardening, proxy support, and GL045 HTTP include warning
Security fixes: - Path traversal guard in include: local: — paths with ../ that escape the repo root are rejected instead of reading arbitrary host files - HTTP timeout (30 s) on all fetcher requests to prevent indefinite hangs - Response size cap (10 MiB) via io.LimitReader to prevent memory exhaustion - Cache directory and file permissions tightened to 0700/0600 - LSP Content-Length cap (64 MiB) to guard against DoS from a malicious client New feature: - --proxy flag on check, graph, and lsp subcommands; also proxy: key in .glint.yml; overrides system HTTP_PROXY / HTTPS_PROXY env vars when set; cmdGraph and cmdLSP now also load .glint.yml for proxy/token/url fallbacks New lint rule: - GL045 (Warning): include: remote: using plain http:// instead of https:// Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -339,3 +340,46 @@ func TestFetchURL_NotOK(t *testing.T) {
|
||||
_, err := cfg.FetchURL(srv.URL)
|
||||
if err == nil { t.Fatal("expected error for non-200 status") }
|
||||
}
|
||||
|
||||
func TestFetchFile_ResponseTooLarge(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
// Write maxResponseBytes+1 bytes to exceed the cap.
|
||||
chunk := make([]byte, 4096)
|
||||
written := int64(0)
|
||||
for written <= maxResponseBytes {
|
||||
n, _ := w.Write(chunk)
|
||||
written += int64(n)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
cfg := GitLabConfig{BaseURL: srv.URL}
|
||||
_, err := cfg.FetchFile("group/project", "/ci.yml", "main")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for oversized response")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "exceeds maximum size") {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchURL_ResponseTooLarge(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
chunk := make([]byte, 4096)
|
||||
written := int64(0)
|
||||
for written <= maxResponseBytes {
|
||||
n, _ := w.Write(chunk)
|
||||
written += int64(n)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
cfg := GitLabConfig{}
|
||||
_, err := cfg.FetchURL(srv.URL)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for oversized response")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "exceeds maximum size") {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user