hub (unreleased): review fix 3 — a name that reaches a household's mail is a plain app slug; a link-shaped name gets no notice and is never agreed
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
7b46dbcc3e
commit
73a534e753
7 files changed
+131
-3
No files matched your search
@@ -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
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
## Unreleased (after v0.182.0)
|
## 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
|
- **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
|
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
|
name each time, or one app pressed, taken back and pressed again — and each one mailed the operator
|
||||||
|
|||||||
@@ -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-<n>.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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`
|
// 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
|
// (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.
|
// 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) {
|
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"
|
return EndNoticeFailed, "not an app name"
|
||||||
}
|
}
|
||||||
if d.resendAPIKey == "" {
|
if d.resendAPIKey == "" {
|
||||||
|
|||||||
@@ -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 {
|
func untoldReason(now time.Time, notices map[string]store.EndNotice, app string) string {
|
||||||
n, ok := notices[app]
|
n, ok := notices[app]
|
||||||
switch {
|
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:
|
case !ok:
|
||||||
return reasonNoNotice
|
return reasonNoNotice
|
||||||
case !n.Told():
|
case !n.Told():
|
||||||
|
|||||||
@@ -147,3 +147,20 @@ func endedFixtureNoNotice(t *testing.T) (*Service, *[]evt) {
|
|||||||
}
|
}
|
||||||
return s, events
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
claimed := map[string]string{} // app → press (the first claim of a name wins)
|
||||||
var order []string
|
var order []string
|
||||||
for _, c := range claims {
|
for _, c := range claims {
|
||||||
if !ValidPresenceApp(c.App) || ReservedPresenceApp(c.App) || in[c.App] {
|
if !ValidNoticeApp(c.App) || in[c.App] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, dup := claimed[c.App]; dup {
|
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)
|
customerID, eventType, since.UTC().Format("2006-01-02 15:04:05"), marker).Scan(&n)
|
||||||
return n > 0, err
|
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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user