fix(fed): sanitize peer rows, cap peer bytes, add --peer-blocklist
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 24s
CI / Tests (Linux, race detector) (push) Successful in 34s
CI / Dependency audit (push) Successful in 14s
Release / Plan (reuse the published image?) (push) Successful in 3s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 4s

Peer events and summary rows are rebuilt from validated fields (address,
country code, category) and the forged/unban flags from peers are
ignored. The live relay drops a peer that exceeds about 1 MB/s, also
within a single window. --peer-blocklist=off keeps the hub's blocklist
to local observations. UI polish: plural forms, blocklist preview and
downloads follow the active slice, compact IP cards on phones. Docs for
the 1.1.0 interface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 18:10:54 -03:00
1 parent f4b295f582
commit 783b0cba3e
31 files changed
+355 -127

No files matched your search

+9 -2
View File
@@ -149,7 +149,7 @@ func (e *PeerExport) Sanitize(rangeName string) error {
x.Domains, x.Samples = clipList(x.Domains, maxDomain, 120), clipList(x.Samples, maxSample, 300)
x.UAs, x.UALabels = clipList(x.UAs, maxUAs, 200), clipList(x.UALabels, maxUAs, 120)
x.Jails = clipList(x.Jails, maxJails, 40)
x.RDNS, x.CC, x.Country, x.City, x.ASOrg = clipS(x.RDNS, 200), clipS(x.CC, 2), clipS(x.Country, 80), clipS(x.City, 80), clipS(x.ASOrg, 120)
x.RDNS, x.CC, x.Country, x.City, x.ASOrg = clipS(x.RDNS, 200), validCC2(clipS(x.CC, 2)), clipS(x.Country, 80), clipS(x.City, 80), clipS(x.ASOrg, 120)
ips = append(ips, x)
}
s.IPs = ips
@@ -170,8 +170,15 @@ func (e *PeerExport) Sanitize(rangeName string) error {
r := &s.Recent[i]
r.IP, r.Cat, r.Source = clipS(r.IP, 45), clipS(r.Cat, 20), clipS(r.Source, 20)
r.Domain, r.Method, r.Path = clipS(r.Domain, 100), clipS(r.Method, 12), clipS(r.Path, 240)
r.User, r.Jail, r.CC = clipS(r.User, 64), clipS(r.Jail, 40), clipS(r.CC, 2)
r.User, r.Jail = clipS(r.User, 64), clipS(r.Jail, 40)
}
kept := s.Recent[:0]
for _, r := range s.Recent {
if SanitizeFeed(&r) {
kept = append(kept, r)
}
}
s.Recent = kept
if len(s.Sources) > 16 {
s.Sources = s.Sources[:16]
}
+13 -1
View File
@@ -136,7 +136,7 @@ func (e *LiveEvent) Sanitize(now int64) bool {
if e.Status < 0 || e.Status > 999 {
e.Status = 0
}
e.Unban = false
e.Unban, e.Forged = false, false
e.CC = validCC2(clipS(e.CC, 2))
if e.Src != nil {
if !validLatLon(e.Src.Lat, e.Src.Lon) {
@@ -158,3 +158,15 @@ func validCC2(cc string) string {
// String is for debugging.
func (l Location) String() string { return fmt.Sprintf("%.4f,%.4f %s", l.Lat, l.Lon, l.Label) }
// SanitizeFeed validates a feed row that came from a peer's summary; false drops it.
func SanitizeFeed(r *FeedEvent) bool {
a, err := netip.ParseAddr(r.IP)
if err != nil || a.Zone() != "" {
return false
}
r.IP = a.Unmap().String()
r.CC = validCC2(clipS(r.CC, 2))
r.Unban, r.Forged = false, false
return true
}
+21
View File
@@ -35,3 +35,24 @@ func TestPeerLocationAndLiveSanitize(t *testing.T) {
t.Fatalf("%+v", le)
}
}
func TestPeerRowsAreSanitized(t *testing.T) {
le := LiveEvent{FeedEvent: FeedEvent{IP: "1.2.3.4", Cat: "scanner", T: 1, Forged: true, Unban: true, CC: "<s"}}
if !le.Sanitize(1_800_000_000) || le.Forged || le.Unban || le.CC != "" {
t.Fatalf("%+v", le)
}
e := PeerExport{V: ExportVersion, Summary: Summary{
Recent: []FeedEvent{{IP: "<script>", Cat: "scanner"}, {IP: "5.6.7.8", Cat: "scanner", CC: "<s", Forged: true}},
IPs: []IPSummary{{IP: "9.9.9.9", CC: "<s", Score: 1}},
}}
if err := e.Sanitize("24h"); err != nil {
t.Fatal(err)
}
r := e.Summary.Recent
if len(r) != 1 || r[0].IP != "5.6.7.8" || r[0].CC != "" || r[0].Forged {
t.Fatalf("%+v", r)
}
if e.Summary.IPs[0].CC != "" {
t.Fatal("cc must be validated")
}
}