oficina / home Public

Isolate dashboard protocol module and tighten provider validation

claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3774eb68f8168f7aa43d9a9fe9406cda12c9d998 parent 2ffdf3f
10 files changed, +188 −2
  • Makefile +5 −1
  • dashboard/go.mod +21 −0
  • dashboard/go.sum +55 −0
  • {connect/dashboard => dashboard}/migrations/0001_dashboard.sql +0 −0
  • {connect/dashboard => dashboard}/provider.go +0 −0
  • dashboard/provider_test.go +103 −0
  • {connect/dashboard => dashboard}/replay.go +0 −0
  • {connect/dashboard => dashboard}/token.go +0 −0
  • {connect/dashboard => dashboard}/token_test.go +0 −0
  • {connect/dashboard => dashboard}/wire.go +4 −1

CI cancelled — superseded by a newer push — run details

diff --git a/Makefile b/Makefile
index 47c04de..f4ebd01 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,7 @@ test: test-vet test-fmt test-build test-go test-race
# with HTTP 429 however long the runner waited between runs. What one
# attempt fetched stays cached, so each retry asks for less.
deps:
- @for dir in . handoff roster connect; do \
+ @for dir in . handoff roster connect dashboard; do \
n=0; until (cd $$dir && go mod download); do \
n=$$((n+1)); [ $$n -lt 6 ] || exit 1; \
echo "go mod download in $$dir failed (the hub's git rate limit?); retrying in $$((n*5))s"; \
@@ -85,6 +85,7 @@ test-vet: deps
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 ./...
# Fails on unformatted files rather than rewriting them. CI must never
@@ -102,12 +103,14 @@ test-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 ./...
test-go:
CGO_ENABLED=0 go test -count=1 ./...
cd handoff && CGO_ENABLED=0 go test -count=1 ./...
cd roster && CGO_ENABLED=0 go test -count=1 ./...
+ cd dashboard && CGO_ENABLED=0 go test ./...
cd connect && CGO_ENABLED=0 go test -count=1 ./...
# The one concurrency-bearing package. internal/home's link store is
@@ -124,6 +127,7 @@ test-race:
go test -race -count=1 ./internal/home/ ./internal/operator/ ./internal/operatorlaunch/ ./internal/provisioner/ ./internal/home/directorydata/
cd handoff && CGO_ENABLED=1 go test -race -count=1 ./...
cd roster && CGO_ENABLED=1 go test -race -count=1 ./...
+ cd dashboard && CGO_ENABLED=1 go test -race -count=1 ./...
cd connect && CGO_ENABLED=1 go test -race -count=1 ./...
# The browser checks, in a real Chromium (RASTRILLO_CHROME, on PATH, or
diff --git a/dashboard/go.mod b/dashboard/go.mod
new file mode 100644
index 0000000..ebbe7a2
--- /dev/null
+++ b/dashboard/go.mod
@@ -0,0 +1,21 @@
+module amadan.net/oficina/home/dashboard
+
+go 1.25.0
+
+require (
+ 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
+)
+
+require (
+ github.com/dustin/go-humanize v1.0.1 // indirect
+ github.com/google/uuid v1.6.0 // indirect
+ github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/ncruces/go-strftime v1.0.0 // indirect
+ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
+ golang.org/x/sys v0.46.0 // indirect
+ modernc.org/libc v1.74.1 // indirect
+ modernc.org/mathutil v1.7.1 // indirect
+ modernc.org/memory v1.11.0 // indirect
+)
diff --git a/dashboard/go.sum b/dashboard/go.sum
new file mode 100644
index 0000000..8bd49e5
--- /dev/null
+++ b/dashboard/go.sum
@@ -0,0 +1,55 @@
+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=
+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
+github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 h1:iizUGZ9pEquQS5jTGkh4AqeeHCMbfbjeb0zMt0aEFzs=
+github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
+github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
+github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
+github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
+github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
+github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
+golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
+golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
+golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
+golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
+golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
+golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
+golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
+modernc.org/cc/v4 v4.29.0 h1:CXgwL8cvxmyzBQZzbSl/6xFtMCryb6u8IOqDci39cgc=
+modernc.org/cc/v4 v4.29.0/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
+modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
+modernc.org/ccgo/v4 v4.34.6/go.mod h1:SZ8YcN9NG7XVsQYdm6jYBvi8PQP1qi+kqB6OhjqI3Fk=
+modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
+modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
+modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
+modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
+modernc.org/gc/v3 v3.1.4 h1:2g65LGVSmFQrXeITAw97x7hCRvZFcyE1uDP+7Vng7JI=
+modernc.org/gc/v3 v3.1.4/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
+modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
+modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
+modernc.org/libc v1.74.1 h1:bdR4VTKFMC4966QSNZ05XLGI/VwzVa2kTUX51Dm0riQ=
+modernc.org/libc v1.74.1/go.mod h1:uH4t5bOx3G3g9Xcmj10YKlTcVISlRDwv8VoQJG9n8Os=
+modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
+modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
+modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
+modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
+modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
+modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
+modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
+modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
+modernc.org/sqlite v1.55.0 h1:hIFh0MCH0rGinQ/4KYb5/UbCkRkb+UP+OkLCVWa5MTM=
+modernc.org/sqlite v1.55.0/go.mod h1:4ntCLuNmnH8+GNqjka1wNg7KJd5/Hi5FYp8K+XQ7GZw=
+modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
+modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
+modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
+modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
diff --git a/connect/dashboard/migrations/0001_dashboard.sql b/dashboard/migrations/0001_dashboard.sql
similarity index 100%
rename from connect/dashboard/migrations/0001_dashboard.sql
rename to dashboard/migrations/0001_dashboard.sql
diff --git a/connect/dashboard/provider.go b/dashboard/provider.go
similarity index 100%
rename from connect/dashboard/provider.go
rename to dashboard/provider.go
diff --git a/dashboard/provider_test.go b/dashboard/provider_test.go
new file mode 100644
index 0000000..200f921
--- /dev/null
+++ b/dashboard/provider_test.go
@@ -0,0 +1,103 @@
+package dashboard
+
+import (
+ "context"
+ "database/sql"
+ "net/http/httptest"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestProviderRequiresBoundTokenAndExistingIdentity(t *testing.T) {
+ db, e := sql.Open("sqlite", t.TempDir()+"/provider.db")
+ if e != nil {
+ t.Fatal(e)
+ }
+ defer db.Close()
+ db.SetMaxOpenConns(1)
+ b, _ := Migrations.ReadFile("migrations/0001_dashboard.sql")
+ if _, e = db.Exec(string(b)); e != nil {
+ t.Fatal(e)
+ }
+ k, c := fixture(t)
+ c.Issued = time.Now().Unix()
+ c.Expires = c.Issued + 120
+ resolveCalls, readCalls := 0, 0
+ cfg := ProviderConfig{DB: db, Issuer: c.Issuer, Origin: c.Audience, Directory: c.Directory, Team: c.Team, Kind: "documents", Keys: map[string][]byte{c.KeyID: k.SignPub()}, Resolve: func(_ context.Context, sub string) (int64, error) {
+ resolveCalls++
+ if sub != c.Subject {
+ return 0, ErrRefused
+ }
+ return 1, nil
+ }, Read: func(_ context.Context, id int64, sub string, _ time.Time) (Response, error) {
+ readCalls++
+ return Response{Items: []Item{{ID: "one", Title: "Private canary", URL: c.Audience + "/d/one", Updated: time.Now()}}}, nil
+ }}
+ h, e := NewProvider(cfg)
+ if e != nil {
+ t.Fatal(e)
+ }
+ request := func(token string) *httptest.ResponseRecorder {
+ r := httptest.NewRequest("GET", c.Audience+Path, nil)
+ if token != "" {
+ r.Header.Set("Authorization", "Bearer "+token)
+ }
+ w := httptest.NewRecorder()
+ h.ServeHTTP(w, r)
+ return w
+ }
+ if w := request(""); w.Code != 401 {
+ t.Fatal(w.Code)
+ }
+ bad := c
+ bad.Team = "other"
+ token, _ := Sign(k, bad)
+ if w := request(token); w.Code != 401 {
+ t.Fatal(w.Code)
+ }
+ if resolveCalls != 0 || readCalls != 0 {
+ t.Fatal("unverified request reached identity/data")
+ }
+ token, _ = Sign(k, c)
+ w := request(token)
+ if w.Code != 200 || !strings.Contains(w.Body.String(), "Private canary") || w.Header().Get("Cache-Control") != "private, no-store" {
+ t.Fatalf("response %d", w.Code)
+ }
+ if w = request(token); w.Code != 401 {
+ t.Fatal("replay", w.Code)
+ }
+ other := c
+ other.ID, _ = ID()
+ other.Subject = "pr_" + strings.Repeat("b", 26)
+ token, _ = Sign(k, other)
+ if w = request(token); w.Code != 403 || strings.Contains(w.Body.String(), "canary") {
+ t.Fatal("unknown identity", w.Code)
+ }
+ if readCalls != 1 {
+ t.Fatal("read reached more than authorized request", readCalls)
+ }
+}
+func TestMalformedWireIsNotEmptySuccess(t *testing.T) {
+ r := Response{Version: 1, Team: "pilot", Kind: "documents"}
+ if r.Valid("https://docs.example.com", "pilot", "documents") {
+ t.Fatal("nil items accepted")
+ }
+ r.Items = []Item{}
+ if !r.Valid("https://docs.example.com", "pilot", "documents") {
+ t.Fatal("explicit empty refused")
+ }
+ r.Kind = "events"
+ if r.Valid("https://docs.example.com", "pilot", "events") {
+ t.Fatal("missing timezone accepted")
+ }
+ r.Timezone = "Europe/Dublin"
+ if !r.Valid("https://docs.example.com", "pilot", "events") {
+ t.Fatal("valid empty agenda refused")
+ }
+ for _, link := range []string{"https://evil.example.com/d/1", "https://docs.example.com@evil.example.com/d/1", "https://docs.example.com/\\evil"} {
+ if SafeLink(link, "https://docs.example.com") {
+ t.Fatal("unsafe link")
+ }
+ }
+}
diff --git a/connect/dashboard/replay.go b/dashboard/replay.go
similarity index 100%
rename from connect/dashboard/replay.go
rename to dashboard/replay.go
diff --git a/connect/dashboard/token.go b/dashboard/token.go
similarity index 100%
rename from connect/dashboard/token.go
rename to dashboard/token.go
diff --git a/connect/dashboard/token_test.go b/dashboard/token_test.go
similarity index 100%
rename from connect/dashboard/token_test.go
rename to dashboard/token_test.go
diff --git a/connect/dashboard/wire.go b/dashboard/wire.go
similarity index 89%
rename from connect/dashboard/wire.go
rename to dashboard/wire.go
index 42855ec..4d62ee3 100644
--- a/connect/dashboard/wire.go
+++ b/dashboard/wire.go
@@ -34,10 +34,13 @@ func SafeLink(raw, origin string) bool {
return e == nil && u.Scheme+"://"+u.Host == origin && u.User == nil && u.Opaque == "" && strings.HasPrefix(u.Path, "/") && !strings.ContainsAny(raw, "\r\n\\")
}
func (r Response) Valid(origin, team, kind string) bool {
- if r.Version != 1 || r.Team != team || r.Kind != kind || len(r.Items) > MaxItems || (kind != "documents" && kind != "events") {
+ if r.Version != 1 || r.Team != team || r.Kind != kind || r.Items == nil || len(r.Items) > MaxItems || (kind != "documents" && kind != "events") {
return false
}
if kind == "events" {
+ if len(r.Timezone) == 0 || len(r.Timezone) > 128 {
+ return false
+ }
if _, e := time.LoadLocation(r.Timezone); e != nil {
return false
}