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:
@@ -1,11 +1,31 @@
|
||||
package postcard
|
||||
|
||||
import (
|
||||
"html"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
xhtml "golang.org/x/net/html"
|
||||
)
|
||||
|
||||
// scriptURLText finds a script URL in text: javascript: or vbscript: at a
|
||||
// scheme boundary, or data: at a scheme boundary directly followed by a
|
||||
// non-space character (a data URL). A boundary is the start of the text or a
|
||||
// character that cannot belong to a URL scheme, so "Metadata: Weekly" and
|
||||
// "Big Data: Summit" do not match.
|
||||
var scriptURLText = regexp.MustCompile(`(?i)(?:^|[^a-z0-9+.\-])(?:(?:javascript|vbscript):|data:\S)`)
|
||||
|
||||
// UnsafeText reports whether a text that a layout prints, such as the site
|
||||
// name of the built-in layouts, must be kept out of mail. A text is unsafe
|
||||
// when, HTML-escaped as html/template prints text, it fails the rendered-HTML
|
||||
// safety checks (for example event-handler-shaped text such as
|
||||
// "Shop onclick=x"), or when it holds a script URL: javascript: or vbscript:
|
||||
// at a scheme boundary, or a data: URL. "Big Data: Summit" is safe;
|
||||
// "javascript: Acme" is not.
|
||||
func UnsafeText(s string) bool {
|
||||
return validateHTML(html.EscapeString(s)) != nil || scriptURLText.MatchString(s)
|
||||
}
|
||||
|
||||
// urlAttributes are the attributes that hold one URL. Their decoded value is
|
||||
// refused when it starts with a script or data scheme.
|
||||
var urlAttributes = map[string]bool{
|
||||
|
||||
Reference in New Issue
Block a user