hub (unreleased): the operator's in-place notice is bounded — 5 per household a day, the same app once in 7 days (the security review of the notice lock)

A box of a household with no address could mail the operator at every new press.
A notice that waits is not told: it starts no 30 days and nothing is agreed for it.
The stuck line is bounded the same way.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 16:28:49 +01:00
1 parent 9ef8cee1c4
commit c9d67309e2
5 files changed
+165 -2

No files matched your search

+35 -2
View File
@@ -143,12 +143,26 @@ func (h *Handler) endNoticeToOperator(customerID string, n store.EndNotice, why
if h.dispatcher == nil {
return fmt.Errorf("the hub has no mail service configured")
}
// The limits (security review of 2026-11-15), both from the hub's own sent log, by the real clock the log is
// written with. A notice that waits returns an error: the caller records the reason and nobody counts as told.
wall := time.Now()
if again, err := h.store.OperatorSentAboutSince(customerID, offsitekeys.EventEndNoticeOperator, operatorNoticeMarker(n.App), wall.Add(-operatorNoticeSameAppGap)); err != nil {
return fmt.Errorf("the hub's sent log could not be read")
} else if again {
return fmt.Errorf("the operator was told about this app of this household less than %d days ago — the notice for this press goes later", int(operatorNoticeSameAppGap.Hours()/24))
}
if sent, err := h.store.CountOperatorSentSince(customerID, offsitekeys.EventEndNoticeOperator, wall.Add(-24*time.Hour)); err != nil {
return fmt.Errorf("the hub's sent log could not be read")
} else if sent >= operatorNoticesPerDay {
return fmt.Errorf("the operator already got %d of these notices about this household in the last 24 hours (the daily limit) — this one goes later", operatorNoticesPerDay)
}
day := now.Add(offsitekeys.EndedAppAfter).UTC().Format("2006-01-02")
msg := fmt.Sprintf("Off-site: the household %s removed the app %q with „delete backup data”, and the hub could not tell the household: %s. "+
// The text must hold operatorNoticeMarker(app): the same-app limit finds an earlier mail by it.
msg := fmt.Sprintf("Off-site: the household %s "+operatorNoticeMarker(n.App)+" „delete backup data”, and the hub could not tell the household: %s. "+
"This mail is the notice in its place. The hub counts the 30 days from now: from %s a clean-up window may remove that app's off-site copies. "+
"Tell the household. If the household did not ask for this, it can take it back on its Backups page (“Keep it after all”) and must change its password. "+
"When the household gets a notification address, the hub mails the household itself and the 30 days start again from that mail.",
customerID, n.App, why, day)
customerID, why, day)
details, _ := json.Marshal(map[string]any{"subject": n.App, "app": n.App, "agrees_from": day})
if err := h.dispatcher.SendOperatorNow(customerID, offsitekeys.EventEndNoticeOperator, "warning", msg, string(details)); err != nil {
return err
@@ -173,6 +187,11 @@ func (h *Handler) endNoticeStuck(customerID string, n store.EndNotice, now time.
if h.dispatcher != nil && h.dispatcher.MailHeld() {
return
}
// At most operatorNoticesPerDay of these lines per household in 24 hours (the hub's own event rows): a box that
// keeps fifty invented presses waiting must not turn the line into fifty mails. The rest are filed later.
if filed, err := h.store.GetEventsByType(customerID, offsitekeys.EventEndNoticeStuck, time.Now().Add(-24*time.Hour)); err != nil || len(filed) >= operatorNoticesPerDay {
return
}
why := n.LastReason
if why == "" {
why = "no try has been recorded"
@@ -194,3 +213,17 @@ func (h *Handler) endNoticeStuck(customerID string, n store.EndNotice, now time.
h.dispatcher.ProcessEvent(customerID, offsitekeys.EventEndNoticeStuck, "warning", msg, string(details), "hub")
}
}
// The operator's in-place notice is bounded like the household's (security review of 2026-11-15): a box of a
// household with no address must not be able to mail the operator without end. Both are read from the hub's own sent
// log, and a notice that waits is NOT told — it starts no 30 days.
const (
// operatorNoticesPerDay: the most in-place notices the operator is mailed about ONE household in 24 hours.
operatorNoticesPerDay = 5
// operatorNoticeSameAppGap: the SAME app of a household is told to the operator again no sooner than this — a
// press, a take-back and a press again are one matter for the operator, not a mail each.
operatorNoticeSameAppGap = 7 * 24 * time.Hour
)
// operatorNoticeMarker is the part of the in-place notice's text that names the app (a checked app name, quoted).
func operatorNoticeMarker(app string) string { return fmt.Sprintf("removed the app %q with", app) }
+79
View File
@@ -507,3 +507,82 @@ func TestNotice_TheReportStartsTheWalkOffTheRequest(t *testing.T) {
}
t.Fatalf("no notice within 3 s of the report: %+v", r.all())
}
// SECURITY REVIEW of 42ef25c2 (2026-11-15): the operator's in-place notice had no limit. A box of a household with no
// address could name new presses without end — a new app name each time, or one app with a new press each time — and
// every one mailed the operator. Now: at most operatorNoticesPerDay of these mails per household in 24 hours, and the
// SAME app at most once in operatorNoticeSameAppGap — both counted in the hub's own sent log. A notice that waits is
// NOT told: no 30 days start for it, so nothing is agreed for it.
// RED-PROOF: documentation/audits/build-release-4b-2026-11-15/A/redproof-notice-operator-cap.txt.
func TestNotice_NoAddress_ABoxCannotFloodTheOperator(t *testing.T) {
r := newNoticeRig(t, "")
opMails := func() int { return len(r.opNotice(offsitekeys.EventEndNoticeOperator)) }
// 50 presses for ONE name: press, take-back, press — fifty times in a day
for i := 0; i < 50; i++ {
r.report(pressed("vikunja", fmt.Sprintf("2026-11-15T10:%02d:00Z", i)))
r.report(repKept)
}
r.report(pressed("vikunja", "2026-11-15T11:00:00Z"))
if n := opMails(); n != 1 {
t.Fatalf("51 presses of ONE app in a day mailed the operator %d times, want 1 (the same app is told again at most once in %s)", n, operatorNoticeSameAppGap)
}
if n, ok := r.notice("vikunja"); !ok || n.Told() || !strings.Contains(n.LastReason, "less than") {
t.Fatalf("the newest press of vikunja was not mailed, so it must NOT be told: %+v", n)
}
// 50 presses for 50 names
var recs []string
for i := 0; i < 50; i++ {
recs = append(recs, fmt.Sprintf(`{"app":"inv-%02d","removed_at":"2026-11-15T10:00:00Z"}`, i))
}
many := `{"customer_id":"c1","stacks":{"deployed":["immich"]},"offsite":{"enabled":true,"ended_apps":[` + strings.Join(recs, ",") + `]}}`
for i := 0; i < 3; i++ {
r.report(many)
r.h.endNotices("c1", time.Now().Add(time.Duration(i+2)*time.Hour)) // and the later tries of the same day
}
if n := opMails(); n != operatorNoticesPerDay {
t.Fatalf("101 presses in a day mailed the operator %d times, want the household's daily limit %d", n, operatorNoticesPerDay)
}
told, waiting := 0, 0
ns, _ := r.st.EndNotices("c1")
for app, n := range ns {
if n.Told() {
told++
if n.ToldTo != store.EndNoticeOperator {
t.Fatalf("%s: told to %q", app, n.ToldTo)
}
} else {
waiting++
if n.LastReason == "" {
t.Fatalf("%s waits with no reason on its row", app)
}
}
}
// vikunja's first press was told and then voided by the take-back; four of the fifty names were told today
if told != operatorNoticesPerDay-1 || waiting != len(ns)-told || waiting < 40 {
t.Fatalf("told=%d waiting=%d of %d rows — only a press whose mail WENT may count as told", told, waiting, len(ns))
}
// the limit DELAYS, it never drops: a day later five more are told
if err := r.st.BackdateNotificationLogForTest("c1", 25*time.Hour); err != nil {
t.Fatal(err)
}
r.h.endNotices("c1", time.Now().Add(26*time.Hour))
if n := opMails(); n != 2*operatorNoticesPerDay {
t.Fatalf("a day later: %d operator mails in all, want %d", n, 2*operatorNoticesPerDay)
}
// the forty that still wait must not become forty „stuck” lines either: at most the daily limit of those
r.h.endNotices("c1", time.Now().Add(EndNoticeStuckAfter+30*time.Hour))
if e := r.events(offsitekeys.EventEndNoticeStuck); len(e) == 0 || len(e) > operatorNoticesPerDay {
t.Fatalf("%d waiting notices filed %d stuck line(s) at once, want 1..%d", waiting, len(e), operatorNoticesPerDay)
}
// … and the same app again only after operatorNoticeSameAppGap
r2 := newNoticeRig(t, "")
r2.report(pressed("vikunja", "2026-11-15T10:00:00Z"))
r2.report(repKept)
if err := r2.st.BackdateNotificationLogForTest("c1", operatorNoticeSameAppGap+time.Hour); err != nil {
t.Fatal(err)
}
r2.report(pressed("vikunja", "2026-11-25T10:00:00Z"))
if n, _ := r2.notice("vikunja"); len(r2.opNotice(offsitekeys.EventEndNoticeOperator)) != 2 || !n.Told() {
t.Fatalf("after the gap the same app must be told again: mails=%d %+v", len(r2.opNotice(offsitekeys.EventEndNoticeOperator)), n)
}
}