fix(35): WR-01 strip whitespace before the list, meta, CSS and comment scheme checks

Single-URL attributes removed ASCII whitespace and control characters
before looking for a scheme, the list-valued, meta content, style and
comment checks did not, so values="java	script:..." and a tab-split
meta refresh passed. The stripping is factored out as stripURLSpace and
used by every scheme check.
This commit is contained in:
Jakub Zych
2026-11-14 17:32:14 +01:00
parent 1d481bb02d
commit baba524caf
4 changed files with 36 additions and 14 deletions

View File

@@ -78,6 +78,13 @@ func TestURLSchemeCheck(t *testing.T) {
{"xmp_href", `<xmp><a href="javascript:alert(1)">x</a></xmp>`, `href="javascript:alert(1)"`, schemeMsg},
{"self_closing_style", `<style/><a href="javascript&#58;alert(1)">x</a>`, `javascript&#58;alert(1)`, schemeMsg},
{"conditional_comment_handler", `<!--[if mso]><img src="x.png" onerror="alert(1)"><![endif]-->`, `onerror="alert(1)"`, "event handlers"},
// Whitespace-split schemes in list, meta, CSS and comment values
// (WR-01).
{"values_tab_split", `<svg><a><animate attributeName="href" values="java&#9;script:alert(1)"/><text>x</text></a></svg>`, `values="java&#9;script:alert(1)"`, schemeMsg},
{"meta_refresh_tab_split", `<meta http-equiv="refresh" content="0;url=java&#9;script:alert(1)">`, `url=java&#9;script:alert(1)`, schemeMsg},
{"srcset_newline_split", `<img src="a.png" srcset="a.png 1x, java&#10;script:x 2x">`, `java&#10;script:x 2x`, schemeMsg},
{"style_tab_split", `<div style="background:url(java&#9;script:x)">x</div>`, `url(java&#9;script:x)`, schemeMsg},
{"style_element_space_split", "<style>td { background: url(java\tscript:x); }</style>", "url(java script:x)", schemeMsg},
{"nested_too_deep", strings.Repeat("<noscript>", maxMarkupDepth+2) + "x", "<noscript>", "too deeply"},
}
for _, tc := range refuses {