fix(postcard): check URL schemes in decoded attribute values, not in text

- validateHTML keeps the raw tag and handler regexes and reads the rest
  through unsafeMarkup: x/net/html tokenizer, decoded attribute values,
  prefix check on URL attributes, whole-value check on CSS, list
  attributes, meta content and comments; any on* attribute is refused
- text is not a URL: "Metadata: Weekly" or "Big Data: Summit" as a site
  name or body text no longer stops a send (CR-01)
- entity-encoded javascript: is refused whether or not the layout
  opts out of inlining (WR-05)
- draft layout CSS is checked as a style element
- fixtures that pinned prose as unsafe now carry markup-level URLs;
  the 35-07 subtest pinning an unsafe stored name is removed
- TestMailSafetySmoke prose_site_name and encoded_scheme
This commit is contained in:
Jakub Zych
2026-11-14 15:13:35 +01:00
parent 274dff4458
commit 13ab905f8d
11 changed files with 277 additions and 35 deletions

View File

@@ -89,18 +89,6 @@ func TestMailBrandSiteName(t *testing.T) {
t.Errorf("a send without a site name, a logo or a mail.from name has a header row:\n%s", got.HTML)
}
})
t.Run("unsafe_name_current_behaviour", func(t *testing.T) {
// Open item (35-06 threat flag): the site name is not checked for a
// URL scheme at save time. It is stored as typed; the rendered
// header then fails the safety check, so the preview refuses it.
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "javascript: Acme"})
rec := env.call(t, http.MethodPost, "/mail/preview", root, map[string]any{"mode": "branding", "id": 0, "values": map[string]any{"site_name": "javascript: Acme"}})
if rec.Code != http.StatusUnprocessableEntity {
t.Errorf("preview of an unsafe site name: status %d, want 422 (%s)", rec.Code, rec.Body.String())
}
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": ""})
})
}
// inlineLayoutFiles is the blog fixture whose blog layout carries a style