oficina / base Public

Recognise native Oficina ID sessions; bump connect to Home main

Bumps amadan.net/oficina/home/connect and handoff to Home 8125a3c, which
carries the native exchange (and, by minimum version selection, rastrillo
v0.38.0 and estilo 487cadb). rastrillo's default CSP gained the hash for
auth's fallback confirm page, so formPolicy follows it.

requireMember, ownSignInOnly and Settings now ask connect.IsHomeDerived
instead of comparing with HomeMethod, so a native session (NativeMethod)
counts as an Oficina sign-in everywhere a browser one does. memberFor
refuses a native session seven days after it was minted (connect.Expired)
before resolving it.

make ci: 16 packages ran, 0 failed; test step 13.5s of 60s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev c9c963f9f3dc268e13d142de349f57de3983024d parent 33633a5
6 files changed, +138 −23
  • go.mod +5 −4
  • go.sum +10 −8
  • internal/web/app.go +13 −9
  • internal/web/oficina.go +2 −1
  • internal/web/settings.go +1 −1
  • internal/webtest/native_test.go +107 −0
diff --git a/go.mod b/go.mod
index 960db01..d416e8a 100644
--- a/go.mod
+++ b/go.mod
@@ -3,16 +3,17 @@ module amadan.net/carlos/base
go 1.26.0
require (
- amadan.net/oficina/home/connect v0.0.0-20261110233753-14c83d71b992
- amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
- amadan.net/rastrillo/rastrillo v0.33.0
+ amadan.net/oficina/home/connect v0.0.0-20261122210203-8125a3ca6735
+ amadan.net/oficina/home/handoff v0.0.0-20261122210203-8125a3ca6735
+ amadan.net/rastrillo/rastrillo v0.38.0
github.com/chromedp/cdproto v0.158.6
github.com/chromedp/chromedp v0.21.0
github.com/go-chi/chi/v5 v5.3.2
)
require (
- amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d // indirect
+ amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88 // indirect
+ amadan.net/rastrillo/fiesta v1.5.0 // indirect
amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
diff --git a/go.sum b/go.sum
index 77b68c1..cff6f08 100644
--- a/go.sum
+++ b/go.sum
@@ -1,11 +1,13 @@
-amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s1viTINgQ6XoDD5ghOxYubD7FNcjhBTw=
-amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
-amadan.net/oficina/home/connect v0.0.0-20261110233753-14c83d71b992 h1:pyAvFStnIR6D/MSfMYpRQG+Lete8eYCF10nBdjtBbhA=
-amadan.net/oficina/home/connect v0.0.0-20261110233753-14c83d71b992/go.mod h1:7tsJ//7X4o5QkD068WoUGVDxj/e3ygZ2adF+PHhvBxE=
-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/rastrillo/rastrillo v0.33.0 h1:aYK33p7SIKOglr6rZM3EQLXdpz02Rnq9NB4Zhitz5yw=
-amadan.net/rastrillo/rastrillo v0.33.0/go.mod h1:IQnXick/ERWFvhqiQey87Zw1Td2aHlyloykFQB0g0pI=
+amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88 h1:wqpT3PmQQajULdOhtjJ/yENvdVB/NFG0QM7jlaEPS8s=
+amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8=
+amadan.net/oficina/home/connect v0.0.0-20261122210203-8125a3ca6735 h1:l2F7i47Y90p6BEnbvd354nh2r4+DWSpojiYh6k6Ye7s=
+amadan.net/oficina/home/connect v0.0.0-20261122210203-8125a3ca6735/go.mod h1:B45bHBZF5AtFJqy4d1qSDNDOqYcNkSz1qD20TLF1DI8=
+amadan.net/oficina/home/handoff v0.0.0-20261122210203-8125a3ca6735 h1:tWr0Xx1BpWNx/q/Bvbqdjj2PLX32YAiOuN8B51XZ9Vw=
+amadan.net/oficina/home/handoff v0.0.0-20261122210203-8125a3ca6735/go.mod h1:Mn5Rsm7Vcd6VZArBKMawza2yO+Fjo8KB1Ii6UcjcJHQ=
+amadan.net/rastrillo/fiesta v1.5.0 h1:wKfTsL5zRMofJBAqOxNlCY7aCtgHCtfwvTPBMA+ZA20=
+amadan.net/rastrillo/fiesta v1.5.0/go.mod h1:LpO391W1dIRUxOIKklHm+bGyWXtlFyBRRPQCysb9LjY=
+amadan.net/rastrillo/rastrillo v0.38.0 h1:q8aPnVtKt4q+uNjfxBRCTizhVvj+HdjDJh1MhlkBPOc=
+amadan.net/rastrillo/rastrillo v0.38.0/go.mod h1:0bufVMz8D4aWvxvJjehW70T8Jsvytrp1YEwoIzFTKm8=
amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM=
amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
diff --git a/internal/web/app.go b/internal/web/app.go
index 16fb289..d1f5439 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -288,10 +288,14 @@ func (a *app) requireMember(next http.Handler) http.Handler {
// memberFor is the member behind session s. found is false for a session
// that names nobody who is a member now.
func (a *app) memberFor(r *http.Request, s sessions.Session) (m store.Member, found bool, err error) {
- if s.Method == connect.HomeMethod {
- if a.oficina == nil {
- // Left over from when Oficina ID was on: it names an Oficina
- // account, never an address.
+ if connect.IsHomeDerived(s.Method) {
+ // A browser, native or native-to-web sign-in through Oficina. The
+ // native kinds end seven days after they were minted, however
+ // recently used; connect's ResolveSession refuses them too, but
+ // the age is checked here first so no path forgets it.
+ if a.oficina == nil || connect.Expired(connect.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime, At: s.At}, time.Now()) {
+ // Without Oficina ID on, one left over from when it was names
+ // an Oficina account, never an address.
return store.Member{}, false, nil
}
return a.oficina.member(r)
@@ -299,13 +303,13 @@ func (a *app) memberFor(r *http.Request, s sessions.Session) (m store.Member, fo
return store.MemberByEmail(r.Context(), a.db, s.Subject)
}
-// ownSignInOnly refuses a request whose session came from Oficina ID. A
-// passkey is filed under the session's subject, which for an Oficina session
-// is the Oficina account, not the member's address: a passkey added there
-// could never sign the member in.
+// ownSignInOnly refuses a request whose session came from Oficina ID, in a
+// browser or the native app. A passkey is filed under the session's subject,
+// which for an Oficina session is the Oficina account, not the member's
+// address: a passkey added there could never sign the member in.
func ownSignInOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if s, ok := sessions.Current(r); !ok || s.Method == connect.HomeMethod {
+ if s, ok := sessions.Current(r); !ok || connect.IsHomeDerived(s.Method) {
http.Error(w, "forbidden", http.StatusForbidden)
return
}
diff --git a/internal/web/oficina.go b/internal/web/oficina.go
index efdee32..97d77f9 100644
--- a/internal/web/oficina.go
+++ b/internal/web/oficina.go
@@ -93,7 +93,8 @@ func (a *app) newOficina(home *connect.DecodedCredentials) (*oficina, error) {
// TestFormPolicyIsRastrillosWithTheIssuer keeps the two in step.
func formPolicy(issuer string) string {
return "default-src 'self'; " +
- "style-src 'self' 'unsafe-hashes' 'sha256-yJxAE4rjdcckohdlnvecSporPcqS9xOaA4hJxi87LMc='; " +
+ "style-src 'self' 'unsafe-hashes' 'sha256-yJxAE4rjdcckohdlnvecSporPcqS9xOaA4hJxi87LMc=' " +
+ "'sha256-81gZUb3tp60YCqhJ0dItBPh5hRQiGbfst4gpwCNPTfI='; " +
"img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self' " + issuer
}
diff --git a/internal/web/settings.go b/internal/web/settings.go
index 46771f7..045c1f7 100644
--- a/internal/web/settings.go
+++ b/internal/web/settings.go
@@ -50,7 +50,7 @@ var appearances = []struct{ value, label, stored string }{
func (a *app) settings(w http.ResponseWriter, r *http.Request) {
me, _ := CurrentMember(r)
s, _ := sessions.Current(r)
- viaOficina := s.Method == connect.HomeMethod
+ viaOficina := connect.IsHomeDerived(s.Method)
// Passkeys are filed under the address a member signs in with, which an
// Oficina session's subject is not.
subject := s.Subject
diff --git a/internal/webtest/native_test.go b/internal/webtest/native_test.go
new file mode 100644
index 0000000..42d3440
--- /dev/null
+++ b/internal/webtest/native_test.go
@@ -0,0 +1,107 @@
+package webtest
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/home/connect"
+ "amadan.net/rastrillo/rastrillo/sessions"
+)
+
+// The native app's Oficina ID session (Home spec 2026-11-14-oficina-id-native.md
+// §7): connect's NativeMethod, minted without a browser and handed to the
+// app, which sends it as the session cookie with Origin set to Base's own.
+
+// sessionCookie is the name of Base's session cookie at homeOrigin.
+const sessionCookie = "__Host-rastrillo_session"
+
+// storedSession writes a session row as rastrillo's store would have,
+// created at, and returns a browser carrying its cookie. It stands in for a
+// session minted some time ago.
+func (a *testApp) storedSession(subject, method string, at time.Time) *testApp {
+ a.t.Helper()
+ token, hash, err := sessions.NewToken()
+ if err != nil {
+ a.t.Fatal(err)
+ }
+ if _, err := a.DB.Exec(`INSERT INTO sessions (token_hash, subject, method, auth_time, created_at, expires_at) VALUES (?, ?, ?, ?, ?, ?)`,
+ hash, subject, method, at.UTC().Format(time.RFC3339), at.UTC().Format(time.RFC3339), time.Now().Add(30*24*time.Hour).UTC().Format(time.RFC3339)); err != nil {
+ a.t.Fatal(err)
+ }
+ return a.withSession(token)
+}
+
+// withSession is a fresh browser that holds only the session token, as the
+// native app does: it sends the cookie itself.
+func (a *testApp) withSession(token string) *testApp {
+ a.t.Helper()
+ b := a.newBrowser()
+ u, _ := url.Parse(homeOrigin + "/")
+ b.client.Jar.SetCookies(u, []*http.Cookie{{Name: sessionCookie, Value: token, Path: "/", Secure: true, HttpOnly: true}})
+ return b
+}
+
+// nativePost is a JSON POST as the native app makes it.
+func (a *testApp) nativePost(target, body string) Resp {
+ a.t.Helper()
+ req, _ := http.NewRequest(http.MethodPost, a.base+target, strings.NewReader(body))
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Set("Origin", homeOrigin)
+ req.Header.Set("Accept", "application/json")
+ return a.do(req)
+}
+
+func TestNativeSessionIsAMember(t *testing.T) {
+ a := newHomeApp(t)
+ a.link(ownerAddress, "subject-owner")
+ b := a.storedSession("subject-owner", connect.NativeMethod, time.Now().Add(-time.Hour))
+ if r := b.get("/"); r.Code != 200 {
+ t.Fatalf("native session, GET /: %d %q", r.Code, r.Location())
+ }
+ if r := b.get("/settings"); r.Code != 200 || !strings.Contains(r.Body, ownerAddress) {
+ t.Fatalf("native session, GET /settings: %d", r.Code)
+ }
+ // A subject with no link names nobody.
+ if r := a.storedSession("subject-stranger", connect.NativeMethod, time.Now()).get("/"); r.Code != http.StatusForbidden {
+ t.Errorf("unlinked native session, GET /: %d", r.Code)
+ }
+}
+
+// Seven days after it was minted, however recently used, the native session
+// opens nothing (connect.Expired): the app mints a new one long before.
+func TestNativeSessionExpiresAfterSevenDays(t *testing.T) {
+ a := newHomeApp(t)
+ a.link(ownerAddress, "subject-owner")
+ if r := a.storedSession("subject-owner", connect.NativeMethod, time.Now().Add(-connect.NativeLifetime+time.Minute)).get("/"); r.Code != 200 {
+ t.Fatalf("a native session just short of seven days: %d", r.Code)
+ }
+ old := a.storedSession("subject-owner", connect.NativeMethod, time.Now().Add(-connect.NativeLifetime-time.Second))
+ for _, p := range []string{"/", "/settings"} {
+ if r := old.get(p); r.Code == 200 {
+ t.Errorf("a native session past seven days, GET %s: %d", p, r.Code)
+ }
+ }
+ // A browser Home session of the same age is the store's to expire.
+ if r := a.storedSession("subject-owner", connect.HomeMethod, time.Now().Add(-connect.NativeLifetime-time.Hour)).get("/"); r.Code != 200 {
+ t.Errorf("a browser Oficina session of eight days: %d", r.Code)
+ }
+}
+
+// A passkey is filed under the session's subject; for every Home-derived
+// session that is the Oficina account, so none may add one.
+func TestOwnSignInOnlyRefusesNativeSessions(t *testing.T) {
+ a := newHomeApp(t)
+ a.link(ownerAddress, "subject-owner")
+ b := a.storedSession("subject-owner", connect.NativeMethod, time.Now())
+ if r := b.nativePost("/passkey/register/begin", "{}"); r.Code != http.StatusForbidden {
+ t.Errorf("register from a native session: %d", r.Code)
+ }
+ // Settings offers no passkey to a native session, and lists the
+ // member's own by address.
+ if body := b.get("/settings").Body; strings.Contains(body, "data-passkey-add") {
+ t.Errorf("settings offers a passkey to a native session")
+ }
+}