fix(35): WR-02 drop the whole-document event-handler regex

validateHTML ran (?i)\son[a-z]+\s*= over the rendered document, text
included, so a variable such as "buy one = get one free" stopped its own
message, and it is what made Online=Shop in the footer a send failure.
The tokenizer walk refuses every on* attribute, and since CR-02 it also
reads raw-text element and comment content as markup, so the regex is
dropped. Text shaped like a handler is now sent; such site names are shown
and saved, and the Branding refusal copy no longer mentions onclick=.
This commit is contained in:
Jakub Zych
2026-11-14 17:37:52 +01:00
parent baba524caf
commit 31de2ff90f
11 changed files with 79 additions and 59 deletions

View File

@@ -82,19 +82,12 @@ func TestMailSiteNameSafety(t *testing.T) {
if got := storedSiteName(t, env); got != "Acme Mail" {
t.Fatalf("the refused pl save stored site_name %q", got)
}
// A name unsafe only where the layouts print it, after the footer's
// "© <year> ", is refused as well (CR-01 residual).
for _, name := range []string{"Online=Shop", "onboarding=team"} {
env.expectFieldRefusal(t, http.StatusUnprocessableEntity, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": name}, "site_name", "cannot be shown in mail", false)
if got := storedSiteName(t, env); got != "Acme Mail" {
t.Fatalf("the refused save of %q stored site_name %q", name, got)
}
}
})
t.Run("prose_names_saved", func(t *testing.T) {
for _, name := range []string{"Big Data: Summit", "Metadata: Weekly"} {
// Text shaped like an event handler is text, also after the footer's
// "© <year> " (CR-01 residual, WR-02).
for _, name := range []string{"Big Data: Summit", "Metadata: Weekly", "Online=Shop", "onboarding=team"} {
saved := env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": name})
if got := dataOf(saved)["data"].(map[string]any)["site_name"]; got != name {
t.Errorf("response site_name = %#v, want %q", got, name)
@@ -106,6 +99,19 @@ func TestMailSiteNameSafety(t *testing.T) {
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "Acme Mail"})
})
t.Run("handler_shaped_name_sends", func(t *testing.T) {
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "Online=Shop"})
t.Cleanup(func() {
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "Acme Mail"})
})
for _, layout := range []string{mailDefaultLayout, mailSystemLayout} {
got := moveWelcome(t, env, root, layout)
if !strings.Contains(got.HTML, "Online=Shop</p>") || !strings.Contains(got.Text, "Online=Shop") {
t.Errorf("%s: the footer does not show the saved name:\n%s\n%s", layout, got.HTML, got.Text)
}
}
})
t.Run("preview_drops_unsafe_name", func(t *testing.T) {
html := brandPreview(t, env, root, map[string]any{"site_name": "javascript: Acme"})
if strings.Contains(html, "javascript:") {