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:
@@ -1800,11 +1800,16 @@ func (MailBrandSetting) Rules() map[string]string {
|
||||
|
||||
var brandColourPattern = regexp.MustCompile(`^#[0-9a-f]{6}$`)
|
||||
|
||||
// BeforeValidate trims the site name, lower-cases colours, refuses anything
|
||||
// but #rrggbb or empty, and checks logo_file_id is null or a library image.
|
||||
// BeforeValidate trims the site name and refuses a name mail could not show
|
||||
// (postcard's UnsafeText), lower-cases colours, refuses anything but #rrggbb
|
||||
// or empty, and checks logo_file_id is null or a library image. One refusal
|
||||
// lists every field at fault.
|
||||
func (b *MailBrandSetting) BeforeValidate(tx *gorm.DB) error {
|
||||
b.SiteName = strings.TrimSpace(b.SiteName)
|
||||
details := map[string]any{}
|
||||
if postcard.UnsafeText(b.SiteName) {
|
||||
details["site_name"] = []string{"backend::lang.mail.brand.site_name_unsafe"}
|
||||
}
|
||||
for _, col := range []struct {
|
||||
name string
|
||||
value *string
|
||||
|
||||
Reference in New Issue
Block a user