carlos / platform Public

console: CLI app delete is owner-only, like the browser (H4-M2)

The CLI/API trash door needed only membership (or a publish-role
service credential), while the browser delete needs owner plus passkey.
apiOwnerOnly, a new shared gate beside apiOwnerAccountFor, gives the CLI
door the owner half with the same 403 wording. The passkey half is owed
to the CLI step-up design (H4-M9).

Owner-minted service credentials keep the door's role set; a legacy
instance token, which any member can mint, is held to its minter's role.

Carries the hunt test TestHunt_H4_M2_MemberCannotTrash. The trash test
fixture and one restart test now trash with an owner bearer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f6ac853273e0603f3b56c3a2e7b6a2f1dc800b58 parent 5007dac
5 files changed, +78 −6
  • internal/console/apicli.go +5 −0
  • internal/console/apicli_test.go +6 −5
  • internal/console/apirestart_test.go +2 −1
  • internal/console/apiservices.go +39 −0
  • internal/console/hunt_H4-M2_test.go +26 −0
diff --git a/internal/console/apicli.go b/internal/console/apicli.go
index aa367b4a3..02e9b9640 100644
--- a/internal/console/apicli.go
+++ b/internal/console/apicli.go
@@ -1712,6 +1712,11 @@ func (s *Server) handleAPITrashApp(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
+ // The browser's delete is owner plus passkey (handleAppDelete); the CLI
+ // has no step-up yet, so this door holds the owner half (H4-M2).
+ if !s.apiOwnerOnly(w, r, acct, "delete an app") {
+ return
+ }
p, _ := principalFrom(r.Context())
if !s.allowWrite(p, time.Now()) {
jsonError(w, http.StatusTooManyRequests, "too many requests — wait a minute and try again")
diff --git a/internal/console/apicli_test.go b/internal/console/apicli_test.go
index ced8f9f48..b46fa2828 100644
--- a/internal/console/apicli_test.go
+++ b/internal/console/apicli_test.go
@@ -2118,9 +2118,10 @@ func TestAPIShipReshipToleratesADifferentLabel(t *testing.T) {
// ---- trash and restore ------------------------------------------------------
-// trashFixture is a console with titogo claimed in the ops account and a
-// MEMBER (not owner) token for it: trashing is a member action on purpose —
-// the 30-day window is what makes the reversible verb cheap.
+// trashFixture is a console with titogo claimed in the ops account, alice a
+// member, and an OWNER token for it: the CLI delete is owner-only, the
+// browser delete's owner half (security hunt H4-M2,
+// TestHunt_H4_M2_MemberCannotTrash).
func trashFixture(t *testing.T, code string) (*consoleFixture, string) {
t.Helper()
fx := newConsoleFixture(t)
@@ -2131,7 +2132,7 @@ func trashFixture(t *testing.T, code string) (*consoleFixture, string) {
if err := fx.st.AddMember(OpsAccountID, "alice@keymail.dev", RoleMember, now); err != nil {
t.Fatal(err)
}
- return fx, cliToken(t, fx, "alice@keymail.dev", code)
+ return fx, cliToken(t, fx, "paul@keymail.dev", code)
}
// tombstone reads the trash marker straight from the fixture's own bucket —
@@ -2178,7 +2179,7 @@ func TestAPITrashAndRestoreApp(t *testing.T) {
if tomb == nil {
t.Fatal("no trash marker in the bucket after a 200 delete")
}
- if tomb.Actor != "alice@keymail.dev" {
+ if tomb.Actor != "paul@keymail.dev" {
t.Fatalf("marker actor = %q, want the token's own identity", tomb.Actor)
}
if has, err := fx.st.HasAppIn(OpsAccountID, "titogo"); err != nil || has {
diff --git a/internal/console/apirestart_test.go b/internal/console/apirestart_test.go
index b099d58ba..dfb581d27 100644
--- a/internal/console/apirestart_test.go
+++ b/internal/console/apirestart_test.go
@@ -155,7 +155,8 @@ func TestAPIRestartIsRateLimited(t *testing.T) {
// somebody's app was deleted.
func TestAPIRestartRefusesATrashedApp(t *testing.T) {
fx, token := restartFixture(t, "code-restart-trashed")
- if status, out := postBody(t, fx.ts.URL+"/api/cli/apps/bab/titogo/delete", token, ""); status != http.StatusOK {
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-restart-trashed-owner") // delete is owner-only (H4-M2)
+ if status, out := postBody(t, fx.ts.URL+"/api/cli/apps/bab/titogo/delete", owner, ""); status != http.StatusOK {
t.Fatalf("trash = %d %s", status, out)
}
if status, body := postBody(t, fx.ts.URL+"/api/cli/apps/bab/titogo/restart", token, ""); status != http.StatusNotFound {
diff --git a/internal/console/apiservices.go b/internal/console/apiservices.go
index 5500eddfb..9d1d14553 100644
--- a/internal/console/apiservices.go
+++ b/internal/console/apiservices.go
@@ -136,6 +136,45 @@ func (s *Server) apiOwnerAccountFor(w http.ResponseWriter, r *http.Request, purp
return p, acct, true
}
+// apiOwnerOnly is the owner gate of the browser's owner-only app doors
+// (owner(), or accountApp plus role == RoleOwner) for a CLI door that has
+// already resolved acct through the family's 404 (apiAccountApp and kin).
+// It answers apiOwnerAccountFor's 403 in the same words: the caller has
+// proved membership, so the refusal hides nothing (security hunt H4).
+//
+// A person must hold the owner role. A service credential minted through
+// the services doors carries the authority of the owner who minted it
+// (those doors are owner-only) and passes; the door's role set is its
+// limit. A legacy instance token (kind 'app', no name), which ANY member
+// may mint, is held to its minter's role now: otherwise a member reaches an
+// owner-only act by minting one and calling the door with it.
+func (s *Server) apiOwnerOnly(w http.ResponseWriter, r *http.Request, acct *Account, purpose string) bool {
+ p, _ := principalFrom(r.Context())
+ if s.ownerAuthority(p, acct) {
+ return true
+ }
+ jsonError(w, http.StatusForbidden, "only an account owner can "+purpose)
+ return false
+}
+
+// ownerAuthority is apiOwnerOnly's rule without the answer. A store error
+// is not ownership.
+func (s *Server) ownerAuthority(p Principal, acct *Account) bool {
+ switch {
+ case p.Kind == PrincipalUser:
+ return acct.Role == RoleOwner
+ case p.Kind == PrincipalService && p.Name == "":
+ role, err := s.store.Role(acct.ID, p.Address)
+ if err != nil {
+ log.Printf("console: owner gate %s: minter role: %v", acct.Sqid, err)
+ }
+ return err == nil && role == RoleOwner
+ case p.Kind == PrincipalService:
+ return true
+ }
+ return false
+}
+
// doorsFor lists the /api/cli/ patterns a role reaches, sorted.
//
// It reads s.cliRoles — the SAME map the gate consults on every request — so
diff --git a/internal/console/hunt_H4-M2_test.go b/internal/console/hunt_H4-M2_test.go
new file mode 100644
index 000000000..2cffe3094
--- /dev/null
+++ b/internal/console/hunt_H4-M2_test.go
@@ -0,0 +1,26 @@
+package console
+
+import (
+ "net/http"
+ "net/url"
+ "testing"
+)
+
+func TestHunt_H4_M2_MemberCannotTrash(t *testing.T) {
+ fx, member := huntInstanceFixture(t, "hunt-m2")
+ browser := newBrowser(t)
+ signUp(t, fx, browser, "hunt-m2-browser")
+ status, _, _ := postForm(t, browser, fx.u("/apps/titogo/delete"), url.Values{"csrf": {sessionToken(t, fx, browser)}})
+ if status != http.StatusNotFound {
+ t.Fatalf("browser member control: %d; want 404", status)
+ }
+ status, out := postBody(t, fx.ts.URL+"/api/cli/apps/bab/titogo/delete", member, "")
+ has, err := fx.st.HasTrashedAppIn(OpsAccountID, "titogo")
+ if err != nil {
+ t.Fatal(err)
+ }
+ tomb := tombstone(t, fx, "titogo")
+ if status != http.StatusForbidden && status != http.StatusNotFound || tomb != nil || has {
+ t.Errorf("member trashed app: status=%d tombstone=%v trashed_row=%v; want refusal and unchanged app; response=%s", status, tomb != nil, has, out)
+ }
+}