Fix critical and high audit findings

Fixed findings from the audit reports (SECURITY, QUALITY, PERFORMANCE):
- P-001 · Dashboard re-downloads the entire dataset every 5 seconds

Re-synced the vendored shared/ snapshot from shared commit 199a5ef.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Haiku 5.5 committed 2026-10-19 07:48:07 +00:00
1 parent 7dd0d34383
commit a84a36349b
31 files changed
+653 -6055

No files matched your search

+40 -6
View File
@@ -1,8 +1,12 @@
package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/http"
"strconv"
"strings"
"time"
)
@@ -71,10 +75,7 @@ func (s *Server) handleWebData(w http.ResponseWriter, r *http.Request) {
webLists = append(webLists, webList{List: list, EffectiveUpdatedAt: effective})
}
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
writeJSON(w, http.StatusOK, map[string]any{
payload := map[string]any{
"lists": webLists,
"fields": fields,
"items": items,
@@ -85,8 +86,41 @@ func (s *Server) handleWebData(w http.ResponseWriter, r *http.Request) {
"items": len(items),
"values": len(values),
},
"timestamp": time.Now().UnixMilli(),
})
}
// The ETag covers the data only; the timestamp is added after hashing because
// it changes on every request.
body, err := json.Marshal(payload)
if err != nil {
writeJSONError(w, http.StatusInternalServerError, "Failed to fetch data")
return
}
digest := sha256.Sum256(body)
etag := `W/"` + hex.EncodeToString(digest[:]) + `"`
// Browsers may keep this per-user response, but revalidate it on every poll,
// so an unchanged dashboard gets a 304 instead of the full body.
w.Header().Set("Cache-Control", "private, no-cache")
w.Header().Set("ETag", etag)
if etagMatches(r.Header.Get("If-None-Match"), etag) {
w.WriteHeader(http.StatusNotModified)
return
}
payload["timestamp"] = time.Now().UnixMilli()
writeJSON(w, http.StatusOK, payload)
}
// etagMatches reports whether an If-None-Match header matches etag under the
// weak comparison of RFC 9110, which ignores the W/ prefix.
func etagMatches(ifNoneMatch, etag string) bool {
if strings.TrimSpace(ifNoneMatch) == "*" {
return true
}
want := strings.TrimPrefix(etag, "W/")
for _, candidate := range strings.Split(ifNoneMatch, ",") {
if strings.TrimPrefix(strings.TrimSpace(candidate), "W/") == want {
return true
}
}
return false
}
func (s *Server) handleNotificationPoll(w http.ResponseWriter, r *http.Request) {