From b57fdd20852b6be8758eedd652d8ce34d05b91a5 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 4 Feb 2026 12:00:54 +0000 Subject: [PATCH] Add path traversal regression tests --- internal/api/security_regression_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.go index c2d814b86..fdd72de34 100644 --- a/internal/api/security_regression_test.go +++ b/internal/api/security_regression_test.go @@ -2699,6 +2699,30 @@ func TestAuditVerifyRequiresAuthInAPIMode(t *testing.T) { } } +func TestPathTraversalBlockedForAPIPaths(t *testing.T) { + cfg := newTestConfigWithTokens(t) + router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0") + + req := httptest.NewRequest(http.MethodGet, "/api/../api/security/status", nil) + rec := httptest.NewRecorder() + router.Handler().ServeHTTP(rec, req) + if rec.Code != http.StatusUnauthorized { + t.Fatalf("expected 401 for path traversal on api, got %d", rec.Code) + } +} + +func TestPathTraversalBlockedForNonAPIPaths(t *testing.T) { + cfg := newTestConfigWithTokens(t) + router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0") + + req := httptest.NewRequest(http.MethodGet, "/../etc/passwd", nil) + rec := httptest.NewRecorder() + router.Handler().ServeHTTP(rec, req) + if rec.Code != http.StatusBadRequest { + t.Fatalf("expected 400 for path traversal on non-api, got %d", rec.Code) + } +} + func TestOIDCLoginBypassesAuth(t *testing.T) { cfg := newTestConfigWithTokens(t) cfg.AuthUser = "admin"