oficina / home Public

connect: IsHomeDerived and the 7-day absolute limit for native sessions

Human

Prompt

Implement the consumer (connect) half of slice A: IsHomeDerived, the 7-day limit (spec 2026-11-14 §7).

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

One predicate for Home-derived session methods (home-assertion, home-assertion-native, home-native-web) replaces the literal HomeMethod checks in finish, existingPerson and signedIn; Expired refuses native and native-web sessions 7 days after At (absolute) or with no At. Requires handoff at c43a910 for the native exchange that follows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c99b3ff108a71930feb452ab4270c0e7d987ed3b parent c43a910
7 files changed, +134 −13
  • connect/api.go +40 −0
  • connect/bridge.go +5 −2
  • connect/derived_test.go +77 −0
  • connect/go.mod +1 −1
  • connect/go.sum +2 −0
  • connect/routes.go +8 −9
  • connect/routes_test.go +1 −1
diff --git a/connect/api.go b/connect/api.go
index ad33166..43798a8 100644
--- a/connect/api.go
+++ b/connect/api.go
@@ -14,6 +14,46 @@ import (
const HomeMethod = "home-assertion"
+// NativeMethod is a session minted by NativeExchange for a native app, from
+// an assertion Home made for a device grant (Home spec
+// 2026-11-14-oficina-id-native.md §7). NativeWebMethod is the browser
+// session "Open on the web" mints (§12, slice D); connect does not mint it
+// yet, but resolves and ages it like any Home-derived session.
+const (
+ NativeMethod = "home-assertion-native"
+ NativeWebMethod = "home-native-web"
+)
+
+// NativeLifetime is how long after its creation (Session.At) connect accepts
+// a NativeMethod or NativeWebMethod session: absolute, never sliding (Paul,
+// 2026-11-14). The app re-mints after a day and on any 401; this bounds what
+// an offline device keeps after its grant is revoked.
+const NativeLifetime = 7 * 24 * time.Hour
+
+// IsHomeDerived reports whether a session method names a person by their
+// Home subject: a browser sign-in through Home, a native exchange, or a
+// native-to-web handoff. Every check that used to compare a method with
+// HomeMethod asks this instead, so the three are one kind of session.
+func IsHomeDerived(method string) bool {
+ switch method {
+ case HomeMethod, NativeMethod, NativeWebMethod:
+ return true
+ }
+ return false
+}
+
+// Expired reports whether connect refuses a session by its age: a native or
+// native-web session more than NativeLifetime after its At, or one with no
+// At at all (fail closed). Browser and local sessions keep the session
+// store's own expiry. Apps that resolve sessions themselves, rather than
+// through ResolveSession, must refuse what this refuses.
+func Expired(s Session, now time.Time) bool {
+ if s.Method != NativeMethod && s.Method != NativeWebMethod {
+ return false
+ }
+ return s.At.IsZero() || s.At.After(now.Add(time.Minute)) || now.Sub(s.At) > NativeLifetime
+}
+
// Session times must come from the verified stored session, never request or last-seen time.
// AuthTime is the method verification time; At is immutable session creation time.
type Session struct {
diff --git a/connect/bridge.go b/connect/bridge.go
index e35e5f5..3c0fd9b 100644
--- a/connect/bridge.go
+++ b/connect/bridge.go
@@ -72,7 +72,7 @@ func New(c Config) (*Bridge, error) {
b := &Bridge{namespace: c.Namespace, keyHash: sha256.Sum256(c.DEK), origin: c.Origin, issuer: c.Issuer, sessionCookie: c.SessionCookie, links: linker, now: now, returnPath: c.ReturnPath, readSession: c.ReadSession, mintSession: c.MintHomeSession, localPerson: c.LookupLocalSession, render: c.Render, unlinked: c.Unlinked, homeOnly: c.HomeOnly}
cfg := handoff.ConsumerConfig{Store: exchange, ConsumerID: c.ConsumerID, Complete: b.complete, Fail: b.fail, Now: func() time.Time { return b.now() }, CurrentSubject: func(r *http.Request) string {
result, _ := r.Context().Value(homeFinishKey{}).(*homeFinishResult)
- if result != nil && result.session != nil && result.session.Method == HomeMethod {
+ if result != nil && result.session != nil && IsHomeDerived(result.session.Method) {
return result.session.Subject
}
return ""
@@ -248,7 +248,10 @@ func (b *Bridge) complete(w http.ResponseWriter, r *http.Request, claims asserti
// existingPerson never creates a person or samples, even during ordinary SSO.
func (b *Bridge) existingPerson(r *http.Request, session Session) (Person, error) {
- if session.Method == HomeMethod {
+ if IsHomeDerived(session.Method) {
+ if Expired(session, b.now()) {
+ return Person{}, errIdentityRefused
+ }
return b.Resolve(r.Context(), session.Subject)
}
if session.Method != "magiclink" && session.Method != "keymail" {
diff --git a/connect/derived_test.go b/connect/derived_test.go
new file mode 100644
index 0000000..8b68ff4
--- /dev/null
+++ b/connect/derived_test.go
@@ -0,0 +1,77 @@
+package connect
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+ "time"
+)
+
+func TestIsHomeDerivedIsExactlyTheThreeHomeMethods(t *testing.T) {
+ for method, want := range map[string]bool{
+ HomeMethod: true, NativeMethod: true, NativeWebMethod: true,
+ "magiclink": false, "keymail": false, "guest": false, "": false,
+ "home-assertion-native ": false, "Home-Assertion": false,
+ } {
+ if IsHomeDerived(method) != want {
+ t.Errorf("IsHomeDerived(%q) = %v", method, !want)
+ }
+ }
+}
+
+func TestExpiredIsSevenDaysAbsoluteForNativeSessions(t *testing.T) {
+ now := time.Unix(1_800_000_000, 0)
+ for _, c := range []struct {
+ method string
+ at time.Time
+ want bool
+ }{
+ {NativeMethod, now.Add(-NativeLifetime), false},
+ {NativeMethod, now.Add(-NativeLifetime - time.Second), true},
+ {NativeWebMethod, now.Add(-NativeLifetime - time.Second), true},
+ {NativeMethod, time.Time{}, true},
+ {NativeMethod, now.Add(time.Hour), true},
+ // A browser or local session keeps the session store's own expiry.
+ {HomeMethod, now.Add(-30 * 24 * time.Hour), false},
+ {"magiclink", time.Time{}, false},
+ } {
+ if got := Expired(Session{Subject: "pr_x", Method: c.method, At: c.at}, now); got != c.want {
+ t.Errorf("Expired(%s, at %v) = %v", c.method, now.Sub(c.at), got)
+ }
+ }
+}
+
+// A native session resolves, signs in and holds the same-person rules like a
+// Home one, until seven days after it was minted, however recently used.
+func TestNativeSessionResolvesUntilSevenDays(t *testing.T) {
+ f, h := newHomeOnlyFixture(t)
+ if _, err := h.db.Exec("INSERT INTO home_only(issuer,subject) VALUES(?,?)", bridgeIssuer, "pr_member"); err != nil {
+ t.Fatal(err)
+ }
+ token, err := f.sessions.Mint(Session{Subject: "pr_member", Method: NativeMethod, AuthTime: time.Now().Add(-time.Minute)})
+ if err != nil {
+ t.Fatal(err)
+ }
+ cookie := &http.Cookie{Name: f.b.sessionCookie, Value: token}
+ if p, err := f.b.ResolveSession(bridgeRequest(http.MethodGet, "/", []*http.Cookie{cookie})); err != nil || p.ID <= 1000 {
+ t.Fatalf("native session did not resolve: %+v %v", p, err)
+ }
+ routes := f.routes(t)
+ w := httptest.NewRecorder()
+ routes.Signin(w, bridgeRequest(http.MethodGet, "/signin?return_to=%2Fd%2Fx", []*http.Cookie{cookie}))
+ if w.Code != 303 || w.Header().Get("Location") != "/d/x" {
+ t.Fatalf("a live native session is not signed in: %d %q", w.Code, w.Header().Get("Location"))
+ }
+
+ s := f.sessions.values[token]
+ s.At = time.Now().Add(-NativeLifetime - time.Minute)
+ f.sessions.values[token] = s
+ if _, err := f.b.ResolveSession(bridgeRequest(http.MethodGet, "/", []*http.Cookie{cookie})); err == nil {
+ t.Fatal("a native session resolved after seven days")
+ }
+ w = httptest.NewRecorder()
+ routes.Signin(w, bridgeRequest(http.MethodGet, "/signin?return_to=%2Fd%2Fx", []*http.Cookie{cookie}))
+ if w.Header().Get("Location") == "/d/x" {
+ t.Fatal("an expired native session counted as signed in")
+ }
+}
diff --git a/connect/go.mod b/connect/go.mod
index 7d92eac..3588735 100644
--- a/connect/go.mod
+++ b/connect/go.mod
@@ -4,7 +4,7 @@ go 1.25.0
require (
amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d
- amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
+ amadan.net/oficina/home/handoff v0.0.0-20261114095655-c43a9100faf0
amadan.net/rastrillo/rastrillo v0.26.1-0.20260908075707-29e4491631bd
github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2
modernc.org/sqlite v1.55.0
diff --git a/connect/go.sum b/connect/go.sum
index 067fbd4..31ea037 100644
--- a/connect/go.sum
+++ b/connect/go.sum
@@ -2,6 +2,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s
amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM=
amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
+amadan.net/oficina/home/handoff v0.0.0-20261114095655-c43a9100faf0 h1:DTpsiobE852SQDorghPVYRIrDI9DA5r/8BHNosBCM54=
+amadan.net/oficina/home/handoff v0.0.0-20261114095655-c43a9100faf0/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
amadan.net/rastrillo/rastrillo v0.26.1-0.20260908075707-29e4491631bd h1:jlFSt95M1ontOg+VePU+kIJpChtWqDQAbnmlxqCnbgc=
amadan.net/rastrillo/rastrillo v0.26.1-0.20260908075707-29e4491631bd/go.mod h1:RpyHVPD0udcSfHJroY0KZE/FUjgw6Tvfo8SJm2qeZGE=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
diff --git a/connect/routes.go b/connect/routes.go
index a3ef883..be81f15 100644
--- a/connect/routes.go
+++ b/connect/routes.go
@@ -131,11 +131,11 @@ func (h *Routes) Signin(w http.ResponseWriter, r *http.Request) {
// signedIn reports a live, signed-in app session: exactly one session
// cookie, which ReadSession resolves to a person who signed in, through
-// Home (HomeMethod) or a local link (magiclink, keymail). An ambiguous
-// pair or a revoked cookie is not one, and neither is any other method:
-// Calls' anonymous per-meeting guests ("guest") are sessions but not
-// sign-ins, and sending one to the root instead of the exchange ends on a
-// 404 (the #74 review, finding 3). An unknown method falls back to the
+// Home (IsHomeDerived and not Expired) or a local link (magiclink,
+// keymail). An ambiguous pair or a revoked cookie is not one, and neither
+// is any other method: Calls' anonymous per-meeting guests ("guest") are
+// sessions but not sign-ins, and sending one to the root instead of the
+// exchange ends on a 404 (the #74 review, finding 3). An unknown method falls back to the
// exchange, which is what /signin did before this check existed.
func (h *Routes) signedIn(r *http.Request) bool {
if cookieCount(r, h.cfg.SessionCookie) != 1 {
@@ -145,11 +145,10 @@ func (h *Routes) signedIn(r *http.Request) bool {
if err != nil || s == nil || s.Subject == "" {
return false
}
- switch s.Method {
- case HomeMethod, "magiclink", "keymail":
- return true
+ if IsHomeDerived(s.Method) {
+ return !Expired(*s, h.bridge.now())
}
- return false
+ return s.Method == "magiclink" || s.Method == "keymail"
}
func (h *Routes) SignedOut(w http.ResponseWriter, r *http.Request) {
diff --git a/connect/routes_test.go b/connect/routes_test.go
index 2c7fc26..ce2a9ef 100644
--- a/connect/routes_test.go
+++ b/connect/routes_test.go
@@ -124,7 +124,7 @@ func assertSignoutCleared(t *testing.T, w *httptest.ResponseRecorder) {
func TestSigninWhenAlreadySignedIn(t *testing.T) {
_, n := navigationFixture(t)
locals := 0
- h := &Routes{bridge: &Bridge{render: func(w http.ResponseWriter, r *http.Request, state, label string, status int) { w.WriteHeader(status) }}, navigation: n, cfg: RoutesConfig{Origin: navigationOrigin, SessionCookie: "__Host-rastrillo_session", ReadSession: func(r *http.Request) (*Session, error) {
+ h := &Routes{bridge: &Bridge{now: time.Now, render: func(w http.ResponseWriter, r *http.Request, state, label string, status int) { w.WriteHeader(status) }}, navigation: n, cfg: RoutesConfig{Origin: navigationOrigin, SessionCookie: "__Host-rastrillo_session", ReadSession: func(r *http.Request) (*Session, error) {
c, err := r.Cookie("__Host-rastrillo_session")
if err != nil || (c.Value != "verified" && c.Value != "guest") {
return nil, nil