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
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user