carlos / platform Public

console: legacy buy redirects ignore a linked app's state

The old app-scoped buy and purchase URLs depend only on membership and
the purchase's account. They were classified linkedRefuseDomains and
answered 409 when {app} named a linked app, including a purged app's
name reused by one, so an owned purchase's Checkout return failed. They
are linkedAllow now and the redirect gate reads nothing about the app;
CSRF and the purchase's account check stay. The account doors they lead
to still refuse a linked app. Tests cover a linked app on both the
purchase redirects and the stale posts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6b1420bb3aa5a386bd4a86b57f747ce9f6291334 parent 76cddb5
4 files changed, +42 −15
  • internal/console/accountdomainbuy_test.go +18 −0
  • internal/console/apilinks_test.go +8 −0
  • internal/console/appdomainbuy.go +5 −10
  • internal/console/linkedpolicy.go +11 −5

CI failed — run details

diff --git a/internal/console/accountdomainbuy_test.go b/internal/console/accountdomainbuy_test.go
index 45056643d..ae63cf250 100644
--- a/internal/console/accountdomainbuy_test.go
+++ b/internal/console/accountdomainbuy_test.go
@@ -384,6 +384,14 @@ func TestOldPurchaseURLsRedirect(t *testing.T) {
if status, _, _ := get(t, c, f.acctURL("/domains/purchases/"+p.ID)); status != 200 {
t.Fatalf("the account card after the purge: %d", status)
}
+ // The legacy URLs never read the app's state: they land the same once
+ // the purged app's name belongs to a linked app.
+ t.Run("linked app", func(t *testing.T) {
+ if _, err := f.st.CreateLinkedApp(f.acct.ID, "kass", "link:0123456789ab", "0123456789ab", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ check(t)
+ })
}
func TestOldBuyPostsRedirectAndStartNothing(t *testing.T) {
@@ -396,6 +404,16 @@ func TestOldBuyPostsRedirectAndStartNothing(t *testing.T) {
t.Fatalf("POST %s: %d %q %s", path, status, loc, body)
}
}
+ // A linked app's stale form lands the same way and starts nothing.
+ if _, err := f.st.CreateLinkedApp(f.acct.ID, "blog", "link:0123456789ab", "0123456789ab", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ for _, path := range []string{"/apps/blog/domains/check", "/apps/blog/domains/buy"} {
+ status, loc, body := postForm(t, c, f.acctURL(path), form)
+ if status != http.StatusSeeOther || loc != "/a/"+f.acct.Sqid+"/domains/buy?app=blog" {
+ t.Fatalf("linked POST %s: %d %q %s", path, status, loc, body)
+ }
+ }
f.assertStartedNothing(t)
if contacts, _ := f.st.SavedContacts(context.Background(), f.acct.ID); len(contacts) != 0 {
t.Fatalf("a stale form saved a contact: %+v", contacts)
diff --git a/internal/console/apilinks_test.go b/internal/console/apilinks_test.go
index 3e9092897..2ee2b480a 100644
--- a/internal/console/apilinks_test.go
+++ b/internal/console/apilinks_test.go
@@ -672,6 +672,14 @@ var linkedAllowAnswers = map[string]int{
// row, so they stay editable; each redirects back with its flash.
"POST /a/{sqid}/apps/{app}/analytics/setting": http.StatusSeeOther,
"POST /a/{sqid}/apps/{app}/protection/setting": http.StatusSeeOther,
+ // The old app-scoped buy routes only redirect to the account's: the
+ // buy page and its stale posts at once; a purchase URL after reading
+ // the purchase, which the walk's placeholder ID is not.
+ "GET /a/{sqid}/apps/{app}/domains/buy": http.StatusSeeOther,
+ "POST /a/{sqid}/apps/{app}/domains/check": http.StatusSeeOther,
+ "POST /a/{sqid}/apps/{app}/domains/buy": http.StatusSeeOther,
+ "GET /a/{sqid}/apps/{app}/domains/purchases/{id}": http.StatusNotFound,
+ "GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status": http.StatusNotFound,
}
// linkedAllowForm and linkedAllowQuery are the fields an allowed door needs
diff --git a/internal/console/appdomainbuy.go b/internal/console/appdomainbuy.go
index 8f904fa7d..615c6f31f 100644
--- a/internal/console/appdomainbuy.go
+++ b/internal/console/appdomainbuy.go
@@ -200,11 +200,11 @@ func (s *Server) renderPurchaseCard(w http.ResponseWriter, r *http.Request, addr
// buying is the account's now. The old routes stay for open pages, stale
// forms and Checkouts prepared before the move, and only redirect. They
// check account membership (and a purchase's account), never that {app}
-// still exists, so a Checkout return lands after its app was purged. A
-// linked app still gets the domains refusal its policy names.
+// still exists, so a Checkout return lands after its app was purged, or
+// once its name belongs to a linked app (linkedpolicy.go: linkedAllow).
-// appBuyRedirectGate is the redirects' gate: membership, CSRF on a POST,
-// and the linked-app policy.
+// appBuyRedirectGate is the redirects' gate: membership and CSRF on a
+// POST. Nothing about the app is read.
func (s *Server) appBuyRedirectGate(w http.ResponseWriter, r *http.Request) (*Account, string, bool) {
_, raw, acct, _, ok := s.account(w, r)
if !ok {
@@ -214,12 +214,7 @@ func (s *Server) appBuyRedirectGate(w http.ResponseWriter, r *http.Request) (*Ac
s.renderMessage(w, r, http.StatusForbidden, domainBuyCopy["refused"], domainBuyCopy["csrf"])
return nil, "", false
}
- app := r.PathValue("app")
- if ref := s.linkedAppRefusal(r, acct, app); ref != nil {
- s.renderMessage(w, r, ref.Status, "Refused", ref.Msg)
- return nil, "", false
- }
- return acct, app, true
+ return acct, r.PathValue("app"), true
}
// handleAppDomainBuyRedirect answers the old buy page and its two stale
diff --git a/internal/console/linkedpolicy.go b/internal/console/linkedpolicy.go
index 1f1b191b2..16fa991ca 100644
--- a/internal/console/linkedpolicy.go
+++ b/internal/console/linkedpolicy.go
@@ -70,12 +70,18 @@ var linkedPolicies = map[string]linkedPolicy{
"GET /api/cli/apps/{account}/{app}/analytics": linkedAllow,
"GET /api/cli/apps/{account}/{app}/geo": linkedAllow,
+ // Plan 1's app-scoped buy routes only redirect to the account's
+ // (appdomainbuy.go): they depend on membership and a purchase's
+ // account alone, never on the app's state, so a Checkout return lands
+ // even when the name now belongs to a linked app. The account's doors
+ // they lead to refuse a linked app themselves (startDomainPurchase).
+ "GET /a/{sqid}/apps/{app}/domains/buy": linkedAllow,
+ "POST /a/{sqid}/apps/{app}/domains/check": linkedAllow,
+ "POST /a/{sqid}/apps/{app}/domains/buy": linkedAllow,
+ "GET /a/{sqid}/apps/{app}/domains/purchases/{id}": linkedAllow,
+ "GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status": linkedAllow,
+
// Custom domains, slice 1: refused with their own sentence (LD-C12).
- "GET /a/{sqid}/apps/{app}/domains/buy": linkedRefuseDomains,
- "POST /a/{sqid}/apps/{app}/domains/check": linkedRefuseDomains,
- "POST /a/{sqid}/apps/{app}/domains/buy": linkedRefuseDomains,
- "GET /a/{sqid}/apps/{app}/domains/purchases/{id}": linkedRefuseDomains,
- "GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status": linkedRefuseDomains,
"POST /a/{sqid}/apps/{app}/domains/attach": linkedRefuseDomains,
"POST /a/{sqid}/apps/{app}/domains/detach": linkedRefuseDomains,
"POST /a/{sqid}/apps/{app}/domains/point": linkedRefuseDomains,