From 6d2d4bd09d07ec4b4d5501b7fc576ac026749ff5 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Sun, 15 Nov 2026 14:52:02 +0100 Subject: [PATCH] hub: the large request's wait is keyed on the whole app set, not its shortened display list (security review) The key was the display string cut after ten names, so two different app sets with the same first ten names shared one wait and one operator mail. largeSetKey is a SHA-256 of the full sorted set; the display string is only shown. Test seen red; 2 mutations seen red (redproof-review-s2.txt). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS --- .../A/redproof-review-s2.txt | 21 +++++++++ hub/CHANGELOG.md | 5 +++ hub/internal/offsitekeys/ended.go | 18 ++++++-- .../offsitekeys/ended_large_marker_test.go | 43 +++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 documentation/audits/build-release-4-2026-11-15/A/redproof-review-s2.txt diff --git a/documentation/audits/build-release-4-2026-11-15/A/redproof-review-s2.txt b/documentation/audits/build-release-4-2026-11-15/A/redproof-review-s2.txt new file mode 100644 index 00000000..21c62fc8 --- /dev/null +++ b/documentation/audits/build-release-4-2026-11-15/A/redproof-review-s2.txt @@ -0,0 +1,21 @@ +SECURITY FINDING 2 on the review-fix-1 commit — the wait's key was the shortened display list of the apps. + +### RED: the new test before the fix (felhom.eu 1fac9c16) +=== RUN TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait + ended_large_marker_test.go:115: a different app set rode the first set's week (the two differ only after the tenth name): 10 agreed, [{App: Reason:2 snapshot id(s) wait for the next window: one window removes at most 10 snapshots of removed apps (the size of its own cap)}] +--- FAIL: TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait (0.05s) +FAIL +FAIL gitea.dooplex.hu/admin/felhom-hub/internal/offsitekeys 0.056s +FAIL + +### After the fix: mutations +== MUTATION: the key is the shortened display list again + RED on the mutant, GREEN on the real file + --- FAIL: TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait (0.05s) + ended_large_marker_test.go:115: a different app set rode the first set's week (the two differ only after the tenth name): 10 agreed, [{App: Reason:2 snapshot id(s) wait for the next window: one window removes at most 10 snapshots +== MUTATION: the key depends on the order the names came in + RED on the mutant, GREEN on the real file + --- FAIL: TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait (0.05s) + ended_large_marker_test.go:121: the key must be one fixed-size value for one set, whatever its order: "9ab9de25768ac172235e119b76362ecddad33878fe9a7792cdddbe47236f9a87" "ab096ba45a5db065588d721c11c2ba547a9ed29e67941e6949d9ea4c9da9 + +2 mutations, 0 not a red-proof diff --git a/hub/CHANGELOG.md b/hub/CHANGELOG.md index f2224061..5d1ad83e 100644 --- a/hub/CHANGELOG.md +++ b/hub/CHANGELOG.md @@ -1,5 +1,10 @@ ## Unreleased (after v0.182.0) +- **Security fix 2 on review fix 1 (2026-11-15): the large request's wait is keyed on the WHOLE app set.** The key + was the shortened display list (ten names „and N more”), so two different sets with the same first ten names + shared one wait and one mail. `largeSetKey` is now a SHA-256 of the full sorted set; the display string is only + shown. Test `TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait` — seen red; 2 mutations seen red + (`…/A/redproof-review-s2.txt`). - **Security fix on review fix 1 (2026-11-15): the hub's first sight of a large request is its OWN record.** It was found by searching the windows' refusal text (`instr(ended_refused, …)`), and that text also held names a box had claimed — a box could plant the marker in a claimed name a week ahead and skip the wait and the operator's mail. diff --git a/hub/internal/offsitekeys/ended.go b/hub/internal/offsitekeys/ended.go index 88280eb7..f8e1e78f 100644 --- a/hub/internal/offsitekeys/ended.go +++ b/hub/internal/offsitekeys/ended.go @@ -1,6 +1,8 @@ package offsitekeys import ( + "crypto/sha256" + "encoding/hex" "fmt" "sort" "strings" @@ -241,7 +243,7 @@ func (s *Service) agreeEndedFor(customerID string, windowID int64, maxRemove int "NOTHING of them is removed in this window. The hub's own records agree to each app, so from %s a window removes them, at most %d per window. "+ "If the household did not remove these apps, switch the weekly windows off for it before that day and look at the box.", windowID, customerID, len(ids), total, appNames(byApp), now.Add(largeEndedWait).UTC().Format("2006-01-02"), endedCap(maxRemove, total)), - map[string]any{"subject": "large:" + appNames(byApp), "window_id": windowID, "asked": len(ids), "listed": total}) + map[string]any{"subject": "large:" + key[:16], "window_id": windowID, "asked": len(ids), "listed": total}) } refused = append(refused, store.EndedRefusal{Reason: fmt.Sprintf("the request is for %d of %d snapshots — more than half of the store: it waits one week, and the operator is told", len(ids), total)}) @@ -347,8 +349,18 @@ func appNames(byApp map[string][]string) string { return strings.Join(names, ", ") } -// largeSetKey is the key of an app set in the hub's own record of large requests. -func largeSetKey(byApp map[string][]string) string { return appNames(byApp) } +// largeSetKey is the key of an app set in the hub's own record of large requests: a hash of the WHOLE sorted set. +// Never the display string (appNames), which is cut after ten names — two sets that differ after the tenth name +// would share one wait (security review of 2026-11-15). +func largeSetKey(byApp map[string][]string) string { + names := make([]string, 0, len(byApp)) + for app := range byApp { + names = append(names, app) + } + sort.Strings(names) + sum := sha256.Sum256([]byte(strings.Join(names, "\n"))) + return hex.EncodeToString(sum[:]) +} // ledgerName is a claimed name as the hub may write it down: itself when it has the shape of an app name, else a // fixed placeholder. diff --git a/hub/internal/offsitekeys/ended_large_marker_test.go b/hub/internal/offsitekeys/ended_large_marker_test.go index 17dec949..135d1187 100644 --- a/hub/internal/offsitekeys/ended_large_marker_test.go +++ b/hub/internal/offsitekeys/ended_large_marker_test.go @@ -81,3 +81,46 @@ func TestD84_TheLargeRequestRecordIsBoundedAndGoesWithTheHousehold(t *testing.T) } var _ = store.EndedRefusal{} } + +// Security review, second finding: the wait's key was the SHORTENED display list of the apps (ten names „and N +// more”), so two different app sets with the same first ten names shared one wait. The key is the whole sorted set. +// RED-PROOF: documentation/audits/build-release-4-2026-11-15/A/redproof-review-s2.txt. +func TestD84_TwoAppSetsThatDifferAfterTheTenthNameDoNotShareAWait(t *testing.T) { + s, events, all := ghostFixture(t) + now := time.Now().UTC() + var names []string + for i := 0; i < 10; i++ { + names = append(names, "app-0"+string(rune('0'+i))) + } + names = append(names, "zz-first", "zz-second") + if err := s.Store.NoteAppList("c1", []string{"immich"}, names, now.Add(-31*24*time.Hour)); err != nil { + t.Fatal(err) + } + set := func(last string) []EndedClaim { + var cl []EndedClaim + for i := 0; i < 10; i++ { + cl = append(cl, EndedClaim{App: names[i], SnapshotIDs: []string{all[i]}}) + } + return append(cl, EndedClaim{App: last, SnapshotIDs: []string{all[10], all[11]}}) // 12 of 20: a large request + } + g0 := openGranted(t, s, 20, set("zz-first")...) + if len(g0.EndedAllowed) != 0 || !hasReason(g0.EndedRefused, "waits one week") { + t.Fatalf("fixture: the first large request must wait: %d agreed, %+v", len(g0.EndedAllowed), g0.EndedRefused) + } + _ = s.CloseWindowFor(context.Background(), "c1", WindowResult{WindowID: g0.WindowID, CountBefore: 20, CountAfter: 20, Outcome: "nothing"}) + aWeekLater(t, s) + // a week later ANOTHER set — the same first ten names, another eleventh + g1 := openGranted(t, s, 20, set("zz-second")...) + if len(g1.EndedAllowed) != 0 || !hasReason(g1.EndedRefused, "waits one week") { + t.Fatalf("a different app set rode the first set's week (the two differ only after the tenth name): %d agreed, %+v", len(g1.EndedAllowed), g1.EndedRefused) + } + if n := len(ofType(*events, EventEndedLargeAgreement)); n != 2 { + t.Fatalf("two different large requests gave %d operator warning(s), want 2", n) + } + if a, b := largeSetKey(map[string][]string{"x": nil, "y": nil}), largeSetKey(map[string][]string{"y": nil, "x": nil}); a != b || len(a) != 64 { + t.Fatalf("the key must be one fixed-size value for one set, whatever its order: %q %q", a, b) + } + if largeSetKey(map[string][]string{"a,b": nil}) == largeSetKey(map[string][]string{"a": nil, "b": nil}) { + t.Fatal("two different sets have one key") + } +}