oficina / fichas Public

Preserve source origin on the contract release form

Paul Campbell pushed by paul@keymail.dev 92bd3cd29b7fb5232f9d1e096f058cc512ae0d64 parent 14b9dce
2 files changed, +6 −0
  • internal/fichas/contract_release.go +3 −0
  • internal/fichastest/contract_test.go +3 −0

CI passed — run details

diff --git a/internal/fichas/contract_release.go b/internal/fichas/contract_release.go
index 6469b11..e717030 100644
--- a/internal/fichas/contract_release.go
+++ b/internal/fichas/contract_release.go
@@ -86,6 +86,9 @@ func (a *app) contractPage(w http.ResponseWriter, r *http.Request, p contractRel
p.Destination = a.cfg.ContractRelease.Destination
p.Importer = a.cfg.ContractRelease.Importer
if p.Phase == "send" {
+ // A no-referrer policy makes a cross-origin POST carry Origin: null.
+ // Docs requires our exact origin; disclose only the origin, never the path.
+ w.Header().Set("Referrer-Policy", "strict-origin")
// Scope the exact destination to this single outbound form page.
policy := w.Header().Get("Content-Security-Policy")
if strings.Contains(policy, "form-action 'self'") {
diff --git a/internal/fichastest/contract_test.go b/internal/fichastest/contract_test.go
index 9ce153e..0429110 100644
--- a/internal/fichastest/contract_test.go
+++ b/internal/fichastest/contract_test.go
@@ -125,6 +125,9 @@ func TestContractReleaseThroughRealAdmission(t *testing.T) {
if !strings.Contains(w.Header().Get("Content-Security-Policy"), "form-action 'self' "+cfg.ContractRelease.Destination) {
t.Fatal("browser would block outbound form")
}
+ if got := w.Header().Get("Referrer-Policy"); got != "strict-origin" {
+ t.Fatalf("outbound form must preserve Origin without leaking paths: %q", got)
+ }
// A field definition change without a card revision change still invalidates approval.
var def fichas.FieldDef
if e = d.G.Where("key = ?", fichas.FieldName).First(&def).Error; e != nil {