Harden core packages and add interactive CLI config builder (rud config/validate/test)

This commit is contained in:
tyuXX 2026-11-19 13:05:26 +00:00
parent d37503c863
commit 99e24be6c9
29 changed files with 6763 additions and 165 deletions

View file

@ -68,3 +68,54 @@ func TestSingleEndpointHTMLAndJSON(t *testing.T) {
t.Fatalf("expected JSON status 'down', got %q", snap.OverallState)
}
}
func TestServerSecurityAndRenderingFixes(t *testing.T) {
cfg := config.DefaultConfig()
cfg.Page.Theme.FontFamily = `"JetBrains Mono", monospace`
cfg.Page.Theme.BgColor = `#111111; } </style><script>alert(1)</script>`
cfg.Page.Elements = []config.PageElement{
{
Type: "status_banner",
Messages: map[string]string{
"down": "We're experiencing issues",
},
},
{
Type: "monitor_group",
Monitors: []string{"rud-http"},
Display: &config.MonitorDisplayConfig{
ShowMessage: config.BoolPtr(true),
},
},
}
st := store.New(&cfg) // rud-http is pending with empty LastMessage
srv := New(&cfg, st)
req := httptest.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()
srv.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected 200 OK, got %d", w.Code)
}
body := w.Body.String()
if strings.Contains(body, "ZgotmplZ") {
t.Fatalf("unexpected ZgotmplZ in rendered HTML CSS")
}
if !strings.Contains(body, `--font: "JetBrains Mono", monospace;`) {
t.Fatalf("expected quoted FontFamily to render intact, got:\n%s", body)
}
if strings.Contains(body, `<script>alert(1)</script>`) {
t.Fatalf("CSS value breakout was not stripped")
}
if !strings.Contains(body, `We&#39;re experiencing issues`) {
t.Fatalf("expected single quote in data-messages to be HTML-attribute escaped")
}
if !strings.Contains(body, `data-field="message"`) {
t.Fatalf("expected [data-field=\"message\"] placeholder even when monitor LastMessage is empty")
}
if strings.Contains(body, `bar.innerHTML`) {
t.Fatalf("expected safe DOM construction instead of bar.innerHTML")
}
}