carlos / platform Public

console: a refused platform link adopts no owner either

A manifest whose platform link materialization refuses is anomalous,
since no minter writes one, so it now fails closed: the account is born
unlinked and ownerless, skipping both owner-adoption paths (AddMember
and materializeOwner). New test: a refused link plus a valid owner gives
no membership and the stdlib 404. The birth test now fails on a Members
error before checking the result.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9f2f64ebd1f6f9bccd2aee3c7c2cf6723a4c9777 parent 785331a
2 files changed, +56 −11
  • internal/console/materialize.go +14 −9
  • internal/console/materialize_test.go +42 −2
diff --git a/internal/console/materialize.go b/internal/console/materialize.go
index da5843591..04778857b 100644
--- a/internal/console/materialize.go
+++ b/internal/console/materialize.go
@@ -164,14 +164,16 @@ func materializeAccounts(ctx context.Context, s release.Store, st *Store, unlink
// A customer account's platform link is adopted here and only here,
// under the same check MintLinkedAccount applies before it writes,
// plus the one only the account knows: it is not its own platform. A
- // link that fails is dropped, not the account: the row is born
- // unlinked and, as customers are minted with no owner, unreachable,
- // which is the safe side.
+ // link that fails is dropped, not the account. No minter writes such
+ // a manifest, so it fails CLOSED: the row is born unlinked and
+ // ownerless (an owner it names is not adopted either), which is
+ // unreachable, the safe side.
link := m.Platform != ""
+ rejectedLink := false
if link && (!domains.ValidPlatformLink(m.Platform, m.PlatformMint) || m.Platform == m.Sqid) {
log.Printf("console: %s names platform %q with mint id %q, which is not a link it can have; "+
- "materializing the account unlinked", key, m.Platform, m.PlatformMint)
- link = false
+ "materializing the account unlinked and without an owner", key, m.Platform, m.PlatformMint)
+ link, rejectedLink = false, true
}
var added bool
if link {
@@ -197,8 +199,8 @@ func materializeAccounts(ctx context.Context, s release.Store, st *Store, unlink
// leave behind. Only on the FIRST materialization, and only for an
// address the sign-in form would accept: a typo'd owner is a grant
// nobody could ever claim, and inventing it would just be a stranded
- // row with a confusing name on it.
- if m.Owner != "" {
+ // row with a confusing name on it. Never for a refused link (above).
+ if m.Owner != "" && !rejectedLink {
if !ValidAddress(m.Owner) {
log.Printf("console: account %s names owner %q, which is not a keymail address — "+
"nobody could sign in as it, so no membership was created. Fix it with: "+
@@ -213,8 +215,11 @@ func materializeAccounts(ctx context.Context, s release.Store, st *Store, unlink
}
log.Printf("console: materialized account %s (%s) from the bucket", m.Sqid, m.Name)
n++
- // ONLY here — on the pass that created the row, never on a later one.
- materializeOwner(st, key, m, created)
+ // ONLY here — on the pass that created the row, never on a later one,
+ // and never for a refused link.
+ if !rejectedLink {
+ materializeOwner(st, key, m, created)
+ }
}
return n, nil
}
diff --git a/internal/console/materialize_test.go b/internal/console/materialize_test.go
index 51248d8e0..4f98d78f5 100644
--- a/internal/console/materialize_test.go
+++ b/internal/console/materialize_test.go
@@ -742,6 +742,12 @@ const (
// putLinkManifest writes the customer manifest bdf, linked to platform with
// ref and mint and no owner, over whatever is there.
func putLinkManifest(t *testing.T, rel release.Store, platform, ref, mint string) {
+ t.Helper()
+ putLinkManifestOwned(t, rel, platform, ref, mint, "")
+}
+
+// putLinkManifestOwned is putLinkManifest naming owner as well.
+func putLinkManifestOwned(t *testing.T, rel release.Store, platform, ref, mint, owner string) {
t.Helper()
ctx := t.Context()
sqid := domains.Sqid(linkCustomerID)
@@ -754,7 +760,7 @@ func putLinkManifest(t *testing.T, rel release.Store, platform, ref, mint string
t.Fatal(err)
}
body, err := json.Marshal(domains.AccountManifest{ID: linkCustomerID, Sqid: sqid, Name: "Shop",
- Platform: platform, PlatformRef: ref, PlatformMint: mint, CreatedAt: time.Unix(1700000000, 0).UTC()})
+ Owner: owner, Platform: platform, PlatformRef: ref, PlatformMint: mint, CreatedAt: time.Unix(1700000000, 0).UTC()})
if err != nil {
t.Fatal(err)
}
@@ -788,7 +794,11 @@ func TestMaterializeCarriesThePlatformLinkAtBirth(t *testing.T) {
if p, ref := accountPlatformOf(t, st, linkCustomerID); p != linkPlatform || ref != "4812" {
t.Errorf("AccountPlatform(bdf) = %q, %q; want bcd, 4812", p, ref)
}
- if members, _ := st.Members(linkCustomerID); len(members) != 0 {
+ members, err := st.Members(linkCustomerID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(members) != 0 {
t.Errorf("Members(bdf) = %+v, want none: a customer is born held by its platform", members)
}
}
@@ -916,3 +926,33 @@ func TestLinkedOwnerlessAccountReachesNobody(t *testing.T) {
t.Errorf("GET /a/bdf/ signed in = %d %q, want the stdlib 404", status, body)
}
}
+
+// A manifest carrying a link the console refuses is anomalous: no minter
+// writes one. It fails closed. The account is born unlinked AND ownerless,
+// even when the manifest also names a valid owner, so the person it names
+// gets the standard 404 rather than an account a forged link came with.
+func TestMaterializeRefusedLinkAdoptsNoOwner(t *testing.T) {
+ fx := newConsoleFixture(t)
+ putLinkManifestOwned(t, fx.rel, domains.Sqid(domains.ReservedAccountID), "4812", linkMint, "paul@keymail.dev")
+ if _, err := MaterializeAccounts(t.Context(), fx.rel, fx.st); err != nil {
+ t.Fatal(err)
+ }
+ if a, err := fx.st.AccountBySqid("bdf"); err != nil || a == nil {
+ t.Fatalf("AccountBySqid(bdf) = %v %v, want the row", a, err)
+ }
+ if p, ref := accountPlatformOf(t, fx.st, linkCustomerID); p != "" || ref != "" {
+ t.Errorf("AccountPlatform(bdf) = %q, %q; want unlinked", p, ref)
+ }
+ members, err := fx.st.Members(linkCustomerID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(members) != 0 {
+ t.Errorf("Members(bdf) = %+v, want none: a refused link adopts no owner", members)
+ }
+ browser := signInPaul(t, fx)
+ status, _, body := get(t, browser, fx.ts.URL+"/a/bdf/")
+ if status != http.StatusNotFound || body != "404 page not found\n" {
+ t.Errorf("GET /a/bdf/ as the manifest's owner = %d %q, want the stdlib 404", status, body)
+ }
+}