fix(core): correctness and robustness fixes across all subsystems

- Move status page template to package-level template.Must (panic on
  parse error at init instead of nil deref at runtime)
- Fix XSS in import error responses (log detail server-side, return
  generic message to client)
- Handle ListenAndServe errors in HTTP and SSH servers
- Use defer resp.Body.Close() in all alert providers, check
  json.Marshal errors
- Share HTTP clients across checks instead of creating per-request
- Use http.NewRequestWithContext for per-site timeout control
- Support HTTP method field (was always GET despite DB storing method)
- Implement AcceptedCodes validation (was hardcoded >= 400 despite DB
  storing accepted code ranges)
- Add defer tx.Rollback() to ImportData for transaction safety
This commit is contained in:
2026-05-15 00:00:02 -04:00
parent 77fa6324f2
commit 4d5116644f
7 changed files with 218 additions and 153 deletions
+16 -7
View File
@@ -61,12 +61,15 @@ type DiscordProvider struct{ URL string }
func (d *DiscordProvider) Send(title, message string) error {
payload := map[string]string{"content": fmt.Sprintf("**%s**\n%s", title, message)}
jsonValue, _ := json.Marshal(payload)
jsonValue, err := json.Marshal(payload)
if err != nil {
return err
}
resp, err := alertClient.Post(d.URL, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
return err
}
resp.Body.Close()
defer resp.Body.Close()
return nil
}
@@ -75,12 +78,15 @@ type SlackProvider struct{ URL string }
func (s *SlackProvider) Send(title, message string) error {
payload := map[string]string{"text": fmt.Sprintf("*%s*\n%s", title, message)}
jsonValue, _ := json.Marshal(payload)
jsonValue, err := json.Marshal(payload)
if err != nil {
return err
}
resp, err := alertClient.Post(s.URL, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
return err
}
resp.Body.Close()
defer resp.Body.Close()
return nil
}
@@ -93,12 +99,15 @@ func (w *WebhookProvider) Send(title, message string) error {
"message": message,
"status": "alert",
}
jsonValue, _ := json.Marshal(payload)
jsonValue, err := json.Marshal(payload)
if err != nil {
return err
}
resp, err := alertClient.Post(w.URL, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
return err
}
resp.Body.Close()
defer resp.Body.Close()
return nil
}
@@ -139,6 +148,6 @@ func (n *NtfyProvider) Send(title, message string) error {
if err != nil {
return err
}
resp.Body.Close()
defer resp.Body.Close()
return nil
}