From 9f1877116b988b0fe7357861c0bc1a76b0912fd2 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 4 Feb 2026 11:58:02 +0000 Subject: [PATCH] Verify security status bootstrap token exposure --- internal/api/security_regression_test.go | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.go index 8ee78a3cea..f6348e7375 100644 --- a/internal/api/security_regression_test.go +++ b/internal/api/security_regression_test.go @@ -2626,6 +2626,53 @@ func TestValidateBootstrapTokenBypassesAuth(t *testing.T) { } } +func TestSecurityStatusHidesBootstrapTokenWhenAuthConfigured(t *testing.T) { + cfg := newTestConfigWithTokens(t) + cfg.AuthUser = "admin" + cfg.AuthPass = "hashed" + router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0") + + ResetRateLimitForIP("203.0.113.49") + req := httptest.NewRequest(http.MethodGet, "/api/security/status", nil) + req.RemoteAddr = "203.0.113.49:1234" + rec := httptest.NewRecorder() + router.Handler().ServeHTTP(rec, req) + if rec.Code != http.StatusOK { + t.Fatalf("expected 200 for security status, got %d", rec.Code) + } + + var payload map[string]interface{} + if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { + t.Fatalf("decode response: %v", err) + } + if _, ok := payload["bootstrapTokenPath"]; ok { + t.Fatalf("expected bootstrapTokenPath to be omitted when auth is configured") + } +} + +func TestSecurityStatusIncludesBootstrapTokenWhenUnauthenticated(t *testing.T) { + cfg := newTestConfigWithTokens(t) + router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0") + + ResetRateLimitForIP("203.0.113.50") + req := httptest.NewRequest(http.MethodGet, "/api/security/status", nil) + req.RemoteAddr = "203.0.113.50:1234" + rec := httptest.NewRecorder() + router.Handler().ServeHTTP(rec, req) + if rec.Code != http.StatusOK { + t.Fatalf("expected 200 for security status, got %d", rec.Code) + } + + var payload map[string]interface{} + if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { + t.Fatalf("decode response: %v", err) + } + path, ok := payload["bootstrapTokenPath"].(string) + if !ok || path == "" { + t.Fatalf("expected bootstrapTokenPath to be present for unauthenticated setup") + } +} + func TestOIDCLoginBypassesAuth(t *testing.T) { cfg := newTestConfigWithTokens(t) cfg.AuthUser = "admin"