fix(35): WR-02 drop the whole-document event-handler regex

validateHTML ran (?i)\son[a-z]+\s*= over the rendered document, text
included, so a variable such as "buy one = get one free" stopped its own
message, and it is what made Online=Shop in the footer a send failure.
The tokenizer walk refuses every on* attribute, and since CR-02 it also
reads raw-text element and comment content as markup, so the regex is
dropped. Text shaped like a handler is now sent; such site names are shown
and saved, and the Branding refusal copy no longer mentions onclick=.
This commit is contained in:
Jakub Zych
2026-11-14 17:37:52 +01:00
parent baba524caf
commit 31de2ff90f
11 changed files with 79 additions and 59 deletions

View File

@@ -46,7 +46,6 @@ var (
// unsafeMarkup applies it to CSS (style attributes and style elements),
// list-valued URL attributes, meta content and comments, never to text.
dangerousScheme = regexp.MustCompile(`(?i)(?:javascript|vbscript|data):`)
eventHandler = regexp.MustCompile(`(?i)\son[a-z]+\s*=`)
rawUnsafeTag = regexp.MustCompile(`(?i)<(?:script|iframe|object|embed)\b`)
markdown = goldmark.New()
@@ -819,17 +818,15 @@ func markdownHTML(src string) (string, error) {
}
// validateHTML is the safety check of rendered HTML. Raw unsafe tags
// (script, iframe, object, embed) and whitespace-prefixed on* attributes are
// found in the raw markup; unsafeMarkup then reads the decoded attribute
// values, style elements and comments for event handlers and script or data
// URLs. Text content is not a URL and is not checked for schemes.
// (script, iframe, object, embed) are found in the raw markup; unsafeMarkup
// then reads the attributes, style elements, comments and raw-text element
// content for event handlers (any attribute whose name starts with "on")
// and script or data URLs. Text content is neither markup nor a URL, so
// prose such as "buy one = get one free" or "metadata:" is not refused.
func validateHTML(html string) error {
if loc := rawUnsafeTag.FindStringIndex(html); loc != nil {
return &unsafeError{msg: "rendered HTML contains raw unsafe tags", snippet: snippetAt(html, loc)}
}
if loc := eventHandler.FindStringIndex(html); loc != nil {
return &unsafeError{msg: "rendered HTML contains event handlers", snippet: snippetAt(html, loc)}
}
return unsafeMarkup(html)
}