carlos / platform Public

fix: accept browser demo reports and key limits by client IP

Use same-origin referrer policy for report forms and the shared edge proof key cache for verified client limits. Preserve exact-Origin and signed forwarding checks.

Cover browser submission, cold-cache client budgets, the form input bound and GET attempt isolation.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev b031a93a3255e9ba7d06bc4647b79e8631ecb7fd parent beb841f
5 files changed, +331 −20
  • internal/console/apidemoreports.go +6 −9
  • internal/console/authcli.go +2 −1
  • internal/console/demo_reports_browser_test.go +229 −0
  • internal/console/demo_reports_test.go +93 −9
  • internal/console/templates/demo_report.html +1 −1

CI failed — run details

Intent

Human

<task-notification> <task-id>beqcksaya</task-id> <tool-use-id>toolu_01CK87VKsyPQa69Qp4kEF6Z8</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6e566fe9-9aca-47cb-9753-64e881b0d285/tasks/beqcksaya.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 5 Codex run" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a9e2447cc8fa608cb</task-id> <tool-use-id>toolu_01SMwS2kqUV3zVTdQVLB734n</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6e566fe9-9aca-47cb-9753-64e881b0d285/tasks/a9e2447cc8fa608cb.output</output-file> <status>completed</status> <summary>Agent "Review Task 5 (Opus)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Spec verdict:** Issues found (❌). Everything the brief asks for is present, but two P1s mean reporting fails in practice. **Quality verdict:** Needs fixes. Overall: NOT READY. **Counts:** 2 P1, 0 P2, 6 P3. - **P1-1:** No real browser can file a report. The form page is sent with `Referrer-Policy: no-referrer` (`apidemoreports.go:95`), and under that policy browsers send `Origin: null` on the form POST. The exact-Origin check (`:147`) then refuses it, so every browser report fails. The tests set the Origin header by hand, and the `null-origin` case asserts the very refusal browsers will trigger. Fix: send `Referrer-Policy: same-origin` on the report page, and add a witness that would catch this. (Boundary: the CSRF gate meeting browser Origin rules.) - **P1-2:** The 10-per-IP-per-hour limit is in practice one bucket shared by everyone. The console sits on 127.0.0.1 behind its own edge. The report check only trusts forwarded addresses when edge proof keys were cached in the last 30 s, and only login and admission requests fill that cache. Otherwise every report counts against 127.0.0.1. Attempts are spent before any validation, so one anonymous client sending 10 junk POSTs an hour blocks all reporting, for example the owner of the phishing demo being reported. This was the implementer's flagged concern. The fix needs your ruling against the "no new S3 reads on the report path" constraint, on one of three options: - (a) Let the report door use the existing key loader: at most one key read per 30 s, as on the login door. - (b) Charge unverifiable loopback attempts only to the global budget, or to a separate, larger budget. - (c) Keep the key cache warm from an existing console loop. (Invariant: per-IP limits keyed by the real client IP, spec §4.6.) The two P1s have different causes: P1-1 is a one-line header change, while P1-2 is a design decision. I ran the console and edge `TestDemoReport` tests and they pass. The root `TestSystemDemosReports` would not run in this sandbox: the default TMPDIR has `~/.carlos/config` above it and /var/tmp wasn't writable, and a retry under /tmp/claude was blocked by bwrap. That is an environment problem, not a code failure; the implementer reports it passing. The full review is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-2/.superpowers/sdd/2026-11-04-agent-start-demo-2-edge-protections/task-5-review-r1.md`.</result> <usage><subagent_tokens>141434</subagent_tokens><tool_uses>24</tool_uses><duration_ms>333949</duration_ms></usage> </task-notification>

Attributed to this commit: 14.8 g CO₂e (1,820,955 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on agent-start-demo-2, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/console/apidemoreports.go b/internal/console/apidemoreports.go
index 8ade96d89..60244b03a 100644
--- a/internal/console/apidemoreports.go
+++ b/internal/console/apidemoreports.go
@@ -92,7 +92,7 @@ func (s *Server) demoReportOrigin() bool {
}
func (s *Server) renderDemoReport(w http.ResponseWriter, status int, host, token, message string) {
w.Header().Set("Cache-Control", "no-store")
- w.Header().Set("Referrer-Policy", "no-referrer")
+ w.Header().Set("Referrer-Policy", "same-origin")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "DENY")
w.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'")
@@ -228,15 +228,12 @@ func (s *Server) handleAPIDemoReportResolve(w http.ResponseWriter, r *http.Reque
writeJSON(w, 200, map[string]string{"state": "resolved"})
}
-// The report door never loads keys or accepts the rollout's unsigned fallback.
-// A cold or stale cache conservatively groups loopback requests at their peer.
+// Reports share login's cached key loader, but always require a signed chain.
func (s *Server) demoReportForwardedByEdge(r *http.Request, xff string) bool {
- st := &s.edgeProof
- st.mu.Lock()
- defer st.mu.Unlock()
- now := time.Now()
- if st.at.IsZero() || now.Sub(st.at) < 0 || now.Sub(st.at) >= edgeProofKeyTTL {
+ proof := r.Header.Get(edgeproof.Header)
+ if proof == "" {
return false
}
- return edgeproof.Verify(st.current, st.next, r.Host, xff, r.Header.Get(edgeproof.Header), now)
+ current, next := s.edgeProofKeys(r.Context())
+ return edgeproof.Verify(current, next, r.Host, xff, proof, time.Now())
}
diff --git a/internal/console/authcli.go b/internal/console/authcli.go
index 46a049a3b..841e187cf 100644
--- a/internal/console/authcli.go
+++ b/internal/console/authcli.go
@@ -1205,7 +1205,8 @@ func (s *Server) clientIP(r *http.Request) string {
return s.clientIPWithProof(r, s.forwardedByEdge)
}
-// Report requests use cached proof keys, so resolving an IP cannot read storage.
+// clientIPWithProof shares proxy selection while letting reports require a proof
+// even before login has closed its unsigned-forwarding rollout window.
func (s *Server) clientIPWithProof(r *http.Request, verify func(*http.Request, string) bool) string {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
diff --git a/internal/console/demo_reports_browser_test.go b/internal/console/demo_reports_browser_test.go
new file mode 100644
index 000000000..861b200a2
--- /dev/null
+++ b/internal/console/demo_reports_browser_test.go
@@ -0,0 +1,229 @@
+package console
+
+import (
+ "crypto/sha256"
+ "crypto/x509"
+ "encoding/base64"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "golang.org/x/net/websocket"
+)
+
+// Follows internal/edge/demo_banner_browser_test.go's opt-in CDP harness.
+func TestDemoReportBrowser(t *testing.T) {
+ if os.Getenv("CARLOS_DEMO_BROWSER_TESTS") != "1" {
+ t.Skip("set CARLOS_DEMO_BROWSER_TESTS=1 to run installed Chromium via CDP")
+ }
+ if _, err := os.Stat("/usr/bin/chromium"); err != nil {
+ t.Fatalf("Chromium required: %v", err)
+ }
+ if tmp := os.Getenv("TMPDIR"); tmp == "" || filepath.Clean(tmp) == "/tmp" {
+ t.Fatal("set TMPDIR to disk scratch before browser tests")
+ }
+ // Keep Chromium's Unix socket path below the platform length limit.
+ scratch, err := os.MkdirTemp(os.Getenv("TMPDIR"), "dr-")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = os.RemoveAll(scratch) })
+ s, d := reportFixture(t)
+ posts := make(chan http.Header, 1)
+ site := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method == http.MethodPost && r.URL.Path == "/demo/report" {
+ select {
+ case posts <- r.Header.Clone():
+ default:
+ t.Error("unexpected extra report submission")
+ }
+ }
+ s.mux.ServeHTTP(w, r)
+ }))
+ defer site.Close()
+ parsed, err := url.Parse(site.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s.cfg.Origin = "https://console.example.com:" + parsed.Port()
+ cert, err := x509.ParseCertificate(site.TLS.Certificates[0].Certificate[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ spki := sha256.Sum256(cert.RawSubjectPublicKeyInfo)
+ profile := filepath.Join(scratch, "chromium")
+ browser := exec.Command("/usr/bin/chromium", "--headless", "--no-sandbox", "--disable-gpu", "--no-first-run", "--no-default-browser-check", "--disable-background-networking", "--disable-component-update", "--disable-sync", "--disable-default-apps", "--no-proxy-server", "--remote-debugging-address=127.0.0.1", "--remote-debugging-port=0", "--remote-allow-origins=http://127.0.0.1", "--host-resolver-rules=MAP console.example.com 127.0.0.1, MAP * ~NOTFOUND", "--ignore-certificate-errors-spki-list="+base64.StdEncoding.EncodeToString(spki[:]), "--user-data-dir="+profile, "about:blank")
+ browser.Env = []string{"PATH=" + os.Getenv("PATH"), "HOME=" + scratch, "TMPDIR=" + scratch}
+ reportBrowserProcess(t, browser, filepath.Join(scratch, "chromium.log"))
+ var port string
+ deadline := time.Now().Add(15 * time.Second)
+ for {
+ b, err := os.ReadFile(filepath.Join(profile, "DevToolsActivePort"))
+ if err == nil {
+ port = strings.Split(string(b), "\n")[0]
+ break
+ }
+ if time.Now().After(deadline) {
+ b, _ := os.ReadFile(filepath.Join(scratch, "chromium.log"))
+ t.Fatalf("Chromium startup: %s", b)
+ }
+ time.Sleep(20 * time.Millisecond)
+ }
+ client := &http.Client{Timeout: 5 * time.Second, Transport: &http.Transport{Proxy: nil}}
+ defer client.CloseIdleConnections()
+ response, err := client.Get("http://127.0.0.1:" + port + "/json/list")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var tabs []struct {
+ Type string `json:"type"`
+ URL string `json:"webSocketDebuggerUrl"`
+ }
+ err = json.NewDecoder(response.Body).Decode(&tabs)
+ response.Body.Close()
+ if err != nil {
+ t.Fatal(err)
+ }
+ wsURL := ""
+ for _, tab := range tabs {
+ if tab.Type == "page" {
+ wsURL = tab.URL
+ break
+ }
+ }
+ ws, err := websocket.Dial(wsURL, "", "http://127.0.0.1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ws.Close()
+ cdp := &reportCDP{t: t, ws: ws}
+ t.Logf("Browser version: %s", cdp.call("Browser.getVersion", nil))
+ cdp.call("Page.enable", nil)
+ formURL := s.cfg.Origin + "/demo/report?host=" + url.QueryEscape(d.Host)
+ cdp.call("Page.navigate", map[string]any{"url": formURL})
+ cdp.wait(`document.readyState==='complete' && !!document.querySelector('form')`)
+ cdp.check(`document.querySelector('#details').maxLength===300 && !document.cookie.includes('__Host-carlos-demo-report')`)
+ // Submit through the browser, without supplying an Origin or a cookie.
+ cdp.eval(`document.querySelector('#details').value='界'.repeat(300); document.querySelector('form').requestSubmit(); true`)
+ cdp.wait(`!!document.querySelector('[role="status"]')`)
+ confirmation, _ := json.Marshal(demoReportCopy["sent"])
+ cdp.check(`document.querySelector('[role="status"]').textContent===` + string(confirmation))
+ select {
+ case headers := <-posts:
+ if headers.Get("Origin") != s.cfg.Origin || headers.Get("Referer") != formURL {
+ t.Fatalf("browser Origin=%q Referer=%q", headers.Get("Origin"), headers.Get("Referer"))
+ }
+ cookies := (&http.Request{Header: headers}).CookiesNamed(demoReportCookie)
+ if len(cookies) != 1 {
+ t.Fatalf("browser sent %d report cookies", len(cookies))
+ }
+ default:
+ t.Fatal("browser did not POST the form")
+ }
+ rows, _, err := s.store.ListDemoReports(t.Context(), "", 50)
+ if err != nil || len(rows) != 1 || rows[0].Host != d.Host || rows[0].Details != strings.Repeat("界", 300) {
+ t.Fatalf("browser reports=%+v error=%v", rows, err)
+ }
+ t.Log("Chromium loaded the HTTPS form, sent the exact Origin and signed cookie, and stored one 900-byte report with a rendered confirmation.")
+ t.Log("Firefox and Safari: NOT RUN, outstanding browser evidence.")
+}
+
+func reportBrowserProcess(t *testing.T, cmd *exec.Cmd, logPath string) {
+ t.Helper()
+ log, err := os.Create(logPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cmd.Stdout = log
+ cmd.Stderr = log
+ if err := cmd.Start(); err != nil {
+ log.Close()
+ t.Fatal(err)
+ }
+ done := make(chan error, 1)
+ go func() { done <- cmd.Wait() }()
+ t.Cleanup(func() {
+ _ = cmd.Process.Signal(os.Interrupt)
+ select {
+ case <-done:
+ case <-time.After(5 * time.Second):
+ _ = cmd.Process.Kill()
+ <-done
+ }
+ _ = log.Close()
+ })
+}
+
+type reportCDP struct {
+ t *testing.T
+ ws *websocket.Conn
+ id int
+}
+
+func (c *reportCDP) call(method string, params any) json.RawMessage {
+ c.t.Helper()
+ c.id++
+ _ = c.ws.SetDeadline(time.Now().Add(15 * time.Second))
+ if err := websocket.JSON.Send(c.ws, map[string]any{"id": c.id, "method": method, "params": params}); err != nil {
+ c.t.Fatal(err)
+ }
+ for {
+ var msg struct {
+ ID int `json:"id"`
+ Result json.RawMessage `json:"result"`
+ Error json.RawMessage `json:"error"`
+ }
+ if err := websocket.JSON.Receive(c.ws, &msg); err != nil {
+ c.t.Fatal(err)
+ }
+ if msg.ID == c.id {
+ if len(msg.Error) > 0 {
+ c.t.Fatalf("CDP %s: %s", method, msg.Error)
+ }
+ return msg.Result
+ }
+ }
+}
+func (c *reportCDP) eval(expression string) json.RawMessage {
+ c.t.Helper()
+ result := c.call("Runtime.evaluate", map[string]any{"expression": expression, "returnByValue": true, "awaitPromise": true})
+ var out struct {
+ Result struct {
+ Value json.RawMessage `json:"value"`
+ } `json:"result"`
+ Exception json.RawMessage `json:"exceptionDetails"`
+ }
+ if err := json.Unmarshal(result, &out); err != nil {
+ c.t.Fatal(err)
+ }
+ if len(out.Exception) > 0 {
+ c.t.Fatalf("JS %s: %s", expression, out.Exception)
+ }
+ return out.Result.Value
+}
+func (c *reportCDP) check(expression string) {
+ c.t.Helper()
+ if got := string(c.eval(expression)); got != "true" {
+ c.t.Fatalf("DOM assertion %s: %s", expression, got)
+ }
+}
+func (c *reportCDP) wait(expression string) {
+ c.t.Helper()
+ deadline := time.Now().Add(10 * time.Second)
+ for {
+ if string(c.eval(expression)) == "true" {
+ return
+ }
+ if time.Now().After(deadline) {
+ c.t.Fatalf("DOM wait: %s", expression)
+ }
+ time.Sleep(30 * time.Millisecond)
+ }
+}
diff --git a/internal/console/demo_reports_test.go b/internal/console/demo_reports_test.go
index 00819f04c..9a9a2d1d5 100644
--- a/internal/console/demo_reports_test.go
+++ b/internal/console/demo_reports_test.go
@@ -1,6 +1,7 @@
package console
import (
+ "encoding/hex"
"errors"
"fmt"
"net/http"
@@ -26,12 +27,18 @@ func reportFixture(t *testing.T) (*Server, DemoRow) {
}
func reportForm(t *testing.T, s *Server, host string) (*http.Cookie, url.Values) {
t.Helper()
- r := httptest.NewRequest("GET", "/demo/report?host="+url.QueryEscape(host), nil)
+ r := httptest.NewRequest("GET", s.cfg.Origin+"/demo/report?host="+url.QueryEscape(host), nil)
w := httptest.NewRecorder()
s.mux.ServeHTTP(w, r)
if w.Code != 200 || strings.Contains(w.Body.String(), "<script") {
t.Fatalf("form %d %s", w.Code, w.Body.String())
}
+ if got := w.Header().Get("Referrer-Policy"); got != "same-origin" {
+ t.Fatalf("form Referrer-Policy = %q, want same-origin", got)
+ }
+ if !strings.Contains(w.Body.String(), `maxlength="300"`) {
+ t.Fatal("form must bound details to 300 UTF-16 code units")
+ }
cookies := w.Result().Cookies()
if len(cookies) != 1 {
t.Fatalf("cookies %v", cookies)
@@ -43,7 +50,13 @@ func reportForm(t *testing.T, s *Server, host string) (*http.Cookie, url.Values)
return c, url.Values{"host": {host}, "category": {"phishing"}, "details": {"<script>alert(1)</script>"}, "csrf": {c.Value}}
}
func reportPost(s *Server, c *http.Cookie, v url.Values, origin, ip string) *httptest.ResponseRecorder {
- r := httptest.NewRequest("POST", "/demo/report", strings.NewReader(v.Encode()))
+ // Model a same-origin browser form submission using the document's policy.
+ page := httptest.NewRecorder()
+ s.renderDemoReport(page, 200, v.Get("host"), v.Get("csrf"), "")
+ if origin == s.cfg.Origin && page.Header().Get("Referrer-Policy") == "no-referrer" {
+ origin = "null"
+ }
+ r := httptest.NewRequest("POST", s.cfg.Origin+"/demo/report", strings.NewReader(v.Encode()))
r.RemoteAddr = ip + ":1234"
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
r.Header.Set("Origin", origin)
@@ -62,6 +75,10 @@ func TestDemoReportQueue(t *testing.T) {
if err != nil || len(rows) != 0 {
t.Fatalf("prefetch %v %v", rows, err)
}
+ var attempts int
+ if err := s.store.db.QueryRow(`SELECT count(*) FROM demo_report_attempts`).Scan(&attempts); err != nil || attempts != 0 {
+ t.Fatalf("prefetch attempts %d: %v", attempts, err)
+ }
w := reportPost(s, c, v, s.cfg.Origin, "192.0.2.1")
if w.Code != 200 || !strings.Contains(w.Body.String(), "Your report was sent to the operator.") || w.Header().Get("Location") != "" {
t.Fatalf("post %d %s", w.Code, w.Body.String())
@@ -404,14 +421,16 @@ func TestDemoReportEscapingAndUniformRefusal(t *testing.T) {
}
}
-func TestDemoReportForwardingUsesNoStorage(t *testing.T) {
+func TestDemoReportForwardingUsesSharedKeyCache(t *testing.T) {
s, d := reportFixture(t)
storage := &demoCountingStore{Store: s.cfg.Releases}
- storage.fail.Store(true)
s.cfg.Releases = storage
c, v := reportForm(t, s, d.Host)
key := []byte("0123456789abcdef0123456789abcdef")
- for i, mode := range []string{"cold", "valid", "forged", "stale", "unsigned", "wrong-host", "extra-xff"} {
+ if _, err := storage.Store.Put(t.Context(), edgeproof.MeshKeyObject, []byte(hex.EncodeToString(key)), ""); err != nil {
+ t.Fatal(err)
+ }
+ for i, mode := range []string{"unsigned", "cold", "valid", "forged", "stale-cache", "stale-proof", "wrong-host", "extra-xff"} {
now := time.Now()
xff := fmt.Sprintf("198.51.100.%d", i+1)
r := httptest.NewRequest("POST", "https://console.example.com/demo/report", strings.NewReader(v.Encode()))
@@ -427,8 +446,10 @@ func TestDemoReportForwardingUsesNoStorage(t *testing.T) {
switch mode {
case "cold":
s.edgeProof.at = time.Time{}
- case "stale":
+ case "stale-cache":
s.edgeProof.at = now.Add(-time.Minute)
+ case "stale-proof":
+ r.Header.Set(edgeproof.Header, edgeproof.Sign(key, r.Host, xff, now.Add(-2*edgeproof.Skew)))
case "forged":
r.Header.Set(edgeproof.Header, "forged")
case "unsigned":
@@ -441,7 +462,7 @@ func TestDemoReportForwardingUsesNoStorage(t *testing.T) {
s.edgeProof.mu.Unlock()
got := s.clientIPWithProof(r, s.demoReportForwardedByEdge)
want := "127.0.0.1"
- if mode == "valid" {
+ if mode == "cold" || mode == "valid" || mode == "stale-cache" {
want = xff
}
if got != want {
@@ -453,8 +474,71 @@ func TestDemoReportForwardingUsesNoStorage(t *testing.T) {
t.Fatalf("%s %d %s", mode, w.Code, w.Body.String())
}
}
- if storage.gets.Load() != 0 || storage.puts.Load() != 0 || storage.polls.Load() != 0 || storage.lists.Load() != 0 {
- t.Fatal("report touched storage")
+ // Cold and expired caches each load the current and next keys once.
+ if storage.gets.Load() != 4 || storage.puts.Load() != 0 || storage.polls.Load() != 0 || storage.lists.Load() != 0 {
+ t.Fatalf("storage: gets=%d puts=%d polls=%d lists=%d", storage.gets.Load(), storage.puts.Load(), storage.polls.Load(), storage.lists.Load())
+ }
+}
+
+func TestDemoReportForwardedClientBudgetsColdCache(t *testing.T) {
+ for _, distinct := range []bool{true, false} {
+ t.Run(fmt.Sprintf("distinct=%t", distinct), func(t *testing.T) {
+ s, d := reportFixture(t)
+ key := []byte("0123456789abcdef0123456789abcdef")
+ if _, err := s.cfg.Releases.Put(t.Context(), edgeproof.MeshKeyObject, []byte(hex.EncodeToString(key)), ""); err != nil {
+ t.Fatal(err)
+ }
+ storage := &demoCountingStore{Store: s.cfg.Releases}
+ s.cfg.Releases = storage
+ c, v := reportForm(t, s, d.Host)
+ if !s.edgeProof.at.IsZero() {
+ t.Fatal("expected cold key cache")
+ }
+ for i := 0; i < 11; i++ {
+ xff := "198.51.100.1"
+ if distinct {
+ xff = fmt.Sprintf("198.51.100.%d", i+1)
+ }
+ r := httptest.NewRequest("POST", s.cfg.Origin+"/demo/report", strings.NewReader(v.Encode()))
+ r.RemoteAddr = "127.0.0.1:1234"
+ r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ r.Header.Set("Origin", s.cfg.Origin)
+ r.Header.Set("X-Forwarded-For", xff)
+ r.Header.Set(edgeproof.Header, edgeproof.Sign(key, r.Host, xff, time.Now()))
+ r.AddCookie(c)
+ w := httptest.NewRecorder()
+ s.mux.ServeHTTP(w, r)
+ want := 200
+ if !distinct && i == 10 {
+ want = 429
+ }
+ if w.Code != want {
+ t.Fatalf("attempt %d: status %d, want %d: %s", i+1, w.Code, want, w.Body.String())
+ }
+ }
+ // Login consumes the same populated cache, with no additional load.
+ probe := httptest.NewRequest("POST", s.cfg.Origin+"/api/cli/auth/start", nil)
+ probe.RemoteAddr = "127.0.0.1:1234"
+ probe.Header.Set("X-Forwarded-For", "198.51.100.99")
+ probe.Header.Set(edgeproof.Header, edgeproof.Sign(key, probe.Host, "198.51.100.99", time.Now()))
+ if got := s.clientIP(probe); got != "198.51.100.99" {
+ t.Fatalf("login IP = %q", got)
+ }
+ var attempts, clients int
+ if err := s.store.db.QueryRow(`SELECT count(*),count(DISTINCT ip_hash) FROM demo_report_attempts`).Scan(&attempts, &clients); err != nil {
+ t.Fatal(err)
+ }
+ wantAttempts, wantClients := 10, 1
+ if distinct {
+ wantAttempts, wantClients = 11, 11
+ }
+ if attempts != wantAttempts || clients != wantClients {
+ t.Fatalf("attempts=%d clients=%d, want %d/%d", attempts, clients, wantAttempts, wantClients)
+ }
+ if storage.gets.Load() != 2 || storage.puts.Load() != 0 || storage.polls.Load() != 0 || storage.lists.Load() != 0 {
+ t.Fatalf("storage: gets=%d puts=%d polls=%d lists=%d", storage.gets.Load(), storage.puts.Load(), storage.polls.Load(), storage.lists.Load())
+ }
+ })
}
}
diff --git a/internal/console/templates/demo_report.html b/internal/console/templates/demo_report.html
index c1b6d16e2..be788db83 100644
--- a/internal/console/templates/demo_report.html
+++ b/internal/console/templates/demo_report.html
@@ -22,7 +22,7 @@
<option value="other">{{.Copy.other}}</option>
</select></p>
<p><label for="details">{{.Copy.details}}</label>
-<textarea id="details" name="details" maxlength="1000" aria-describedby="details-hint"></textarea></p>
+<textarea id="details" name="details" maxlength="300" aria-describedby="details-hint"></textarea></p>
<p id="details-hint">{{.Copy.hint}}</p>
<button type="submit">{{.Copy.submit}}</button>
</form>{{end}}