List views, review changes: Secure cookies, a hidden column never sorts
Claude Fable 5.1 reviewed 99a0dd5: APPROVED WITH CHANGES. - Preference cookies are Secure over HTTPS (from the origin, as the session cookie is), HttpOnly, SameSite=Lax; tested against an HTTPS app (TestPreferenceCookiesAreSecureOverHTTPS). - A sort by a hidden column is dropped, and the View forms return to the list as shown (l.href()), so it stays dropped (TestAHiddenColumnDoesNotSort, mutation-checked). - The checklist scrolls, not the panel, so the apply button stays in view on a type with many fields. - The return-path guard has cases that reach it (the list's own path with a tab or a backslash; mutation-checked). - The stretched link's trade-offs are written down: no drag-select in a row, no hover tooltip on a date cell. Left: a type whose first field is long text has no title cell (as before this change).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+79
−12
internal/fichas/handlers.go+7 −2internal/fichas/listprefs.go+13 −5internal/fichas/static/fichas.css+8 −4internal/fichastest/listprefs_test.go+51 −1
CI passed — run details
CI log
=== vet === go vet ./... go vet -tags browser ./internal/fichastest/ === fmt === === test === go test ./... ? amadan.net/oficina/fichas/cmd/fichas [no test files] ok amadan.net/oficina/fichas/internal/fichas 1.894s ? amadan.net/oficina/fichas/internal/fichas/icons [no test files] ok amadan.net/oficina/fichas/internal/fichas/seal (cached) ok amadan.net/oficina/fichas/internal/fichastest 1.071s ? amadan.net/oficina/fichas/scripts/mockups [no test files] ? amadan.net/oficina/fichas/scripts/preview [no test files] ? amadan.net/oficina/fichas/scripts/writeestilo [no test files] === migration-check === go tool rastrillo migration check rastrillo migration check: models and migrations agree
diff --git a/internal/fichas/handlers.go b/internal/fichas/handlers.go| index f305a09..3c2c863 100644 |
| --- a/internal/fichas/handlers.go |
| +++ b/internal/fichas/handlers.go |
| @@ -332,6 +332,12 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| } |
| base := typeHref(ti.Key) |
| l := parseList(r, base, fields) |
| + // A sort by a column this reader has hidden would order the rows by |
| + // something they cannot see, with no header to undo it: drop it. |
| + shown := shownColumns(r, ti.Key, fields) |
| + if l.Sort != "" && !shown[l.Sort] { |
| + l.Sort, l.Desc = "", false |
| + } |
| res, err := a.ix.Query(ti.Key, l.query()) |
| if err != nil { |
| a.fail(w, r, err) |
| @@ -339,7 +345,6 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| } |
| filtered := l.Q != "" || len(l.Filters) > 0 |
| reset := listState{base: base, View: l.View, Filters: map[string]string{}} |
| - shown := shownColumns(r, ti.Key, fields) |
| a.page(w, r, "index", map[string]any{ |
| "TypeKey": ti.Key, |
| "Result": res, |
| @@ -356,7 +361,7 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| "Shown": shown, |
| "Choices": columnChoices(fields, shown), |
| "Density": densityOf(r), |
| - "Here": r.URL.RequestURI(), |
| + "Here": l.href(), // the list as shown: a dropped sort stays dropped |
| "Pages": l.pages(res), |
| "Count": countLine(res, filtered), |
| "Filtered": filtered, |
diff --git a/internal/fichas/listprefs.go b/internal/fichas/listprefs.go| index 771770f..c90ef1d 100644 |
| --- a/internal/fichas/listprefs.go |
| +++ b/internal/fichas/listprefs.go |
| @@ -119,7 +119,7 @@ func (a *app) saveView(w http.ResponseWriter, r *http.Request) { |
| _ = r.ParseForm() |
| switch d := r.PostForm.Get("density"); d { |
| case DensityComfortable, DensityCompact: |
| - setPref(w, densityCookie, d) |
| + a.setPref(w, densityCookie, d, prefMaxAge) |
| } |
| if r.PostForm.Get("columns") == "1" { |
| show := map[string]bool{} |
| @@ -135,16 +135,24 @@ func (a *app) saveView(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| if len(hide) == 0 { |
| - http.SetCookie(w, &http.Cookie{Name: columnsCookie(ti.Key), Path: "/", MaxAge: -1, HttpOnly: true, SameSite: http.SameSiteLaxMode}) |
| + a.setPref(w, columnsCookie(ti.Key), "", -1) |
| } else { |
| - setPref(w, columnsCookie(ti.Key), strings.Join(hide, ".")) |
| + a.setPref(w, columnsCookie(ti.Key), strings.Join(hide, "."), prefMaxAge) |
| } |
| } |
| http.Redirect(w, r, listReturn(r.PostForm.Get("return_to"), typeHref(ti.Key)), http.StatusSeeOther) |
| } |
| -func setPref(w http.ResponseWriter, name, value string) { |
| - http.SetCookie(w, &http.Cookie{Name: name, Value: value, Path: "/", MaxAge: prefMaxAge, HttpOnly: true, SameSite: http.SameSiteLaxMode}) |
| +// setPref writes a preference cookie (maxAge -1 clears it). Secure |
| +// whenever the app is served over HTTPS, as every other cookie it and |
| +// estilo set is; derived from the origin, as the session cookie is, so a |
| +// plain-http local preview still keeps it in Safari. |
| +func (a *app) setPref(w http.ResponseWriter, name, value string, maxAge int) { |
| + http.SetCookie(w, &http.Cookie{ |
| + Name: name, Value: value, Path: "/", MaxAge: maxAge, |
| + HttpOnly: true, SameSite: http.SameSiteLaxMode, |
| + Secure: strings.HasPrefix(a.cfg.Origin, "https://"), |
| + }) |
| } |
| // listReturn is where a view change lands: the list it was made on (its |
diff --git a/internal/fichas/static/fichas.css b/internal/fichas/static/fichas.css| index 8918648..6ae72de 100644 |
| --- a/internal/fichas/static/fichas.css |
| +++ b/internal/fichas/static/fichas.css |
| @@ -218,7 +218,10 @@ |
| /* ---- A row opens its card: the title's link is stretched over the |
| whole row, so it works with scripts off, middle-clicks into a new tab, |
| and stays one tab stop. A link of the row's own (a domain) sits above |
| - the stretch and keeps working. The row shows the focus ring. */ |
| + the stretch and keeps working. The row shows the focus ring. |
| + Accepted trade-offs (Paul asked for whole-row clicks): text in a row |
| + cannot be selected by dragging, and a date cell's title tooltip is not |
| + reachable by hover; the card page shows both. */ |
| [fichas-grid] tbody tr { position: relative; } |
| [fichas-row-link]::after { content: ""; position: absolute; inset: 0; } |
| [fichas-grid] tbody td a:not([fichas-row-link]) { position: relative; z-index: 1; } |
| @@ -232,8 +235,9 @@ |
| /* ---- The View menu: density and columns, beside Fields. */ |
| [fichas-toolbar-end] { display: flex; align-items: center; gap: var(--rst-sp-2); } |
| [fichas-view-menu] { position: relative; } |
| -/* No height cap: the dropdown's 320px scroll would hide the apply |
| - button below the checklist. */ |
| +/* The panel itself is not capped (the dropdown's 320px scroll would carry |
| + the apply button away); the checklist scrolls instead, so a type with |
| + many fields keeps the button in view. */ |
| [fichas-view-panel] { min-inline-size: 15rem; max-block-size: none; overflow: visible; padding: var(--rst-sp-3); } |
| [fichas-view-panel] hr { margin-block: var(--rst-sp-3); } |
| [fichas-view-heading] { |
| @@ -267,7 +271,7 @@ |
| color: var(--rst-text); |
| box-shadow: 0 1px 2px rgb(23 32 60 / 0.12); |
| } |
| -[fichas-view-columns] { margin: 0 0 var(--rst-sp-3); padding: 0; border: 0; } |
| +[fichas-view-columns] { margin: 0 0 var(--rst-sp-3); padding: 0; border: 0; max-block-size: min(18rem, 50vh); overflow-y: auto; } |
| [fichas-view-check] { |
| display: flex; |
| align-items: center; |
diff --git a/internal/fichastest/listprefs_test.go b/internal/fichastest/listprefs_test.go| index 3a23fa3..9d6cb1d 100644 |
| --- a/internal/fichastest/listprefs_test.go |
| +++ b/internal/fichastest/listprefs_test.go |
| @@ -105,7 +105,9 @@ func TestColumnsAreTheReadersChoice(t *testing.T) { |
| func TestAViewChangeOnlyReturnsToAList(t *testing.T) { |
| h := newApp(t) |
| base := "/t/" + fichas.TypeCustomer |
| - for _, to := range []string{"//evil.example/", "https://evil.example/", "/cards/1/delete", "/\\evil.example", "/t/other"} { |
| + for _, to := range []string{"//evil.example/", "https://evil.example/", "/cards/1/delete", "/\\evil.example", "/t/other", |
| + // The list's own path, carrying a control character or a backslash. |
| + base + "?x=\t//evil.example", base + "?x=\\evil.example"} { |
| rec := post(t, h, base+"/view", url.Values{"density": {"compact"}, "return_to": {to}}) |
| if loc := rec.Header().Get("Location"); loc != base { |
| t.Errorf("return_to %q went to %q, want %q", to, loc, base) |
| @@ -121,3 +123,51 @@ func TestEveryRowLinksToItsCard(t *testing.T) { |
| t.Fatal("the row's title is not the row link") |
| } |
| } |
| + |
| +// A sort by a hidden column is dropped: rows are never ordered by |
| +// something the reader cannot see, and no link on the page carries it on. |
| +func TestAHiddenColumnDoesNotSort(t *testing.T) { |
| + h := newApp(t) |
| + createACustomer(t, h, "Cnoc Teoranta") |
| + base := "/t/" + fichas.TypeCustomer |
| + sorted := base + "?sort=" + fichas.FieldEmail |
| + if body := get(t, h, sorted).Body.String(); !strings.Contains(body, "sort="+fichas.FieldEmail) { |
| + t.Fatal("precondition: a shown column's sort is carried by the page's links") |
| + } |
| + rec := post(t, h, base+"/view", url.Values{"columns": {"1"}, "show": {fichas.FieldStage}, "return_to": {base}}) |
| + // The list's own links (the page content; the account menu's Appearance |
| + // return is the raw URL, and a return there drops the sort again). |
| + body := withCookies(t, h, sorted, rec) |
| + page := body[strings.Index(body, `id="main"`):] |
| + if i := strings.Index(page, "sort="+fichas.FieldEmail); i >= 0 { |
| + t.Errorf("the page still sorts by the hidden Email column: …%s…", page[max(0, i-200):i+40]) |
| + } |
| +} |
| + |
| +// Served over HTTPS, the preference cookies are Secure, as every other |
| +// cookie the app and estilo set is; always HttpOnly and SameSite=Lax. |
| +func TestPreferenceCookiesAreSecureOverHTTPS(t *testing.T) { |
| + const origin = "https://fichas.example" |
| + h := appWith(t, func(c *fichas.Config) { c.Origin = origin }) |
| + base := "/t/" + fichas.TypeCustomer |
| + for _, form := range []url.Values{ |
| + {"density": {"compact"}}, |
| + {"columns": {"1"}, "show": {fichas.FieldStage}}, |
| + {"columns": {"1"}, "show": {fichas.FieldDomain, fichas.FieldEmail, fichas.FieldPhone, fichas.FieldStage, fichas.FieldNextAction, fichas.SortLastCall}}, |
| + } { |
| + req := httptest.NewRequest(http.MethodPost, origin+base+"/view", strings.NewReader(form.Encode())) |
| + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + req.Header.Set("Origin", origin) |
| + rec := httptest.NewRecorder() |
| + h.ServeHTTP(rec, req) |
| + cookies := rec.Result().Cookies() |
| + if rec.Code != http.StatusSeeOther || len(cookies) == 0 { |
| + t.Fatalf("POST %v: %d, %d cookies", form, rec.Code, len(cookies)) |
| + } |
| + for _, c := range cookies { |
| + if !c.Secure || !c.HttpOnly || c.SameSite != http.SameSiteLaxMode { |
| + t.Errorf("%s is not Secure, HttpOnly and SameSite=Lax over HTTPS: %s", c.Name, c.String()) |
| + } |
| + } |
| + } |
| +} |