From 8e1204f40065f3b98c4d27bd0751472d4af09b0e Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Mon, 16 Nov 2026 11:30:23 +0100 Subject: [PATCH] fix(api): let an owner's phone read the version check without Face ID GET /api/version/check is registered at the Configure tier, so reading it through the app's passthrough asked for a passkey ceremony. The iPhone app is about to show the running version, a newer one and its notes in Settings, and Face ID is the wrong cost for a question. Mark the GET NoStepUp. It stays Configure, so an owner is still required and a viewer cannot make the box ask GitHub with ?force=1. Installing (POST /api/version/update) and every other version write keep the ceremony. Tests cover the route table and the passthrough: the owner's read reaches the handler, the update still answers E_NEEDS_STEP_UP and a viewer is refused. The passthrough section of docs/protocol.md now names the routes that skip the ceremony. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Fredrik Ahlgren --- .changeset/version-check-no-step-up.md | 8 +++ docs/protocol.md | 8 +-- go/internal/api/api.go | 5 +- go/internal/api/api_passthrough_test.go | 71 +++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 .changeset/version-check-no-step-up.md diff --git a/.changeset/version-check-no-step-up.md b/.changeset/version-check-no-step-up.md new file mode 100644 index 000000000..6743ed904 --- /dev/null +++ b/.changeset/version-check-no-step-up.md @@ -0,0 +1,8 @@ +--- +"ftw": patch +--- + +An owner's phone can now ask the box whether a newer Core exists +(`GET /api/version/check`) without Face ID, so the app can show the newer +version and its notes. Installing it (`POST /api/version/update`) still asks +for Face ID, and a viewer still cannot read the check. diff --git a/docs/protocol.md b/docs/protocol.md index 815d54693..8177aad12 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -331,9 +331,11 @@ A `local` route is refused with `E_LOCAL_ONLY`, before the role and before the ceremony, because neither of them changes it. `configure` needs role `owner`. Most configure routes also need a `stepUp` -flag. A few household settings — the charging schedule today — skip the -ceremony: the session already proved who is asking, and a second Face ID is -more friction than the table-phone risk is worth. The box names those routes +flag. A few skip the ceremony: the charging schedule, FTW Cloud's grant and +statistics, and `GET /api/version/check`, which tells the app whether a newer +Core exists. The session already proved who is asking, and a second Face ID is +more friction than the table-phone risk is worth. Installing that Core +(`POST /api/version/update`) still needs the flag. The box names those routes beside the handler. The app still carries no list of tiers — it asks without the flag, and a route that still needs a ceremony answers `E_NEEDS_STEP_UP`. diff --git a/go/internal/api/api.go b/go/internal/api/api.go index 733cdbc29..f364130a3 100644 --- a/go/internal/api/api.go +++ b/go/internal/api/api.go @@ -591,7 +591,10 @@ func (s *Server) routes() { s.handle("POST /api/pv/manual_hold", Actuate, s.handlePVManualHold) s.handle("DELETE /api/pv/manual_hold", Actuate, s.handlePVManualHoldClear) s.handle("GET /api/pv/manual_hold", Read, s.handlePVManualHoldGet) - s.handle("GET /api/version/check", Configure, s.handleVersionCheck) + // Owner, since ?force=1 asks GitHub on the box's behalf. NoStepUp: a + // phone reads it to say whether a newer Core exists, and Face ID is the + // wrong cost for a question. The update itself keeps its ceremony. + s.handle("GET /api/version/check", Configure, s.handleVersionCheck, NoStepUp) s.handle("POST /api/version/channel", Configure, s.handleVersionChannel) s.handle("POST /api/version/skip", Configure, s.handleVersionSkip) s.handle("POST /api/version/unskip", Configure, s.handleVersionUnskip) diff --git a/go/internal/api/api_passthrough_test.go b/go/internal/api/api_passthrough_test.go index b893f9b19..6ab1f2964 100644 --- a/go/internal/api/api_passthrough_test.go +++ b/go/internal/api/api_passthrough_test.go @@ -379,6 +379,45 @@ func TestAnOwnerClearsAScheduleWithoutACeremony(t *testing.T) { } } +// The phone's version row reads the check without a ceremony. On a box with +// no native updater the handler itself answers, so the phone learns who +// updates FTW there rather than meeting E_NEEDS_STEP_UP. +func TestAnOwnerReadsTheVersionCheckWithoutACeremony(t *testing.T) { + rig := newAppSession(t, apiauth.RoleOwner) + rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{ + Method: appproto.APIGet, + Path: "/api/version/check", + }) + head := decode[appproto.APIHeadMsg](t, rig.frames.await(t, appproto.MsgAPIHead)) + if head.Status != http.StatusServiceUnavailable { + t.Fatalf("status = %d, want the handler's 503 for a box that does not update itself", head.Status) + } +} + +func TestTheUpdateStillNeedsTheCeremony(t *testing.T) { + rig := newAppSession(t, apiauth.RoleOwner) + rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{ + Method: appproto.APIPost, + Path: "/api/version/update", + }) + refusal := decode[appproto.ErrorBody](t, rig.frames.await(t, appproto.MsgError)) + if refusal.Code != appproto.ErrNeedsStepUp { + t.Fatalf("refusal = %+v, want E_NEEDS_STEP_UP", refusal) + } +} + +func TestAViewerCannotReadTheVersionCheck(t *testing.T) { + rig := newAppSession(t, apiauth.RoleViewer) + rig.send(t, appproto.MsgAPIReq, 1, appproto.APIReq{ + Method: appproto.APIGet, + Path: "/api/version/check", + }) + refusal := decode[appproto.ErrorBody](t, rig.frames.await(t, appproto.MsgError)) + if refusal.Code != appproto.ErrScopeDenied { + t.Fatalf("refusal = %+v, want E_SCOPE_DENIED", refusal) + } +} + func TestAViewerCannotSaveASchedule(t *testing.T) { mgr := loadpoint.NewManager() mgr.Load([]loadpoint.Config{{ID: "garage", DriverName: "easee"}}) @@ -420,6 +459,38 @@ func TestScheduleConfigureSkipsTheCeremony(t *testing.T) { } } +// A phone asks whether a newer Core exists without Face ID; installing it, +// or anything else that changes what runs, still takes the ceremony. +func TestVersionCheckSkipsTheCeremonyButTheUpdateDoesNot(t *testing.T) { + srv := New(&Deps{}) + for _, path := range []string{"/api/version/check", "/api/version/check?force=1"} { + facts := srv.Route(httptest.NewRequest(http.MethodGet, path, nil)) + if facts.Tier != apiauth.TierConfigure { + t.Fatalf("GET %s tier = %q, want configure: a viewer must not make the box ask GitHub", path, facts.Tier) + } + if !facts.NoStepUp { + t.Fatalf("GET %s still needs a ceremony; reading it must not", path) + } + } + for _, path := range []string{ + "/api/version/update", + "/api/version/channel", + "/api/version/skip", + "/api/version/unskip", + "/api/version/restart", + "/api/version/binary-rollback", + } { + facts := srv.Route(newSyntheticRequest("POST", path)) + if facts.Tier != apiauth.TierConfigure || facts.NoStepUp { + t.Fatalf("POST %s = %+v, want configure with a ceremony", path, facts) + } + } + status := srv.Route(newSyntheticRequest("GET", "/api/version/update/status")) + if status.Tier != apiauth.TierRead { + t.Fatalf("GET /api/version/update/status tier = %q, want read", status.Tier) + } +} + // -------------------------------------------------------------------------- // The second door: actuation stays on cmd // --------------------------------------------------------------------------