fix(postcard): an inlined result that fails the safety check sends the style block
- inlineHTML treats a failing post-inline check like an inliner error: the un-inlined HTML, which already passed validateHTML, is sent with its style block and the rate-limited inline:<layout> warning - mail is never stopped by the inliner, as the docs promise (WR-05) - README and docs/services/mail.md describe the check before inlining - TestMailSafetySmoke/inline_unsafe_output
This commit is contained in:
@@ -727,10 +727,11 @@ var styleElement = regexp.MustCompile(`(?i)<style[\s>]`)
|
||||
|
||||
// inlineHTML copies the CSS of a rendered message onto its elements. HTML
|
||||
// without a style element has nothing to inline and is returned as it is.
|
||||
// An inliner error keeps html as it is, with its style block, and is
|
||||
// reported through opts.warn; mail is never stopped by it. The inlined HTML
|
||||
// passes the safety checks again, since CSS values now sit in style
|
||||
// attributes.
|
||||
// Mail is never stopped by the inliner: an inliner error, or inlined HTML
|
||||
// that fails the safety checks, keeps html as it is, with its style block,
|
||||
// and is reported through opts.warn. Sending html is safe: it already passed
|
||||
// validateHTML in renderParts, which reads decoded attribute values and the
|
||||
// CSS of style elements whether or not the layout opts out of inlining.
|
||||
func inlineHTML(html, layout string, opts renderOptions) (string, error) {
|
||||
if !styleElement.MatchString(html) {
|
||||
return html, nil
|
||||
@@ -748,7 +749,11 @@ func inlineHTML(html, layout string, opts renderOptions) (string, error) {
|
||||
return html, nil
|
||||
}
|
||||
if err := validateHTML(inlined); err != nil {
|
||||
return "", err
|
||||
if opts.warn != nil {
|
||||
opts.warn("inline:"+layout, "postcard: inlined CSS failed the safety check, sending the style block only",
|
||||
"layout", layout, "error", err.Error())
|
||||
}
|
||||
return html, nil
|
||||
}
|
||||
return inlined, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user