carlos / platform Public

console: turning a password gate off is the owner's (H4-M12)

Any member could clear an app's password gate, from the browser with no
step-up or from the CLI PATCH with gate "". Per the ruling, clearing is
now owner plus passkey on the browser form (a member meets the owner
gate's 404; requireFreshAuth runs last, before the write) and owner-only
on the CLI PATCH (apiOwnerOnly, 403). Setting a password stays any
member's. CLI step-up is owed to the H4-M9 design.

Carries the hunt test TestHunt_H4_M12_MemberCannotClearPasswordGate.
Three gate tests now clear as the owner and pin the member's refusal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7e79410732455836781012c5de71f8ab9df55333 parent fd53eaa
5 files changed, +92 −9
  • internal/console/apiinstances.go +6 −0
  • internal/console/apiinstances_test.go +10 −3
  • internal/console/appsettings.go +14 −6
  • internal/console/appsettings_gate_test.go +10 −0
  • internal/console/hunt_H4-M12_test.go +52 −0
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index dd593f746..6c6edd4e4 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -3109,6 +3109,12 @@ func (s *Server) handleAPIInstanceUpdate(w http.ResponseWriter, r *http.Request)
"nothing to update — send addrs, probe, steering, environment, gate, or a combination")
return
}
+ // Turning a password off is the owner's act (H4-M12): the browser asks
+ // an owner and a passkey, and the CLI has no step-up yet, so this door
+ // asks the owner. Setting one stays any member's.
+ if req.Gate != nil && *req.Gate == "" && !s.apiOwnerOnly(w, r, acct, "turn off an instance's password") {
+ return
+ }
// A team credential may not repoint a hostname's upstream (§4): addrs
// and steering are refused on shape, before anything is read.
tv, team := teamFrom(r.Context())
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go
index 5eedb7c3e..4e5973063 100644
--- a/internal/console/apiinstances_test.go
+++ b/internal/console/apiinstances_test.go
@@ -1537,8 +1537,10 @@ func TestAPIInstanceUpdateAuditNamesChangedFields(t *testing.T) {
}
// Combined case: steering, environment and gate together name all
- // three, in request-struct order.
- if status, _, out := rawReq(t, http.MethodPatch, pu, token,
+ // three, in request-struct order. An owner's token: turning a password
+ // off is the owner's (H4-M12).
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-audit-fields-owner")
+ if status, _, out := rawReq(t, http.MethodPatch, pu, owner,
`{"steering":"","environment":"","gate":""}`); status != http.StatusOK {
t.Fatalf("patch steering+environment+gate = %d %s, want 200", status, out)
}
@@ -2581,7 +2583,12 @@ func TestAPIInstanceUpdateGateRoundTrip(t *testing.T) {
}
}
- status, _, out = rawReq(t, http.MethodPatch, pu, token, `{"gate":""}`)
+ // Turning it off is the owner's (H4-M12); the member is refused.
+ if status, _, out := rawReq(t, http.MethodPatch, pu, token, `{"gate":""}`); status != http.StatusForbidden {
+ t.Fatalf("member patch clear = %d %s, want 403", status, out)
+ }
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-gate-roundtrip-owner")
+ status, _, out = rawReq(t, http.MethodPatch, pu, owner, `{"gate":""}`)
if status != http.StatusOK {
t.Fatalf("patch clear = %d %s", status, out)
}
diff --git a/internal/console/appsettings.go b/internal/console/appsettings.go
index 54902ae62..175cc6dac 100644
--- a/internal/console/appsettings.go
+++ b/internal/console/appsettings.go
@@ -1172,13 +1172,14 @@ func renameAdvice(err error, to string) string {
}
// handleAppGate is the Settings page's password-gate form: set a password
-// on one instance host, or turn it off. Member-gated, matching the API
-// PATCH's door — the CLI already lets a member do this, and a form that
-// refuses what the CLI allows is a rule in the wrong place. CSRF first,
-// then the same read-mutate-validate-write-audit sequence as the PATCH,
-// against one field. The password is never logged, audited or echoed.
+// on one instance host, or turn it off. Setting is any member's, matching
+// the API PATCH's door. Turning it off exposes the host to everyone, so it
+// is the owner's, with a passkey (security hunt H4-M12): a member meets the
+// owner gate's 404, and requireFreshAuth runs last, before the write. CSRF
+// first, then the same read-mutate-validate-write-audit sequence as the
+// PATCH, against one field. The password is never logged, audited or echoed.
func (s *Server) handleAppGate(w http.ResponseWriter, r *http.Request) {
- addr, raw, acct, _, app, ok := s.accountApp(w, r)
+ addr, raw, acct, role, app, ok := s.accountApp(w, r)
if !ok {
return
}
@@ -1203,6 +1204,10 @@ func (s *Server) handleAppGate(w http.ResponseWriter, r *http.Request) {
var hash string
switch r.FormValue("action") {
case "clear":
+ if role != RoleOwner {
+ http.NotFound(w, r)
+ return
+ }
case "set":
p := r.FormValue("password")
if err := gate.CheckPassword(p); err != nil {
@@ -1237,6 +1242,9 @@ func (s *Server) handleAppGate(w http.ResponseWriter, r *http.Request) {
back("err", err.Error()+".")
return
}
+ if hash == "" && !s.requireFreshAuth(w, r, addr, raw) {
+ return
+ }
if err := s.withRecordLock(rec.Account, rec.App, func() error { return provision.UpdateRecord(ctx, s.cfg.Releases, *rec, etag) }); err != nil {
if errors.Is(err, release.ErrCASConflict) {
back("err", "The instance changed while this request was in flight — try again.")
diff --git a/internal/console/appsettings_gate_test.go b/internal/console/appsettings_gate_test.go
index e62d138cb..00b43e0e3 100644
--- a/internal/console/appsettings_gate_test.go
+++ b/internal/console/appsettings_gate_test.go
@@ -56,8 +56,18 @@ func TestAppSettingsGateSetAndClear(t *testing.T) {
t.Fatalf("short password not refused on the page: %s", body)
}
+ // Turning it off is the owner's, with a passkey (security hunt H4-M12):
+ // the member meets the owner gate's 404, the owner steps up.
status, _, _ = postForm(t, c, fx.u("/apps/titogo/gate"),
url.Values{"csrf": {csrf}, "host": {"pw.go.tito.io"}, "action": {"clear"}})
+ if status != http.StatusNotFound {
+ t.Fatalf("member clear = %d, want 404", status)
+ }
+ fx.setUser("paul@keymail.dev")
+ owner := newBrowser(t)
+ signUp(t, fx, owner, "code-settings-gate-owner")
+ status, _, _ = postGated(t, fx, owner, fx.u("/apps/titogo/gate"),
+ url.Values{"csrf": {sessionToken(t, fx, owner)}, "host": {"pw.go.tito.io"}, "action": {"clear"}})
if status != http.StatusSeeOther {
t.Fatalf("clear = %d", status)
}
diff --git a/internal/console/hunt_H4-M12_test.go b/internal/console/hunt_H4-M12_test.go
new file mode 100644
index 000000000..a7710b11f
--- /dev/null
+++ b/internal/console/hunt_H4-M12_test.go
@@ -0,0 +1,52 @@
+package console
+
+import (
+ "context"
+ "net/http"
+ "net/url"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/gate"
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+func TestHunt_H4_M12_MemberCannotClearPasswordGate(t *testing.T) {
+ fx, member := huntInstanceFixture(t, "hunt-m12")
+ hash, err := gate.Hash("hunt password gate")
+ if err != nil {
+ t.Fatal(err)
+ }
+ rec := provision.Record{Schema: 1, Host: "hunt.go.tito.io", Slug: "hunt", App: "titogo", Account: fx.sqid, Region: "ie", Channel: "stable", CreatedAt: time.Now().UTC(), Gate: hash}
+ if err := provision.CreateRecord(context.Background(), fx.rel, rec); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.st.CreateAppIn(OpsAccountID, "sibling", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ sibling := mintInstanceToken(t, fx, member, "sibling")
+ if code, _, _ := rawReq(t, http.MethodPatch, instancesURL(fx, "bab", "titogo")+"/"+rec.Host, sibling, `{"gate":""}`); code != http.StatusNotFound {
+ t.Fatalf("sibling token control: %d", code)
+ }
+ fx.setUser("stranger@keymail.dev")
+ stranger := newBrowser(t)
+ signUp(t, fx, stranger, "hunt-m12-stranger")
+ if code, _, _ := postForm(t, stranger, fx.u("/apps/titogo/gate"), url.Values{"csrf": {sessionToken(t, fx, stranger)}, "host": {rec.Host}, "action": {"clear"}}); code != http.StatusNotFound {
+ t.Fatalf("foreign member control: %d", code)
+ }
+ untouched, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "titogo", rec.Host)
+ if err != nil || untouched.Gate != hash {
+ t.Fatal("negative control changed gate")
+ }
+ fx.setUser("alice@keymail.dev")
+ browser := newBrowser(t)
+ signUp(t, fx, browser, "hunt-m12-browser")
+ code, _, _ := postForm(t, browser, fx.u("/apps/titogo/gate"), url.Values{"csrf": {sessionToken(t, fx, browser)}, "host": {rec.Host}, "action": {"clear"}})
+ got, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "titogo", rec.Host)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if code != http.StatusForbidden && code != http.StatusNotFound || got.Gate != hash {
+ t.Errorf("member cleared password gate without step-up: status=%d gate_empty=%v; want refusal and unchanged gate", code, got.Gate == "")
+ }
+}