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:
1 parent
9ef8cee1c4
commit
c9d67309e2
5 files changed
+165
-2
No files matched your search
@@ -0,0 +1,22 @@
|
||||
# The operator's in-place notice had no limit (security review of 42ef25c2). The test, on the code BEFORE the fix:
|
||||
--- FAIL: TestNotice_NoAddress_ABoxCannotFloodTheOperator (0.22s)
|
||||
end_notice_test.go:527: 51 presses of ONE app in a day mailed the operator 51 times, want 1 (the same app is told again at most once in 168h0m0s)
|
||||
FAIL
|
||||
FAIL gitea.dooplex.hu/admin/felhom-hub/internal/api 0.246s
|
||||
FAIL
|
||||
|
||||
# After the fix, by mutation:
|
||||
== MUTATION: the same app is told to the operator at every press
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestNotice_NoAddress_ABoxCannotFloodTheOperator (0.21s)
|
||||
end_notice_test.go:527: 51 presses of ONE app in a day mailed the operator 5 times, want 1 (the same app is told again at most once in 168h0m0s)
|
||||
== MUTATION: no daily limit on the operator's in-place notices
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestNotice_NoAddress_ABoxCannotFloodTheOperator (0.32s)
|
||||
end_notice_test.go:543: 101 presses in a day mailed the operator 51 times, want the household's daily limit 5
|
||||
== MUTATION: no daily limit on the stuck lines
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestNotice_NoAddress_ABoxCannotFloodTheOperator (0.40s)
|
||||
end_notice_test.go:575: 46 waiting notices filed 41 stuck line(s) at once, want 1..5
|
||||
|
||||
3 mutations, 0 not a red-proof
|
||||
@@ -1,5 +1,15 @@
|
||||
## Unreleased (after v0.182.0)
|
||||
|
||||
- **The operator's in-place notice is bounded (2026-11-15 evening; the security review of the notice lock's
|
||||
commit).** A box of a household with no address (or a blocked one) could name presses without end — a new app
|
||||
name each time, or one app pressed, taken back and pressed again — and each one mailed the operator
|
||||
(`offsite_end_notice_operator` has no cooldown by design). Now, both read from the hub's own sent log
|
||||
(`store.CountOperatorSentSince`, `OperatorSentAboutSince`): at most **5** of these mails about one household in 24
|
||||
hours, and the **same app** again no sooner than **7 days**. A notice that waits is NOT told — its row keeps the
|
||||
reason, it starts no 30 days, nothing is agreed for it — and it goes when the limit allows (delayed, never
|
||||
dropped). The „stuck” line (`offsite_end_notice_stuck`) is bounded the same way: at most 5 per household in 24
|
||||
hours. Test `TestNotice_NoAddress_ABoxCannotFloodTheOperator` (51 presses of one app + 50 names in a day: 5 mails;
|
||||
seen red before the fix: 51 mails); 3 mutations seen red.
|
||||
- **The notice's texts (2026-11-15 evening, `09` §3 decision 316, R-1374; `07` §8.2f — household-facing, NOT
|
||||
published: the operator reads them before a release).** (1) The mail ends with what to do if the household did
|
||||
not ask for the deletion — „Ha ezt nem te kérted, vond vissza a Mentések oldalon, és változtasd meg a
|
||||
|
||||
@@ -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) }
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -298,3 +298,22 @@ func (s *Store) BackdateNotificationLogForTest(customerID string, by time.Durati
|
||||
fmt.Sprintf("-%d seconds", int(by.Seconds())), customerID)
|
||||
return err
|
||||
}
|
||||
|
||||
// CountOperatorSentSince counts the operator mails of one type that the hub's own log says were SENT about a
|
||||
// household since `since` (the daily limit of the operator's in-place notice).
|
||||
func (s *Store) CountOperatorSentSince(customerID, eventType string, since time.Time) (int, error) {
|
||||
var n int
|
||||
err := s.db.QueryRow(`SELECT COUNT(*) FROM notification_log WHERE customer_id = ? AND event_type = ? AND channel = 'operator' AND status = 'sent' AND created_at >= ?`,
|
||||
customerID, eventType, since.UTC().Format("2006-01-02 15:04:05")).Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// OperatorSentAboutSince reports whether the hub's own log holds a SENT operator mail of one type about a household
|
||||
// whose text contains `marker`, since `since`. marker is the hub's own words around a checked app name; it is
|
||||
// matched as plain text (instr), never as a pattern.
|
||||
func (s *Store) OperatorSentAboutSince(customerID, eventType, marker string, since time.Time) (bool, error) {
|
||||
var n int
|
||||
err := s.db.QueryRow(`SELECT COUNT(*) FROM notification_log WHERE customer_id = ? AND event_type = ? AND channel = 'operator' AND status = 'sent' AND created_at >= ? AND instr(message, ?) > 0`,
|
||||
customerID, eventType, since.UTC().Format("2006-01-02 15:04:05"), marker).Scan(&n)
|
||||
return n > 0, err
|
||||
}
|
||||
Reference in new issue
Block a user