Send Base's origin on the handoff POST
The handoff page used Referrer-Policy: no-referrer, which makes browsers send Origin: null on the cross-origin POST to the app's /auth/assertion, so an app checking Origin against Base's origin would refuse it. Use Referrer-Policy: origin on the header and the meta tag (R21): Base's origin is sent, the path and query carrying the nonce are not.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+13
−4
internal/issuer/issuer.go+5 −1internal/issuer/issuer_test.go+7 −2internal/issuer/templates/handoff.html+1 −1
diff --git a/internal/issuer/issuer.go b/internal/issuer/issuer.go| index 8caf57c..79cdaef 100644 |
| --- a/internal/issuer/issuer.go |
| +++ b/internal/issuer/issuer.go |
| @@ -148,7 +148,11 @@ func (s *issuer) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| name = e.Name |
| } |
| h := w.Header() |
| - h.Set("Referrer-Policy", "no-referrer") |
| + // origin, not no-referrer: a cross-origin POST under no-referrer carries |
| + // Origin: null, and the app accepts the assertion only when Origin is |
| + // exactly Base's origin. origin still withholds the path and query, |
| + // which carry the nonce (R21). |
| + h.Set("Referrer-Policy", "origin") |
| h.Set("Content-Security-Policy", handoffCSP(aud)) |
| if err := s.pages.Page(w, "handoff", handoff{AppName: name, Action: aud + "/auth/assertion", Assertion: token}); err != nil { |
| s.fail(w, app, err) |
diff --git a/internal/issuer/issuer_test.go b/internal/issuer/issuer_test.go| index fbd83bb..c0bcca8 100644 |
| --- a/internal/issuer/issuer_test.go |
| +++ b/internal/issuer/issuer_test.go |
| @@ -301,8 +301,13 @@ func TestAuthorizeSignsForInstalledApp(t *testing.T) { |
| if got := page.Header.Get("Cache-Control"); got != "no-store" { |
| t.Errorf("Cache-Control %q", got) |
| } |
| - if got := page.Header.Get("Referrer-Policy"); got != "no-referrer" { |
| - t.Errorf("Referrer-Policy %q", got) |
| + // origin, not no-referrer: the app checks that the POST's Origin is Base, |
| + // and no-referrer would make browsers send Origin: null (R21). |
| + if got := page.Header.Get("Referrer-Policy"); got != "origin" { |
| + t.Errorf("Referrer-Policy %q, want origin", got) |
| + } |
| + if metas := regexp.MustCompile(`<meta name="referrer"[^>]*>`).FindAllString(page.Body, -1); len(metas) != 1 || metas[0] != `<meta name="referrer" content="origin">` { |
| + t.Errorf("referrer meta: %q", metas) |
| } |
| if got := page.Header.Values("Content-Security-Policy"); len(got) != 1 || got[0] != handoffCSP { |
| t.Errorf("CSP %q, want %q", got, handoffCSP) |
diff --git a/internal/issuer/templates/handoff.html b/internal/issuer/templates/handoff.html| index d0dd307..13ffc0f 100644 |
| --- a/internal/issuer/templates/handoff.html |
| +++ b/internal/issuer/templates/handoff.html |
| @@ -1,5 +1,5 @@ |
| {{define "title"}}Taking you to {{.AppName}}{{end}} |
| -{{define "head"}}<meta name="referrer" content="no-referrer"> |
| +{{define "head"}}{{/* origin, not no-referrer: the app needs Origin to be Base's origin, never null; see issuer.go (R21). */}}<meta name="referrer" content="origin"> |
| <script defer src="{{asset "static/handoff.js"}}"></script>{{end}} |
| {{define "main"}}<main class="signin"> |
| <div class="card glass"> |