oficina / home Public

Require new linking authentication and explicit assertion continuation

Paul Campbell pushed by paul@keymail.dev 97660e913ddaed3ab75cc4c7a16582f89e781430 parent 2980b39
9 files changed, +111 −4
  • implementation/oficina-id-slice1-copy.md +30 −0
  • implementation/oficina-id-slice1-validation.md +14 −0
  • internal/home/app.go +1 −0
  • internal/home/assertion_fresh_test.go +2 −1
  • internal/home/exchange.go +15 −1
  • internal/home/exchange_test.go +1 −1
  • internal/home/id_exchange_test.go +40 −0
  • internal/home/signin.go +1 −1
  • internal/home/templates/id_continue.html +7 −0

CI failed — run details

diff --git a/implementation/oficina-id-slice1-copy.md b/implementation/oficina-id-slice1-copy.md
new file mode 100644
index 0000000..8417933
--- /dev/null
+++ b/implementation/oficina-id-slice1-copy.md
@@ -0,0 +1,30 @@
+# Oficina ID slice 1 copy
+
+COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13)
+
+Reviewed by GPT-6 Astra. Fixed labels only; no account-authored text.
+
+- Sign in with a passkey
+- Add a passkey to sign in without entering your email. JavaScript is needed to add and use passkeys.
+- Replace passkeys · Oficina
+- Replace your passkeys
+- Adding a replacement removes all your existing passkeys, signs you out of Oficina Home on every device, and invalidates all your recovery codes. Sign in with the new passkey before creating new recovery codes.
+- Replace all passkeys
+- Turn on JavaScript to add your replacement passkey.
+- Passkeys replaced · Oficina
+- Your passkeys were replaced
+- You are signed out of Oficina Home on every device. Your previous passkeys and recovery codes no longer work. Sign in with your new passkey to create new recovery codes.
+- Sign in with your new passkey
+- Your Oficina passkeys were replaced
+- A replacement passkey was added to your Oficina account. All previous passkeys were removed, all Oficina Home sessions were signed out, and all recovery codes were invalidated. Sign in with your new passkey to create new recovery codes.
+- Your passkeys were replaced, but we could not send the confirmation email.
+- Send email again
+- Continue to the app · Oficina
+- Continue to the app
+- Continue
+- Signed out · Oficina
+- You are signed out
+- You are signed out of Oficina Home in this browser.
+- Sign in
+- That did not work. You can try again.
+- That code did not work.
diff --git a/implementation/oficina-id-slice1-validation.md b/implementation/oficina-id-slice1-validation.md
new file mode 100644
index 0000000..fe73bee
--- /dev/null
+++ b/implementation/oficina-id-slice1-validation.md
@@ -0,0 +1,14 @@
+# Oficina ID slice 1 validation record
+
+Agent record, 2026-11-13. No deploy or merge.
+
+## Red/green
+
+- Task 1: `TestIDLinkAlwaysRequiresNewGesture` failed because GET reused a
+ recent session (200); `TestIDContinueBeforeMinting` failed because GET minted
+ immediately. Both pass after the issuance change. Existing fresh assertion,
+ Home assertion and directory exchange tests also pass.
+
+## Mutations
+
+Pending.
diff --git a/internal/home/app.go b/internal/home/app.go
index 750bb01..5901425 100644
--- a/internal/home/app.go
+++ b/internal/home/app.go
@@ -218,6 +218,7 @@ func (a *App) Router() http.Handler {
r.Get("/dashboard/authorize", a.beginDashboard)
r.With(a.sessions.Require).Get("/dashboard/resume", a.authorizeDashboard)
r.With(a.sessions.Require).Get("/authorize/resume", a.handleAssertion)
+ r.With(a.sessions.Require).Post("/authorize/resume", a.handleAssertion)
// Adding a team member by email (team-members.md §4): only
// with HOME_RESOLVE_KEY configured.
if a.runtime.resolveSigner != nil {
diff --git a/internal/home/assertion_fresh_test.go b/internal/home/assertion_fresh_test.go
index 3f789c1..3799bc7 100644
--- a/internal/home/assertion_fresh_test.go
+++ b/internal/home/assertion_fresh_test.go
@@ -74,7 +74,8 @@ func TestFreshAssertionUsesFreshSessionAndBindsOriginalPerson(t *testing.T) {
p := newExchangePair(t)
first := signInFully(t, p.credential, sealtest.CanaryAddress)
_, intent := p.startFresh(t, first)
- p.mint(t, intent, first)
+ again := signInFully(t, p.credential, sealtest.CanaryAddress)
+ p.mint(t, intent, again)
_, intent = p.startFresh(t, first)
second := signInFully(t, p.credential, "different@example.invalid")
r := exchangeRequest(p.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, second)
diff --git a/internal/home/exchange.go b/internal/home/exchange.go
index 849b692..c03817f 100644
--- a/internal/home/exchange.go
+++ b/internal/home/exchange.go
@@ -21,6 +21,8 @@ type assertionIntent struct {
Expires int64 `json:"expires"`
MaxAge int `json:"max_age,omitzero"`
Subject string `json:"subject,omitzero"`
+ Started int64 `json:"started,omitzero"`
+ Previous string `json:"previous,omitzero"`
}
func (a *App) handleAuthorize(w http.ResponseWriter, r *http.Request) {
@@ -44,6 +46,10 @@ func (a *App) handleAuthorize(w http.ResponseWriter, r *http.Request) {
}
intent := assertionIntent{Consumer: q.Get("consumer"), Nonce: q.Get("nonce"), Expires: time.Now().Unix() + 600, MaxAge: maxAge}
if maxAge != 0 {
+ intent.Started = time.Now().Unix()
+ if c, err := r.Cookie(a.sessions.CookieName()); err == nil {
+ intent.Previous = sessions.HashToken(c.Value)
+ }
if session, ok := a.sessions.From(r); ok {
intent.Subject = session.Subject
}
@@ -95,10 +101,18 @@ func (a *App) handleAssertion(w http.ResponseWriter, r *http.Request) {
a.failAssertion(w, r, assertionSubject)
return
}
- if intent.MaxAge != 0 && (!sessions.Fresh(session, time.Duration(intent.MaxAge)*time.Second, now) || authTime.After(now) || keymailWithoutGesture(session)) {
+ sameSession := false
+ if c, err := r.Cookie(a.sessions.CookieName()); err == nil {
+ sameSession = intent.Previous != "" && sessions.HashToken(c.Value) == intent.Previous
+ }
+ if intent.MaxAge != 0 && (sameSession || (intent.Started != 0 && authTime.Unix() < intent.Started) || !sessions.Fresh(session, time.Duration(intent.MaxAge)*time.Second, now) || authTime.After(now) || keymailWithoutGesture(session)) {
http.Redirect(w, r, "/signin?return_to=%2Fauthorize%2Fresume", http.StatusSeeOther)
return
}
+ if r.Method == http.MethodGet {
+ a.render(w, r, http.StatusOK, "id_continue.html", nil)
+ return
+ }
id, err := assertion.RandomID()
if err != nil {
a.failAssertion(w, r, assertionRandom)
diff --git a/internal/home/exchange_test.go b/internal/home/exchange_test.go
index 7569860..2e0046c 100644
--- a/internal/home/exchange_test.go
+++ b/internal/home/exchange_test.go
@@ -115,7 +115,7 @@ func (p exchangePair) start(t *testing.T) (*http.Cookie, *http.Cookie) {
}
func (p exchangePair) mint(t *testing.T, intent, session *http.Cookie) (string, *httptest.ResponseRecorder) {
t.Helper()
- rec := exchangeRequest(p.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, session)
+ rec := exchangeRequest(p.credential.App, "POST", Origin+"/authorize/resume", Origin, nil, intent, session)
if rec.Code != 200 {
t.Fatal("mint", rec.Code)
}
diff --git a/internal/home/id_exchange_test.go b/internal/home/id_exchange_test.go
new file mode 100644
index 0000000..d6a11ad
--- /dev/null
+++ b/internal/home/id_exchange_test.go
@@ -0,0 +1,40 @@
+package home
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/home/internal/home/sealtest"
+)
+
+func TestIDLinkAlwaysRequiresNewGesture(t *testing.T) {
+ p := newExchangePair(t)
+ session := signInFully(t, p.credential, sealtest.CanaryAddress)
+ _, intent := p.startFresh(t, session)
+ for _, method := range []string{"GET", "POST"} {
+ r := exchangeRequest(p.credential.App, method, Origin+"/authorize/resume", Origin, nil, intent, session)
+ if r.Code != http.StatusSeeOther || !strings.HasPrefix(r.Header().Get("Location"), "/signin?") {
+ t.Fatalf("%s reused existing session: %d", method, r.Code)
+ }
+ }
+}
+
+func TestIDContinueBeforeMinting(t *testing.T) {
+ p := newExchangePair(t)
+ session := signInFully(t, p.credential, sealtest.CanaryAddress)
+ _, intent := p.start(t)
+ r := exchangeRequest(p.credential.App, "GET", Origin+"/authorize/resume", "", nil, intent, session)
+ if r.Code != 200 || strings.Contains(r.Body.String(), `name="assertion"`) || !strings.Contains(r.Body.String(), `action="/authorize/resume"`) {
+ t.Fatal("GET did not stop at Continue", r.Code)
+ }
+ bad := exchangeRequest(p.credential.App, "POST", Origin+"/authorize/resume", "https://evil.invalid", url.Values{}, intent, session)
+ if bad.Code != 403 {
+ t.Fatal("Continue lacks CSRF protection", bad.Code)
+ }
+ good := exchangeRequest(p.credential.App, "POST", Origin+"/authorize/resume", Origin, url.Values{}, intent, session)
+ if good.Code != 200 || !strings.Contains(good.Body.String(), `name="assertion"`) {
+ t.Fatal("Continue did not mint", good.Code)
+ }
+}
diff --git a/internal/home/signin.go b/internal/home/signin.go
index 61ff83c..b757edd 100644
--- a/internal/home/signin.go
+++ b/internal/home/signin.go
@@ -354,7 +354,7 @@ func (a *App) handleCallback(w http.ResponseWriter, r *http.Request) {
// clock, so a standing Keymail approval would pass as fresh.
now := time.Now()
if intent, ok := a.readAssertionIntent(r, now); ok && intent.MaxAge != 0 &&
- !freshGesture(id.AuthTime, now, time.Duration(intent.MaxAge)*time.Second) {
+ (!freshGesture(id.AuthTime, now, time.Duration(intent.MaxAge)*time.Second) || (intent.Started != 0 && id.AuthTime.Unix() < intent.Started)) {
http.Redirect(w, r, "/signin?force=1", http.StatusSeeOther)
return
}
diff --git a/internal/home/templates/id_continue.html b/internal/home/templates/id_continue.html
new file mode 100644
index 0000000..90e4f07
--- /dev/null
+++ b/internal/home/templates/id_continue.html
@@ -0,0 +1,7 @@
+{{define "title"}}Continue to the app · Oficina{{end}}
+{{define "content"}}
+<h1>Continue to the app</h1>
+<form method="post" action="/authorize/resume" rst-form>
+<button type="submit" rst-btn="primary">Continue</button>
+</form>
+{{end}}