fix(35): CR-01 check the site name where the layouts print it
UnsafeText checked the escaped name on its own, so a name starting with on<letters>= (Online=Shop, onboarding=team) passed, was saved, and then failed every default/system-layout send once the footer printed it after "© <year> ". The name is now checked in the footer, header span and alt contexts, so such a name is dropped at render and refused on the Branding form instead of stopping mail.
This commit is contained in:
@@ -18,12 +18,22 @@ var scriptURLText = regexp.MustCompile(`(?i)(?:^|[^a-z0-9+.\-])(?:(?:javascript|
|
||||
// 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;
|
||||
// safety checks in the places the built-in layouts print it (for example
|
||||
// event-handler-shaped text such as "Shop onclick=x", or "Online=Shop" after
|
||||
// the footer's "© <year> "), 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)
|
||||
return validateHTML(printContext(html.EscapeString(s))) != nil || scriptURLText.MatchString(s)
|
||||
}
|
||||
|
||||
// printContext is the markup the built-in layouts print an escaped site name
|
||||
// in: after "© <year> " in the footer paragraph, in the header's span and in
|
||||
// the logo's alt attribute. A text is checked there, not on its own, so a
|
||||
// check that depends on what precedes the text (a whitespace-prefixed
|
||||
// handler) sees what a send renders.
|
||||
func printContext(esc string) string {
|
||||
return "<p>© 2000 " + esc + "</p><span>" + esc + "</span><img alt=\"" + esc + "\">"
|
||||
}
|
||||
|
||||
// urlAttributes are the attributes that hold one URL. Their decoded value is
|
||||
|
||||
Reference in New Issue
Block a user