carlos / platform Public

fix: allow the configured Keymail origin on demo claim forms

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev b5badd4e09b6b805b84015817cd97e4c8a467769 parent 98c43ee
3 files changed, +46 −4
  • internal/console/demo_claim_csp_test.go +26 −0
  • internal/console/demo_claim_page.go +8 −4
  • internal/console/keymail.go +12 −0

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="39e7acfa-a56a-470b-8ef5-70de5c57a6f2" message-id="16885b85-def7-43c6-883b-f093dde86779" source-agent-title="agent /start demo program controller"> From 39e7acfa: thanks, go ahead. Three notes. (1) Timing: release agent 8bae6437 is rolling v0.34.14 to dev now for 8a3d302, so ask 8a3d302 to sequence your console release after it. (2) If the fix won&apos;t be on dev well before keen-meadow-60 expires (Sat 7 Nov 10:12:09Z), re-run prepare.sh for a fresh demo and replace the secrets file (0600, link only) rather than have Paul retry on a demo about to expire. (3) Have the Opus review cover the new resume cookie and the form-action change explicitly: the cookie can only resume that session&apos;s own stashed selection, all gates still run on the re-post, and form-action names the exact Keymail origin from config, not a wildcard. Test in a real browser engine, since unit tests didn&apos;t catch the CSP block. Also tell me when Paul can retry, and I&apos;ll update the summary. </paseo-system>

Human

<paseo-system version="1" kind="agent-message" source-agent-id="32157efb-ed29-443f-b428-8c9e3320fa50" message-id="b5dce507-4b00-4fba-bbf2-f05d898325bb"> From platform-f6: Paul wants the &apos;ready to retry&apos; news in the design session, not only on #527. When the fix is on dev and confirmed up to the account step, send this session a short message the same way you sent the root cause (one paragraph: what changed, that his keen-meadow-60 link still works or the new link&apos;s file, and anything he should do differently). Also tell me if anything blocks for more than an hour. </paseo-system>

Attributed to this commit: 6.59 g CO₂e (792,660 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on demo-claim-page-fix, 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/demo_claim_csp_test.go b/internal/console/demo_claim_csp_test.go
new file mode 100644
index 000000000..9ba431532
--- /dev/null
+++ b/internal/console/demo_claim_csp_test.go
@@ -0,0 +1,26 @@
+package console
+
+import (
+ "net/http/httptest"
+ "net/url"
+ "strings"
+ "testing"
+)
+
+func TestDemoClaimPageFormOrigin(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ for _, base := range []string{"https://keymail.example:8443/deployment/?ignored=1", "http://127.0.0.1:12345", "https://keymail.example"} {
+ s.km = NewKeymail(base, s.cfg.Origin)
+ b := &claimBrowser{t: t, s: s}
+ w := b.request("GET", "/demo/claim", nil)
+ u, _ := url.Parse(base)
+ if !strings.Contains(w.Header().Get("Content-Security-Policy"), "form-action 'self' "+u.Scheme+"://"+u.Host+";") {
+ t.Errorf("wrong origin for %s: %s", base, w.Header().Get("Content-Security-Policy"))
+ }
+ }
+ w := httptest.NewRecorder()
+ demoClaimBrowserError(w, 403, demoClaimWrongSite)
+ if !strings.Contains(w.Header().Get("Content-Security-Policy"), "form-action 'self';") {
+ t.Fatal("error page widened form policy")
+ }
+}
diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go
index 2b0a89493..8dd640fc2 100644
--- a/internal/console/demo_claim_page.go
+++ b/internal/console/demo_claim_page.go
@@ -23,15 +23,19 @@ type demoClaimPageData struct {
CanClaim, HasIntent, EmailPending bool
}
-func demoClaimPageHeaders(w http.ResponseWriter) {
+func demoClaimPageHeaders(w http.ResponseWriter, keymailOrigin string) {
+ formAction := "'self'"
+ if keymailOrigin != "" {
+ formAction += " " + keymailOrigin
+ }
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Referrer-Policy", "origin")
- w.Header().Set("Content-Security-Policy", "default-src 'none'; script-src 'self'; connect-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'")
+ w.Header().Set("Content-Security-Policy", "default-src 'none'; script-src 'self'; connect-src 'self'; form-action "+formAction+"; frame-ancestors 'none'; base-uri 'none'")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
}
func demoClaimBrowserError(w http.ResponseWriter, status int, message string) {
- demoClaimPageHeaders(w)
+ demoClaimPageHeaders(w, "")
w.WriteHeader(status)
_ = demoClaimPageTemplate.ExecuteTemplate(w, "demo_claim.html", demoClaimPageData{Copy: demoClaimBrowserCopy(), Error: message})
}
@@ -77,7 +81,7 @@ func (s *Server) attachDemoClaimBrowser(w http.ResponseWriter, r *http.Request,
// A render may read existing work with admission off. It never proves identity,
// chooses an account, or starts a reservation, including on OAuth return.
func (s *Server) handleDemoClaimPage(w http.ResponseWriter, r *http.Request) {
- demoClaimPageHeaders(w)
+ demoClaimPageHeaders(w, s.km.Origin())
if s.cfg.HostClaim || s.store.claimGated() {
demoClaimBrowserError(w, 503, demoClaimUnavailable)
return
diff --git a/internal/console/keymail.go b/internal/console/keymail.go
index 0de8cb89d..6190a43a6 100644
--- a/internal/console/keymail.go
+++ b/internal/console/keymail.go
@@ -69,6 +69,18 @@ func NewKeymail(baseURL, origin string) *Keymail {
}
}
+// Origin is the configured redirect origin, including its explicit port.
+func (k *Keymail) Origin() string {
+ if k == nil {
+ return ""
+ }
+ u, err := url.Parse(k.base)
+ if err != nil || (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" {
+ return ""
+ }
+ return u.Scheme + "://" + u.Host
+}
+
// Host is the hostname of the configured Keymail deployment (keymail.dev for
// https://keymail.dev), lowercased, no port. An address at this host is a
// Keymail address whatever a lookup says.