oficina / home Public

Review fixes: Serve's framework routes off, estilo main 487cadb, guards

From Fable's review of a12bb38 (APPROVE AFTER FIXES):

- rastrillo.Serve at v0.38.0 mounts POST /_theme (a non-__Host-
  rastrillo_scheme cookie) and GET /_speculation-rules, and puts a
  Speculation-Rules header on every response, outside Home's router.
  home.ServeOptions, which cmd/home now hands Serve, sets NoSchemeSwitch
  and NoSpeculationRules. TestServeAddsNoFrameworkRoutes builds the
  handler Serve runs (rastrillo.Handler) and checks both origins, with
  a control that turns them back on. TestAppUsesReviewedCSP follows the
  policy into ServeOptions.
- estilo re-pinned to main 487cadb in the root, connect and teammode.
- TestIDRegistrationRefusesWithoutUserVerification: a UV-less
  attestation to /passkey/register/finish is refused and stores no
  credential; the same ceremony with UV is the control.
- TestRendererClonesPerPage: each page's door and hop, and its own
  layout and content, after the clone.
- The unused passkey.Handlers is gone; passkeyCfg stays as the record
  the RP-ID guard reads. guardstest's TestHomeNeverMountsFrameworkSignin
  fails on a direct import of auth, lastsignin or secondfactor, or a
  passkey.New / passkey.Handlers, in production code.
- home.OpenDatabase carries DurableCommits; TestOpenDatabaseCommitsDurably
  reads PRAGMA synchronous = 2 on writer and reader, with db.Open's
  NORMAL default as the control.
- AGENTS.md: direct imports only (passkey links lastsignin and
  secondfactor), the Serve options, the new tests, the estilo pin.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 732759469c717bbd141f37017d000fecc11a96ef parent a12bb38
18 files changed, +442 −48
  • AGENTS.md +27 −8
  • cmd/home/main.go +5 −12
  • connect/go.mod +1 −1
  • connect/go.sum +2 −2
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/guardstest/framework_signin_test.go +89 −0
  • internal/home/app.go +6 −7
  • internal/home/id_passkey_test.go +31 −0
  • internal/home/noscript_test.go +18 −4
  • internal/home/opendb.go +24 −0
  • internal/home/opendb_test.go +45 −0
  • internal/home/passkey.go +2 −8
  • internal/home/render_test.go +66 −0
  • internal/home/serveopts.go +29 −0
  • internal/home/serveopts_test.go +91 −0
  • teammode/go.mod +1 −1
  • teammode/go.sum +2 −2

CI passed — run details

CI log
amadan: .amadan/timeout: this job's budget is 20m0s (this runner allows up to 30m0s)
=== vet ===
CGO_ENABLED=0 go vet ./...
CGO_ENABLED=0 go vet -tags browser ./internal/home/
cd handoff && CGO_ENABLED=0 go vet ./...
cd roster && CGO_ENABLED=0 go vet ./...
cd dashboard && CGO_ENABLED=0 go vet ./...
cd connect && CGO_ENABLED=0 go vet ./...
cd teammode && CGO_ENABLED=0 go vet ./...
=== fmt ===
=== build ===
CGO_ENABLED=0 go build ./...
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ./cmd/home ./cmd/oficina ./internal/operatorlaunch
cd handoff && CGO_ENABLED=0 go build ./...
cd roster && CGO_ENABLED=0 go build ./...
cd dashboard && CGO_ENABLED=0 go build ./...
cd connect && CGO_ENABLED=0 go build ./...
cd teammode && CGO_ENABLED=0 go build ./...
=== go-test ===
CGO_ENABLED=0 go test -count=1 ./...
?   	amadan.net/oficina/home/cmd/home	[no test files]
ok  	amadan.net/oficina/home/cmd/home-placeholder	0.702s
?   	amadan.net/oficina/home/cmd/oficina	[no test files]
ok  	amadan.net/oficina/home/internal/guardstest	0.100s
ok  	amadan.net/oficina/home/internal/home	51.622s
ok  	amadan.net/oficina/home/internal/home/directorydata	1.376s
ok  	amadan.net/oficina/home/internal/home/logtest	0.004s
ok  	amadan.net/oficina/home/internal/home/seal	0.002s
ok  	amadan.net/oficina/home/internal/home/sealtest	0.003s
ok  	amadan.net/oficina/home/internal/home/wisp	0.044s
ok  	amadan.net/oficina/home/internal/operator	6.471s
ok  	amadan.net/oficina/home/internal/operatorlaunch	4.127s
ok  	amadan.net/oficina/home/internal/provisioner	48.665s
cd handoff && CGO_ENABLED=0 go test -count=1 ./...
ok  	amadan.net/oficina/home/handoff	0.663s
ok  	amadan.net/oficina/home/handoff/seal	0.002s
cd roster && CGO_ENABLED=0 go test -count=1 ./...
ok  	amadan.net/oficina/home/roster	5.122s
cd dashboard && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/dashboard	(cached)
cd connect && CGO_ENABLED=0 go test -count=1 ./...
ok  	amadan.net/oficina/home/connect	1.345s
ok  	amadan.net/oficina/home/connect/linkstore	0.527s
cd teammode && CGO_ENABLED=0 go test -count=1 ./...
ok  	amadan.net/oficina/home/teammode	0.100s
?   	amadan.net/oficina/home/teammode/teammodetest	[no test files]
=== race ===
go test -race -count=1 ./internal/home/ ./internal/operator/ ./internal/operatorlaunch/ ./internal/home/directorydata/
ok  	amadan.net/oficina/home/internal/home	319.156s
ok  	amadan.net/oficina/home/internal/operator	82.751s
ok  	amadan.net/oficina/home/internal/operatorlaunch	22.395s
ok  	amadan.net/oficina/home/internal/home/directorydata	23.594s
ok  	amadan.net/oficina/home/internal/provisioner	398.187s
cd handoff && CGO_ENABLED=1 go test -race -count=1 ./...
ok  	amadan.net/oficina/home/handoff	12.823s
ok  	amadan.net/oficina/home/handoff/seal	1.013s
cd roster && CGO_ENABLED=1 go test -race -count=1 ./...
ok  	amadan.net/oficina/home/roster	6.963s
cd dashboard && CGO_ENABLED=1 go test -race -count=1 ./...
ok  	amadan.net/oficina/home/dashboard	1.064s
cd connect && CGO_ENABLED=1 go test -race -count=1 ./...
ok  	amadan.net/oficina/home/connect	5.997s
ok  	amadan.net/oficina/home/connect/linkstore	6.503s
cd teammode && CGO_ENABLED=1 go test -race -count=1 ./...
ok  	amadan.net/oficina/home/teammode	1.961s
?   	amadan.net/oficina/home/teammode/teammodetest	[no test files]
diff --git a/AGENTS.md b/AGENTS.md
index a60dc95..24e2c73 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -354,8 +354,9 @@ quietly ignored).
itself on the `passkey_recovery_codes` table `passkey.Schema` still
creates, and `secondfactor.Schema` must never be merged (it copies
those codes out and drops the table). `webauthn.Config.Register`
- stopped requiring user verification, so Home refuses a registration
- without it (`TestIDReplacementProofBinding`). `passkey.Schema` gained
+ stopped requiring user verification, so Home refuses an attestation
+ without it, on registration (`TestIDRegistrationRefusesWithoutUserVerification`)
+ and on replacement (`TestIDReplacementProofBinding/bad-uv`). `passkey.Schema` gained
`0002_credential_details` (ALTERs `passkey_credentials`); BootSchema
is frozen in the admission and compatibility profiles, so it takes
`passkey/0001_init` alone (`passkeyFrozen`, models.go), and the
@@ -365,10 +366,18 @@ quietly ignored).
Home's policy matches it and the hop pages link `handoff.css` (and
`handoff-noscript.css` inside `<noscript>`) instead of `<style>`
blocks. `db.Open` defaults to `synchronous(NORMAL)` since v0.34.0;
- `cmd/home` passes `db.DurableCommits()` to keep `FULL`.
-- **What v0.38.0 changed under Home: no Go code.** Home imports neither
+ `cmd/home` opens through `home.OpenDatabase`, which passes
+ `db.DurableCommits()` to keep `FULL` (`TestOpenDatabaseCommitsDurably`
+ reads `PRAGMA synchronous` = 2).
+- **What v0.38.0 changed under Home.** Home's own code imports neither
`auth` nor `lastsignin`, whose structs and one-way door are the
- release's API changes; `sessions`, `crypto`, `db`, `passkey` and
+ release's API changes. That is direct imports only: `passkey` (for
+ its Schema and Config) links `lastsignin` and `secondfactor` itself.
+ Home builds none of passkey's handlers (its ceremonies are its own;
+ `passkeyCfg` is kept only as the record the RP-ID guard reads), and
+ `internal/guardstest`'s `TestHomeNeverMountsFrameworkSignin` fails on
+ a direct import of `auth`, `lastsignin` or `secondfactor`, or a
+ `passkey.New` / `passkey.Handlers`, in production code. `sessions`, `crypto`, `db`, `passkey` and
`webauthn`'s Go are byte-identical, `assertion` only moved its
validators into an internal package, `auth`'s migrations are
unchanged, and `keymaildev/signin` stays v0.1.1. `webauthn.JS()`
@@ -376,8 +385,8 @@ quietly ignored).
uses. Fiesta 1.5.0's tokens.css declares the same day token names as
1.3.0, but moved two fallbacks Calma declares: `--rst-focus-edge` to
the accent (its one focus ring) and `--rst-ghost-face-hover` to
- `--rst-surface-2` on the one-way door. estilo `8da96ff`
- (`fix/calma-rastrillo-038-tokens`) declares both; Home pins it. Names
+ `--rst-surface-2` on the one-way door. estilo main `487cadb`
+ declares both; Home pins it. Names
are all `TestVendoredAssetsMatchTheLibrary` checks, so a moved
fallback passes here: re-check fallbacks in estilo on every bump
(estilo AGENTS.md, Theme). Credits regenerated (`make credits`).
@@ -387,7 +396,17 @@ quietly ignored).
limit twice. `newRenderer` now parses the layout and the partials once
and clones that tree per page (each clone carries its own `door` and
`hop`); the race run fell from about 360 s to 150 s here. Keep it
- that way rather than raising the timeout.
+ that way rather than raising the timeout (`TestRendererClonesPerPage`
+ holds each page's `door`, `hop`, `layout` and `content` apart).
+ **`rastrillo.Serve` gained endpoints outside Home's router**:
+ `POST /_theme`, which sets a `rastrillo_scheme` cookie without the
+ `__Host-` prefix, and `GET /_speculation-rules` with a
+ `Speculation-Rules` header on every response, on both origins.
+ `home.ServeOptions` (what `cmd/home` hands Serve) sets
+ `NoSchemeSwitch` and `NoSpeculationRules`; `TestServeAddsNoFrameworkRoutes`
+ builds the handler Serve runs (`rastrillo.Handler`) and checks both
+ hosts, with a control that turns them back on. Check `Options` for
+ new defaults like these on every bump.
- **No script by default; script only to enhance, and always prefer
none** (Paul, 2026-09-29, replacing rulings 21/24's closed list of
screens). Every screen works with scripts off — magic-link sign-in,
diff --git a/cmd/home/main.go b/cmd/home/main.go
index 398b70f..a4a7cdd 100644
--- a/cmd/home/main.go
+++ b/cmd/home/main.go
@@ -47,11 +47,9 @@ package main
import (
"context"
"log/slog"
- "net/http"
"os"
"amadan.net/rastrillo/rastrillo"
- rdb "amadan.net/rastrillo/rastrillo/db"
"amadan.net/rastrillo/rastrillo/migrate"
"amadan.net/oficina/home/internal/home"
@@ -98,12 +96,8 @@ func main() {
// the only one that performs DELETEs.
home.RegisterSecureDelete()
- // DurableCommits: synchronous(FULL), a WAL sync on every commit, which
- // is what every rastrillo before v0.34.0 opened with. This database is
- // credentials, the roster and the sealed link store, none of which
- // rebuilds (AGENTS.md, Deploys), so a power cut must not undo a commit
- // already answered; Home's write rate is far below what FULL costs.
- d, err := rdb.Open(opts.DBPath, logger, rdb.DurableCommits())
+ // synchronous(FULL): see OpenDatabase.
+ d, err := home.OpenDatabase(opts.DBPath, logger)
if err != nil {
logger.Error("open db", "err", err)
os.Exit(1)
@@ -126,10 +120,9 @@ func main() {
// rastrillo.Options.Mux wants a *http.ServeMux; the app's own
// router is a chi.Router (an http.Handler), so it mounts under one.
- mux := http.NewServeMux()
- mux.Handle("/", app.Router())
- opts.Mux = mux
- opts.CSP = app.SecurityPolicy()
+ // ServeOptions also turns off the framework's /_theme and
+ // speculation rules (serveopts.go).
+ opts = app.ServeOptions(opts)
// Blanked because this file opened the handle itself: Serve would
// otherwise open a second one against the same file.
diff --git a/connect/go.mod b/connect/go.mod
index bd0b9b8..38dccc7 100644
--- a/connect/go.mod
+++ b/connect/go.mod
@@ -3,7 +3,7 @@ module amadan.net/oficina/home/connect
go 1.26.0
require (
- amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe
+ amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88
amadan.net/oficina/home/handoff v0.0.0-20261114103055-d11246af8c07
amadan.net/rastrillo/rastrillo v0.38.0
github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3
diff --git a/connect/go.sum b/connect/go.sum
index 06b6d39..59e7b6c 100644
--- a/connect/go.sum
+++ b/connect/go.sum
@@ -1,5 +1,5 @@
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe h1:qF1+uozfPS+xMUFkZX3xpVQoMRYBAhHErQ+Bnw8zuAg=
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8=
+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/handoff v0.0.0-20261114103055-d11246af8c07 h1:F/cCmhmNZONlrdWt9AD5O3BjpLqIUeRDYDLvYrpST+o=
amadan.net/oficina/home/handoff v0.0.0-20261114103055-d11246af8c07/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
amadan.net/rastrillo/rastrillo v0.38.0 h1:q8aPnVtKt4q+uNjfxBRCTizhVvj+HdjDJh1MhlkBPOc=
diff --git a/go.mod b/go.mod
index 673dcda..7094091 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.26.0
toolchain go1.26.5
require (
- amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe
+ amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816
amadan.net/oficina/home/handoff v0.0.0-20261114110939-e03a01a1881c
amadan.net/oficina/home/roster v0.0.0-20261028165624-d942439ac4e4
diff --git a/go.sum b/go.sum
index de80b79..dc86672 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
amadan.net/carlos/platform.git/launchctx v0.0.0-20260911135504-fb577f96f7d1 h1:RxwIRojWcVtwSdNAjtdz7y1bxHLh3GUgqT1TrXVKpyM=
amadan.net/carlos/platform.git/launchctx v0.0.0-20260911135504-fb577f96f7d1/go.mod h1:6fBmMWgtESLFXZURzu/HyRXM0vyLuo4+XGGdKuZ+wao=
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe h1:qF1+uozfPS+xMUFkZX3xpVQoMRYBAhHErQ+Bnw8zuAg=
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8=
+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/dashboard v0.0.0-20261024234842-3774eb68f816 h1:AFDuOio0MxNxN9ZWVc3lul1QHkNjNUCO56kXpe/Fw3I=
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816/go.mod h1:+7xsX+QyVFrKy5gDAGh+FZ5+75z4CibWTL0wl9DWAw0=
amadan.net/oficina/home/handoff v0.0.0-20261114110939-e03a01a1881c h1:KxjjyIlEu3hY1G6l26IrI2PRcogOscpTeydRgNzimbA=
diff --git a/internal/guardstest/framework_signin_test.go b/internal/guardstest/framework_signin_test.go
new file mode 100644
index 0000000..38a4660
--- /dev/null
+++ b/internal/guardstest/framework_signin_test.go
@@ -0,0 +1,89 @@
+package guards
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "strconv"
+ "strings"
+ "testing"
+)
+
+// frameworkSignin are rastrillo's sign-in packages Home must not import
+// directly. Home is blind: its link store is sealed and its session
+// subject is an opaque person ref, and auth's defaults would write a
+// readable auth_links.address (AGENTS.md, Data). lastsignin remembers an
+// address in a cookie; secondfactor's Schema copies the recovery codes
+// out and drops the table Home's codes live in. passkey links lastsignin
+// and secondfactor itself, which is allowed: what is held here is that
+// Home's own code never reaches for them.
+var frameworkSignin = []string{
+ "amadan.net/rastrillo/rastrillo/auth",
+ "amadan.net/rastrillo/rastrillo/lastsignin",
+ "amadan.net/rastrillo/rastrillo/secondfactor",
+}
+
+// passkeyPkg's New and Handlers build and hold passkey's HTTP handlers.
+// Home runs its own ceremonies (internal/home/id_passkey.go) and keeps
+// passkey.Config only as the record its RP-ID guard reads; passkey's
+// sign-in and Gate handlers are never built, so never mounted.
+const passkeyPkg = "amadan.net/rastrillo/rastrillo/passkey"
+
+// passkeyHandlerUses returns each use of passkey.New or passkey.Handlers
+// in the file's code (comments are not code), under whatever name the
+// file imports passkey as.
+func passkeyHandlerUses(t *testing.T, path string) []string {
+ t.Helper()
+ fset := token.NewFileSet()
+ f, err := parser.ParseFile(fset, path, nil, parser.SkipObjectResolution)
+ if err != nil {
+ t.Fatalf("parse %s: %v", path, err)
+ }
+ name := ""
+ for _, imp := range f.Imports {
+ if p, _ := strconv.Unquote(imp.Path.Value); p == passkeyPkg {
+ name = "passkey"
+ if imp.Name != nil {
+ name = imp.Name.Name
+ }
+ }
+ }
+ if name == "" {
+ return nil
+ }
+ var uses []string
+ ast.Inspect(f, func(n ast.Node) bool {
+ sel, ok := n.(*ast.SelectorExpr)
+ if !ok {
+ return true
+ }
+ if x, ok := sel.X.(*ast.Ident); ok && x.Name == name && (sel.Sel.Name == "New" || sel.Sel.Name == "Handlers") {
+ uses = append(uses, "line "+strconv.Itoa(fset.Position(sel.Pos()).Line)+": passkey."+sel.Sel.Name)
+ }
+ return true
+ })
+ return uses
+}
+
+// TestHomeNeverMountsFrameworkSignin fails on a direct import of auth,
+// lastsignin or secondfactor, or a passkey.New / passkey.Handlers, in
+// any of Home's production files (tests may build fixtures with them).
+func TestHomeNeverMountsFrameworkSignin(t *testing.T) {
+ root := repoRoot(t)
+ for _, path := range goFiles(t, root) {
+ if strings.HasSuffix(path, "_test.go") {
+ continue
+ }
+ rel := relPath(t, root, path)
+ for _, imp := range fileImports(t, path) {
+ for _, banned := range frameworkSignin {
+ if imp == banned {
+ t.Errorf("%s: imports %s; Home does its own sign-in (AGENTS.md, Data)", rel, imp)
+ }
+ }
+ }
+ for _, use := range passkeyHandlerUses(t, path) {
+ t.Errorf("%s: %s; Home mounts none of passkey's handlers", rel, use)
+ }
+ }
+}
diff --git a/internal/home/app.go b/internal/home/app.go
index 609c733..86b70ae 100644
--- a/internal/home/app.go
+++ b/internal/home/app.go
@@ -56,7 +56,6 @@ type App struct {
renderer *renderer
flow *signin.Flow
sessions *sessions.Sessions
- passkeys *passkey.Handlers
// signinLimiter is signin.Flow's own limiter, held here so that /resolve
// spends the same per-IP budget sign-in does; resolveLimiter is
@@ -66,9 +65,11 @@ type App struct {
resolveLimiter *signin.MemoryLimiter
teamWrites *signin.MemoryLimiter
- // passkeyCfg is the config handed to passkey.New. Retained because
- // passkey.Handlers keeps its own copy unexported, and the RP-ID
- // guard has to read what the app configured rather than a literal.
+ // passkeyCfg is the passkey config the app builds. Home mounts none
+ // of passkey's handlers (its ceremonies are its own, id_passkey.go),
+ // so this is never handed to passkey.New: it is the record the RP-ID
+ // guard reads, so that guard checks what the app configured rather
+ // than a literal (TestHomeNeverMountsFrameworkSignin).
passkeyCfg passkey.Config
}
@@ -148,9 +149,7 @@ func NewWithOrigins(secrets Secrets, d *db.DB, logger *slog.Logger, origins Orig
a.flow.Limiter = blindSigninLimiter{next: a.signinLimiter, pepper: secrets.Pepper}
a.resolveLimiter = signin.NewMemoryLimiter(time.Hour)
- if a.passkeys, err = newPasskeys(a); err != nil {
- return nil, err
- }
+ a.passkeyCfg = passkeyConfig(a)
// Sweep at boot as well as on each put. A process that put a link
// and then restarted before the next one leaves that row behind
diff --git a/internal/home/id_passkey_test.go b/internal/home/id_passkey_test.go
index 1b74412..aee2f8f 100644
--- a/internal/home/id_passkey_test.go
+++ b/internal/home/id_passkey_test.go
@@ -319,3 +319,34 @@ func TestIDGatedChallengeGuards(t *testing.T) {
})
}
}
+
+// TestIDRegistrationRefusesWithoutUserVerification: since v0.27.1
+// rastrillo's webauthn.Config.Register no longer requires user
+// verification, so Home refuses a UV-less attestation itself, on
+// registration as on replacement (TestIDReplacementProofBinding/bad-uv).
+// The same ceremony with UV set is the control: it must succeed, so
+// the refusal is about the flag and nothing else.
+func TestIDRegistrationRefusesWithoutUserVerification(t *testing.T) {
+ for _, uv := range []bool{false, true} {
+ a := newTestApp(t)
+ s := signInFully(t, a, sealtest.CanaryAddress)
+ b := idJSON(t, a, "/passkey/register/begin", nil, s)
+ k, _ := authtest.New()
+ opts := authtest.Options{RPID: credentialHost, Origin: Origin}
+ if !uv {
+ opts.Flags = authtest.FlagUserPresent | authtest.FlagAttestedData
+ }
+ cd, att := k.Create(challengeFrom(t, b), opts)
+ r := idJSON(t, a, "/passkey/register/finish", map[string]string{"clientDataJSON": base64.RawURLEncoding.EncodeToString(cd), "attestationObject": base64.RawURLEncoding.EncodeToString(att)}, s)
+ var n int
+ if err := a.db.Reader().QueryRow("SELECT count(*) FROM passkey_credentials").Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ if uv && (r.Code != 200 || n != 1) {
+ t.Fatalf("control: registration with UV got %d and %d credentials", r.Code, n)
+ }
+ if !uv && (r.Code == 200 || n != 0) {
+ t.Fatalf("registration without user verification accepted: %d, %d credentials", r.Code, n)
+ }
+ }
+}
diff --git a/internal/home/noscript_test.go b/internal/home/noscript_test.go
index d46bfd6..ccfd76e 100644
--- a/internal/home/noscript_test.go
+++ b/internal/home/noscript_test.go
@@ -342,15 +342,29 @@ func TestServedCSPAllowsNoInlineScript(t *testing.T) {
}
}
-// The binary uses the policy whose only framework change is tested separately.
+// The binary uses the policy whose only framework change is tested
+// separately: cmd/home hands Serve exactly ServeOptions (serveopts.go),
+// sets no CSP of its own, and ServeOptions sets exactly the reviewed one.
func TestAppUsesReviewedCSP(t *testing.T) {
b, err := os.ReadFile("../../cmd/home/main.go")
if err != nil {
t.Fatal(err)
}
- assignment := []byte("opts.CSP = app.SecurityPolicy()")
- if bytes.Count(b, assignment) != 1 || bytes.Contains(bytes.ReplaceAll(b, assignment, nil), []byte("CSP")) {
- t.Error("binary must wire exactly the reviewed policy")
+ call := []byte("opts = app.ServeOptions(opts)")
+ if bytes.Count(b, call) != 1 || bytes.Contains(b, []byte("CSP")) {
+ t.Error("binary must hand Serve exactly app.ServeOptions, and set no CSP itself")
+ }
+ s, err := os.ReadFile("serveopts.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ assignment := []byte("opts.CSP = a.SecurityPolicy()")
+ if bytes.Count(s, assignment) != 1 || bytes.Contains(bytes.ReplaceAll(s, assignment, nil), []byte("CSP")) {
+ t.Error("ServeOptions must wire exactly the reviewed policy")
+ }
+ app := newTestApp(t)
+ if got := app.ServeOptions(rastrillo.Options{}).CSP; got != app.SecurityPolicy() {
+ t.Errorf("ServeOptions CSP = %q, want the reviewed policy", got)
}
}
diff --git a/internal/home/opendb.go b/internal/home/opendb.go
new file mode 100644
index 0000000..6a0a77e
--- /dev/null
+++ b/internal/home/opendb.go
@@ -0,0 +1,24 @@
+package home
+
+import (
+ "log/slog"
+
+ "amadan.net/rastrillo/rastrillo/db"
+)
+
+// OpenDatabase opens Home's database as cmd/home serves it.
+//
+// DurableCommits: synchronous(FULL), a WAL sync on every commit, which
+// is what every rastrillo before v0.34.0 opened with (since v0.34.0
+// db.Open defaults to NORMAL). This database is credentials, the roster
+// and the sealed link store, none of which rebuilds (AGENTS.md,
+// Deploys), so a power cut must not undo a commit already answered;
+// Home's write rate is far below what FULL costs.
+// TestOpenDatabaseCommitsDurably holds it.
+//
+// Call RegisterSecureDelete first: Open pings, which opens the writer
+// pool's one long-lived connection, and a hook registered after that
+// misses it.
+func OpenDatabase(path string, logger *slog.Logger) (*db.DB, error) {
+ return db.Open(path, logger, db.DurableCommits())
+}
diff --git a/internal/home/opendb_test.go b/internal/home/opendb_test.go
new file mode 100644
index 0000000..d02ab47
--- /dev/null
+++ b/internal/home/opendb_test.go
@@ -0,0 +1,45 @@
+package home
+
+import (
+ "path/filepath"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/db"
+)
+
+// TestOpenDatabaseCommitsDurably: the database cmd/home opens syncs the
+// WAL on every commit, PRAGMA synchronous = 2 (FULL), on the writer that
+// commits and on the readers. db.Open's own default since rastrillo
+// v0.34.0 is NORMAL (1), which is the control: it must differ, or this
+// test proves nothing.
+func TestOpenDatabaseCommitsDurably(t *testing.T) {
+ RegisterSecureDelete()
+ d, err := OpenDatabase(filepath.Join(t.TempDir(), "home.db"), quietLogger())
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { d.Close() })
+ var w, r int
+ if err := d.Writer().QueryRow("PRAGMA synchronous").Scan(&w); err != nil {
+ t.Fatal(err)
+ }
+ if err := d.Reader().QueryRow("PRAGMA synchronous").Scan(&r); err != nil {
+ t.Fatal(err)
+ }
+ if w != 2 || r != 2 {
+ t.Fatalf("PRAGMA synchronous: writer %d, reader %d; want 2 (FULL) on both", w, r)
+ }
+
+ plain, err := db.Open(filepath.Join(t.TempDir(), "plain.db"), quietLogger())
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { plain.Close() })
+ var p int
+ if err := plain.Writer().QueryRow("PRAGMA synchronous").Scan(&p); err != nil {
+ t.Fatal(err)
+ }
+ if p == 2 {
+ t.Fatal("control: db.Open without DurableCommits is FULL too, so this test cannot tell the option is applied")
+ }
+}
diff --git a/internal/home/passkey.go b/internal/home/passkey.go
index 2625617..e8ac127 100644
--- a/internal/home/passkey.go
+++ b/internal/home/passkey.go
@@ -36,8 +36,8 @@ const enrolFreshness = 10 * time.Minute
// It is returned rather than inlined so a test can assert on what the
// APP configures instead of on a literal it wrote itself — an RP-ID
// guard that declares its own config asserts a constant against itself.
-// passkey.Handlers keeps its config unexported, so the App retains this
-// value for that purpose.
+// Home builds no passkey.Handlers (TestHomeNeverMountsFrameworkSignin),
+// so the App retains this value for that purpose alone.
//
// LegacyRPID is deliberately empty. It exists for an instance that has
// changed hostname, so passkeys enrolled under the old name still
@@ -55,12 +55,6 @@ func passkeyConfig(a *App) passkey.Config {
}
}
-// newPasskeys wires the second factor.
-func newPasskeys(a *App) (*passkey.Handlers, error) {
- a.passkeyCfg = passkeyConfig(a)
- return passkey.New(a.passkeyCfg)
-}
-
// pageData is what every passkey page needs: the values the glue reads
// off <body> to run a ceremony.
//
diff --git a/internal/home/render_test.go b/internal/home/render_test.go
new file mode 100644
index 0000000..51b68de
--- /dev/null
+++ b/internal/home/render_test.go
@@ -0,0 +1,66 @@
+package home
+
+import (
+ "strings"
+ "testing"
+)
+
+// TestRendererClonesPerPage: newRenderer parses the layout and the shared
+// partials once and clones that tree for each page. Each clone must carry
+// its own door and hop (the layout branches on both), its own "layout"
+// template, and its own "content", so no page's definitions leak into
+// another's through the shared parse.
+func TestRendererClonesPerPage(t *testing.T) {
+ r, err := newRenderer()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(r.pages) < 2 {
+ t.Fatalf("%d pages", len(r.pages))
+ }
+ layouts := map[any]string{}
+ contents := map[string]string{}
+ for name, page := range r.pages {
+ probe, err := page.Clone()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if probe, err = probe.New("zz-probe").Parse("{{door}} {{hop}}"); err != nil {
+ t.Fatal(err)
+ }
+ var b strings.Builder
+ if err := probe.ExecuteTemplate(&b, "zz-probe", nil); err != nil {
+ t.Fatal(err)
+ }
+ want := map[bool]string{true: "true", false: "false"}
+ if got := b.String(); got != want[doorPages[name]]+" "+want[hopPages[name]] {
+ t.Errorf("%s: door hop = %q, want door=%v hop=%v", name, got, doorPages[name], hopPages[name])
+ }
+
+ layout := page.Lookup("layout")
+ if layout == nil {
+ t.Fatalf("%s: no layout", name)
+ }
+ if other, ok := layouts[layout]; ok {
+ t.Errorf("%s and %s share one layout template", name, other)
+ }
+ layouts[layout] = name
+
+ content := page.Lookup("content")
+ if content == nil || content.Tree == nil {
+ t.Fatalf("%s: no content", name)
+ }
+ body := content.Tree.Root.String()
+ if other, ok := contents[body]; ok {
+ t.Errorf("%s draws %s's content", name, other)
+ }
+ contents[body] = name
+ }
+ for _, m := range []map[string]bool{doorPages, hopPages} {
+ for name := range m {
+ if _, ok := r.pages[name]; !ok {
+ t.Errorf("%s is listed as a door or hop page but has no template", name)
+ }
+ }
+ }
+}
diff --git a/internal/home/serveopts.go b/internal/home/serveopts.go
new file mode 100644
index 0000000..5ba4f9d
--- /dev/null
+++ b/internal/home/serveopts.go
@@ -0,0 +1,29 @@
+package home
+
+import (
+ "net/http"
+
+ "amadan.net/rastrillo/rastrillo"
+)
+
+// ServeOptions is what cmd/home hands rastrillo.Serve: Home's router
+// under a mux, Home's reviewed security policy (noscript_test.go holds it),
+// and two of the framework's own endpoints turned off. A seam, so a
+// test can build the very handler Serve does (rastrillo.Handler) and
+// see the layer outside Home's router.
+//
+// Since v0.38.0 Serve mounts, on every host, POST /_theme (it sets a
+// rastrillo_scheme cookie without the __Host- prefix) and
+// GET /_speculation-rules, and puts a Speculation-Rules header on every
+// response. Home picks the scheme through its own Appearance form and
+// prerenders nothing, and the credential origin must never carry a
+// cookie Home did not mint, so both are off (TestServeAddsNoFrameworkRoutes).
+func (a *App) ServeOptions(opts rastrillo.Options) rastrillo.Options {
+ mux := http.NewServeMux()
+ mux.Handle("/", a.Router())
+ opts.Mux = mux
+ opts.CSP = a.SecurityPolicy()
+ opts.NoSchemeSwitch = true
+ opts.NoSpeculationRules = true
+ return opts
+}
diff --git a/internal/home/serveopts_test.go b/internal/home/serveopts_test.go
new file mode 100644
index 0000000..6c78850
--- /dev/null
+++ b/internal/home/serveopts_test.go
@@ -0,0 +1,91 @@
+package home
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "strings"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo"
+)
+
+// frameworkRoutes reports what rastrillo's own layer added to the handler
+// Serve would run, on host: a rastrillo_scheme cookie from POST /_theme,
+// the speculation ruleset at GET /_speculation-rules, and a
+// Speculation-Rules header on an ordinary page.
+func frameworkRoutes(t *testing.T, h http.Handler, host string) []string {
+ t.Helper()
+ var found []string
+
+ form := url.Values{"scheme": {"dark"}}
+ req := httptest.NewRequest(http.MethodPost, "/_theme", strings.NewReader(form.Encode()))
+ req.Host = host
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Origin", "https://"+host)
+ req.Header.Set("Sec-Fetch-Site", "same-origin")
+ rec := httptest.NewRecorder()
+ h.ServeHTTP(rec, req)
+ for _, c := range rec.Result().Cookies() {
+ if c.Name == rastrillo.SchemeCookie {
+ found = append(found, "POST /_theme set "+c.Name)
+ }
+ }
+
+ req = httptest.NewRequest(http.MethodGet, rastrillo.SpeculationRulesPath, nil)
+ req.Host = host
+ rec = httptest.NewRecorder()
+ h.ServeHTTP(rec, req)
+ if strings.Contains(rec.Header().Get("Content-Type"), "speculationrules") {
+ found = append(found, "GET "+rastrillo.SpeculationRulesPath+" served the ruleset")
+ }
+
+ req = httptest.NewRequest(http.MethodGet, "/", nil)
+ req.Host = host
+ req.Header.Set("Accept", "text/html")
+ rec = httptest.NewRecorder()
+ h.ServeHTTP(rec, req)
+ if v := rec.Header().Get("Speculation-Rules"); v != "" {
+ found = append(found, "Speculation-Rules header "+v)
+ }
+ return found
+}
+
+// TestServeAddsNoFrameworkRoutes builds the handler rastrillo.Serve runs
+// (rastrillo.Handler over ServeOptions, exactly what cmd/home passes) and
+// proves that, on both origins, none of v0.38.0's framework endpoints is
+// there: no POST /_theme and its non-__Host- rastrillo_scheme cookie, no
+// speculation ruleset, no Speculation-Rules header. Home's router tests
+// cannot see this layer, which is why it is tested here. The control
+// half turns the two options back off and expects every one of them, so
+// a probe that has gone blind fails rather than passes.
+func TestServeAddsNoFrameworkRoutes(t *testing.T) {
+ app := newTestApp(t)
+ opts := app.ServeOptions(rastrillo.Options{Logger: quietLogger()})
+ if !opts.NoSchemeSwitch || !opts.NoSpeculationRules {
+ t.Fatalf("ServeOptions: NoSchemeSwitch=%v NoSpeculationRules=%v, want both true", opts.NoSchemeSwitch, opts.NoSpeculationRules)
+ }
+ h, closeFn, err := rastrillo.Handler(opts)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = closeFn() })
+ for _, host := range []string{credentialHost, directoryHost} {
+ if found := frameworkRoutes(t, h, host); len(found) != 0 {
+ t.Errorf("%s: rastrillo's layer adds %v", host, found)
+ }
+ }
+
+ control := opts
+ control.NoSchemeSwitch, control.NoSpeculationRules = false, false
+ ch, closeControl, err := rastrillo.Handler(control)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = closeControl() })
+ for _, host := range []string{credentialHost, directoryHost} {
+ if found := frameworkRoutes(t, ch, host); len(found) != 3 {
+ t.Errorf("%s: control saw %v, want all three framework routes (the probe is blind)", host, found)
+ }
+ }
+}
diff --git a/teammode/go.mod b/teammode/go.mod
index 32fcb79..57157fc 100644
--- a/teammode/go.mod
+++ b/teammode/go.mod
@@ -11,7 +11,7 @@ require (
)
require (
- amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe // indirect
+ amadan.net/oficina/estilo.git v0.0.0-20261120104604-487cadb03b88 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
diff --git a/teammode/go.sum b/teammode/go.sum
index 1214b56..b6867cc 100644
--- a/teammode/go.sum
+++ b/teammode/go.sum
@@ -1,5 +1,5 @@
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe h1:qF1+uozfPS+xMUFkZX3xpVQoMRYBAhHErQ+Bnw8zuAg=
-amadan.net/oficina/estilo.git v0.0.0-20261120093611-8da96ff98afe/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8=
+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-20261028165624-d942439ac4e4 h1:WQ4irMKZerybbbccJblyukiloZZ9zfIxcay4vVyVowU=
amadan.net/oficina/home/connect v0.0.0-20261028165624-d942439ac4e4/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk=
amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM=