From 73a534e7536f252efab0dd7e42a6a750edc425c6 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Sun, 15 Nov 2026 17:03:19 +0100 Subject: [PATCH] =?UTF-8?q?hub=20(unreleased):=20review=20fix=203=20?= =?UTF-8?q?=E2=80=94=20a=20name=20that=20reaches=20a=20household's=20mail?= =?UTF-8?q?=20is=20a=20plain=20app=20slug;=20a=20link-shaped=20name=20gets?= =?UTF-8?q?=20no=20notice=20and=20is=20never=20agreed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS --- .../A/redproof-review-3.txt | 20 +++++++ hub/CHANGELOG.md | 8 +++ hub/internal/api/end_notice_review_test.go | 60 +++++++++++++++++++ hub/internal/notify/end_notice.go | 4 +- hub/internal/offsitekeys/ended.go | 2 + hub/internal/offsitekeys/notice_lock_test.go | 17 ++++++ hub/internal/store/offsite_end_notice.go | 23 ++++++- 7 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 documentation/audits/build-release-4b-2026-11-15/A/redproof-review-3.txt create mode 100644 hub/internal/api/end_notice_review_test.go diff --git a/documentation/audits/build-release-4b-2026-11-15/A/redproof-review-3.txt b/documentation/audits/build-release-4b-2026-11-15/A/redproof-review-3.txt new file mode 100644 index 00000000..f227e9ab --- /dev/null +++ b/documentation/audits/build-release-4b-2026-11-15/A/redproof-review-3.txt @@ -0,0 +1,20 @@ +# Review finding 3 — a link-shaped name in the household's subject. The test on the code BEFORE the fix (ValidNoticeApp = the app record's rule): +--- FAIL: TestReview3_ALinkShapedNameNeverReachesTheHousehold (0.05s) + end_notice_review_test.go:24: "www.evil-bank.example.com" reached the household: subject "[Felhom] www.evil-bank.example.com: a távoli másolatok törlésének napja: 2026. 12. 15." +FAIL +FAIL gitea.dooplex.hu/admin/felhom-hub/internal/api 0.075s +FAIL + +# After the fix, by mutation: +== MUTATION: a name the household cannot be told about is agreed when a row says told + RED on the mutant, GREEN on the real file + --- FAIL: TestReview3_ANameThatCannotBeToldIsNeverAgreed (0.00s) + notice_lock_test.go:163: "www.evil-bank.example.com": agreed [a1b2c685], refused [] + +1 mutations, 0 not a red-proof +== MUTATION: a dot is allowed in a notice name again + RED on the mutant, GREEN on the real file + --- FAIL: TestReview3_ALinkShapedNameNeverReachesTheHousehold (0.05s) + end_notice_review_test.go:24: "www.evil-bank.example.com" reached the household: subject "[Felhom] www.evil-bank.example.com: a távoli másolatok törlésének napja: 2026. 12. 15." + +1 mutations, 0 not a red-proof diff --git a/hub/CHANGELOG.md b/hub/CHANGELOG.md index 87e5d5df..f8131c21 100644 --- a/hub/CHANGELOG.md +++ b/hub/CHANGELOG.md @@ -1,5 +1,13 @@ ## Unreleased (after v0.182.0) +- **Review of the notice lock, finding 3 (2026-11-15 night): a link-shaped name cannot reach a household's mail.** + The app record's name rule allows dots and capitals, and a notice row was made for a name the hub never saw + installed — so a box could put `www.evil-bank.example.com` into the subject of a mail the hub sends to its + household, five a day. A name that reaches a household's mail must now be a plain app slug + (`store.ValidNoticeApp`: lower-case letters, digits, `-`, `_`; no dot; at most 64): anything else gets no notice + row, no mail, and is never agreed („the name is not a plain app name …” in the window's answer). All 66 catalog + app names pass (`TestReview3_EveryCatalogAppNameIsANoticeName` reads the catalog when it is beside this + repository). Tests `TestReview3_*` (3); seen red before the fix, 2 mutations red after. - **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 diff --git a/hub/internal/api/end_notice_review_test.go b/hub/internal/api/end_notice_review_test.go new file mode 100644 index 00000000..2b43614e --- /dev/null +++ b/hub/internal/api/end_notice_review_test.go @@ -0,0 +1,60 @@ +package api + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "gitea.dooplex.hu/admin/felhom-hub/internal/store" +) + +// THE INDEPENDENT REVIEW OF THE NOTICE LOCK (2026-11-15 night). One test per finding, each seen red before its fix: +// documentation/audits/build-release-4b-2026-11-15/A/redproof-review-.txt. + +// Finding 3. A box could put a link-shaped word into the household's subject — `www.evil-bank.example.com`, five a +// day: the app-record's name rule allows dots and capitals, and a notice row was made for a name the hub never saw +// installed. A name that reaches a household's mail must be a plain app slug (store.ValidNoticeApp): lower-case +// letters, digits, `-`, `_`; no dot. Anything else: no row, no mail, never agreed. +func TestReview3_ALinkShapedNameNeverReachesTheHousehold(t *testing.T) { + r := newNoticeRig(t, household) + for _, name := range []string{"www.evil-bank.example.com", "evil.example", "Felhom-Support", "a.b", "x..y"} { + r.report(pressed(name, "2026-11-15T10:00:00Z")) + if got := r.to(household); len(got) != 0 { + t.Fatalf("%q reached the household: subject %q", name, got[0].subject) + } + if _, ok := r.notice(name); ok { + t.Fatalf("%q has a notice row", name) + } + } + // positive control: a plain slug is told + r.report(pressed("paperless-ngx", "2026-11-15T10:00:00Z")) + if got := r.to(household); len(got) != 1 || !strings.Contains(got[0].subject, "paperless-ngx: ") { + t.Fatalf("a plain app name must be told: %+v", got) + } +} + +// The slug rule fits every app the catalog has (read from the sibling repository when it is there). +func TestReview3_EveryCatalogAppNameIsANoticeName(t *testing.T) { + dir := filepath.Join("..", "..", "..", "..", "app-catalog-felhom.eu", "templates") + entries, err := os.ReadDir(dir) + if err != nil { + t.Skipf("the catalog repository is not beside this one (%v)", err) + } + n := 0 + for _, e := range entries { + if !e.IsDir() { + continue + } + if _, err := os.Stat(filepath.Join(dir, e.Name(), ".felhom.yml")); err != nil { + continue + } + n++ + if !store.ValidNoticeApp(e.Name()) { + t.Errorf("the catalog app %q is not a notice name — its household could never be told, and its copies never deleted", e.Name()) + } + } + if n < 50 { + t.Fatalf("only %d catalog apps read — the test stopped reading the catalog", n) + } +} diff --git a/hub/internal/notify/end_notice.go b/hub/internal/notify/end_notice.go index 4136f9a1..091faac3 100644 --- a/hub/internal/notify/end_notice.go +++ b/hub/internal/notify/end_notice.go @@ -84,9 +84,9 @@ func (d *Dispatcher) MailHeld() bool { return d.mailHold.Held() } // SendEndNotice tries ONCE to mail the household that the off-site copies of `app` are deleted from the day `ends` // (the hub's own day: the caller passes its clock + 30 days). It returns what the try came to and, when nobody was // told, the hub's own words for why. It keeps no state: the caller's record decides whether there is a next try. -// app must have passed store.ValidPresenceApp; a name that has not is refused here again. +// app must have passed store.ValidNoticeApp (a plain app slug); a name that has not is refused here again. func (d *Dispatcher) SendEndNotice(customerID, app string, ends time.Time) (EndNoticeOutcome, string) { - if !store.ValidPresenceApp(app) || store.ReservedPresenceApp(app) { + if !store.ValidNoticeApp(app) { return EndNoticeFailed, "not an app name" } if d.resendAPIKey == "" { diff --git a/hub/internal/offsitekeys/ended.go b/hub/internal/offsitekeys/ended.go index e3527c8f..f3138e40 100644 --- a/hub/internal/offsitekeys/ended.go +++ b/hub/internal/offsitekeys/ended.go @@ -201,6 +201,8 @@ func agreeEnded(now time.Time, presence map[string]store.AppPresence, notices ma func untoldReason(now time.Time, notices map[string]store.EndNotice, app string) string { n, ok := notices[app] switch { + case !store.ValidNoticeApp(app): + return "the name is not a plain app name (lower-case letters, digits, - and _): the household cannot be told about it, so nothing is removed" case !ok: return reasonNoNotice case !n.Told(): diff --git a/hub/internal/offsitekeys/notice_lock_test.go b/hub/internal/offsitekeys/notice_lock_test.go index b7ccd4d3..e990f6e5 100644 --- a/hub/internal/offsitekeys/notice_lock_test.go +++ b/hub/internal/offsitekeys/notice_lock_test.go @@ -147,3 +147,20 @@ func endedFixtureNoNotice(t *testing.T) (*Service, *[]evt) { } return s, events } + +// Review finding 3: a name that cannot be put into a household's mail (a dot, a capital) is never agreed — even +// with a row that says „told”, which the hub itself can no longer write for it. +func TestReview3_ANameThatCannotBeToldIsNeverAgreed(t *testing.T) { + now := time.Date(2026, 12, 20, 3, 0, 0, 0, time.UTC) + old := now.Add(-60 * 24 * time.Hour) + listing := store.OffsiteSnapshotListing{ListedAt: now, Entries: map[string]time.Time{eid(1): old}} + for _, app := range []string{"www.evil-bank.example.com", "Vikunja"} { + ids, _, refused := agreeEnded(now, + map[string]store.AppPresence{app: {AbsentSince: now.Add(-40 * 24 * time.Hour)}}, + map[string]store.EndNotice{app: {App: app, ToldAt: now.Add(-40 * 24 * time.Hour), ToldTo: store.EndNoticeHousehold}}, + listing, true, []EndedClaim{{App: app, SnapshotIDs: []string{eid(1)}}}) + if len(ids) != 0 || !hasReason(refused, "not a plain app name") { + t.Fatalf("%q: agreed %v, refused %+v", app, shortIDs(ids), refused) + } + } +} diff --git a/hub/internal/store/offsite_end_notice.go b/hub/internal/store/offsite_end_notice.go index 0e563d88..6f1e3b92 100644 --- a/hub/internal/store/offsite_end_notice.go +++ b/hub/internal/store/offsite_end_notice.go @@ -126,7 +126,7 @@ func (s *Store) NoteEndNotices(customerID string, deployed []string, claims []En claimed := map[string]string{} // app → press (the first claim of a name wins) var order []string for _, c := range claims { - if !ValidPresenceApp(c.App) || ReservedPresenceApp(c.App) || in[c.App] { + if !ValidNoticeApp(c.App) || in[c.App] { continue } if _, dup := claimed[c.App]; dup { @@ -317,3 +317,24 @@ func (s *Store) OperatorSentAboutSince(customerID, eventType, marker string, sin customerID, eventType, since.UTC().Format("2006-01-02 15:04:05"), marker).Scan(&n) return n > 0, err } + +// ValidNoticeApp: the shape of a name that may reach a household's mail — a plain app slug: 1..64 of lower-case +// letters, digits, `-` and `_`, starting with a letter or a digit. NO DOT and no capital: the app record's rule +// (ValidPresenceApp) allows both, and a box could then put `www.some-bank.example.com` into the subject of a mail the +// hub sends to its household (review of 2026-11-15). Every catalog app name passes it +// (api.TestReview3_EveryCatalogAppNameIsANoticeName). A name that fails gets no notice row: nobody is told about it +// and the hub never agrees to it. +func ValidNoticeApp(app string) bool { + if app == "" || len(app) > maxPresenceName || ReservedPresenceApp(app) { + return false + } + for i, r := range app { + switch { + case r >= 'a' && r <= 'z', r >= '0' && r <= '9': + case i > 0 && (r == '_' || r == '-'): + default: + return false + } + } + return true +}