fix(35): WR-03 treat data: in a site name as a data URL only with ; or ,
scriptURLText took data: followed by any non-space character as a data URL, so names such as Data:Lab, Big Data:Summit and data:Science were refused on the Branding form and dropped from mail, contrary to the docs. A data URL now needs its optional MIME type and the ; or , every data URL has. javascript: and vbscript: keep matching with whitespace after the colon, since such a URL still runs.
This commit is contained in:
@@ -9,19 +9,23 @@ import (
|
||||
)
|
||||
|
||||
// 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)`)
|
||||
// scheme boundary (whitespace may follow the colon of a script URL, so
|
||||
// "javascript: Acme" matches), or a data URL: data: at a scheme boundary,
|
||||
// then an optional MIME type and the ";" or "," every data URL has
|
||||
// ("data:text/html,x", "data:,x"). A boundary is the start of the text or a
|
||||
// character that cannot belong to a URL scheme, so "Metadata: Weekly" does
|
||||
// not match; nor do "Big Data: Summit" and "Data:Lab", which are no data
|
||||
// URLs.
|
||||
var scriptURLText = regexp.MustCompile(`(?i)(?:^|[^a-z0-9+.\-])(?:(?:javascript|vbscript):|data:\s*(?:[a-z]+/[a-z0-9.+\-]+\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 in the places the built-in layouts print it, or when it holds
|
||||
// a script URL: javascript: or vbscript: at a scheme boundary, or a data:
|
||||
// URL. Escaped text is never markup, so "Big Data: Summit", "Online=Shop" and
|
||||
// "Shop onclick=x" are safe; "javascript: Acme" is not.
|
||||
// URL. Escaped text is never markup, so "Big Data: Summit", "Data:Lab",
|
||||
// "Online=Shop" and "Shop onclick=x" are safe; "javascript: Acme" and
|
||||
// "data:text/html,x" are not.
|
||||
func UnsafeText(s string) bool {
|
||||
return validateHTML(printContext(html.EscapeString(s))) != nil || scriptURLText.MatchString(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user