fix(postcard,cabana): unsafe site names never stop a send and are refused at save
- postcard.UnsafeText: a text a layout prints is unsafe when, escaped,
it fails the rendered-HTML checks or holds a script or data URL at a
scheme boundary ("Big Data: Summit" is safe)
- siteNameFrom/layoutSiteName: an unsafe Branding name falls back to the
mail.from display name, an unsafe one of those gives no name; one
rate-limited warning per source (site_name:branding, site_name:mail.from),
never the value; file version, override, fallback and editor alike
- the Branding preview of an unsafe draft name renders without it
- MailBrandSetting.BeforeValidate: 422 on site_name with
backend::lang.mail.brand.site_name_unsafe (en/pl)
- settings Put localizes a BeforeValidate refusal's phrase keys, as a
controller save does
- TestMailSafetySmoke/unsafe_site_name, TestMailBrandSiteName/unsafe_name_refused
This commit is contained in:
@@ -89,6 +89,31 @@ 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_refused", func(t *testing.T) {
|
||||
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "Acme Mail"})
|
||||
// A name mail could not show is refused on the field; nothing is stored.
|
||||
env.expectFieldRefusal(t, http.StatusUnprocessableEntity, http.MethodPut, mailBrandPath, root,
|
||||
map[string]any{"site_name": "javascript: Acme"}, "site_name", "cannot be shown in mail", false)
|
||||
var stored cabana.MailBrandSetting
|
||||
if err := env.gdb.First(&stored, 1).Error; err != nil || stored.SiteName != "Acme Mail" {
|
||||
t.Fatalf("refused save changed the row: %+v err=%v", stored, err)
|
||||
}
|
||||
// The preview of the unsaved draft renders without the name.
|
||||
if html := brandPreview(t, env, root, map[string]any{"site_name": "javascript: Acme"}); strings.Contains(html, "javascript:") {
|
||||
t.Errorf("the preview shows the unsafe name:\n%s", html)
|
||||
}
|
||||
// Prose with a colon is a name like any other.
|
||||
env.expect(t, http.StatusOK, http.MethodPut, mailBrandPath, root, map[string]any{"site_name": "Big Data: Summit"})
|
||||
tmplID := env.mailRowID(t, postcard.TemplatesTable, blogWelcome)
|
||||
defaultID := env.mailRowID(t, postcard.LayoutsTable, "postcard::mail.layouts.default")
|
||||
env.expect(t, http.StatusOK, http.MethodPut, fmt.Sprintf("%s/%d", mailTemplatesPath, tmplID), root, templateBody("Witaj, {{ .name }}", "Cześć **{{ .name }}**.", defaultID))
|
||||
got := sendGrace(t, env, blogWelcome)
|
||||
if m := headerSpan.FindStringSubmatch(got.HTML); m == nil || m[1] != "Big Data: Summit" {
|
||||
t.Errorf("sent header does not show the saved site name:\n%s", got.HTML)
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user