fix(17): CR-01 refuse non-http sitemap URLs on save, import and output
A url item stored as javascript://%0aalert(1)%0a//x passed Url::to and reached <loc>, which sitemap.xsl renders as a link on the site origin. - The definitions form refuses, per row, a url that is not a path or an http(s) URL (classes.AllowedItemURL) and a urlPattern that is not a path (signpost.ValidItemPattern), keyed data.<i>.url / .urlPattern. - Generator.addItem drops a loc or alternate that is not http(s). - sitemap:import-winter drops such url items and clears such patterns with a report line; sitemap:import refuses such an entry.
This commit is contained in:
@@ -55,3 +55,30 @@ func TestURLTo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestAllowedItemURL pins the save rule of a url item's address (CR-01).
|
||||
func TestAllowedItemURL(t *testing.T) {
|
||||
for u, want := range map[string]bool{
|
||||
"": true,
|
||||
"/": true,
|
||||
"/about": true,
|
||||
"about/team?x=1": true,
|
||||
"https://example.test/a": true,
|
||||
"HTTP://example.test/a": true,
|
||||
"javascript://%0aalert(1)%0a//x": false,
|
||||
"javascript:alert(1)": false,
|
||||
"data:text/html,x": false,
|
||||
"mailto:a@example.test": false,
|
||||
"//evil.test/x": false,
|
||||
`/\evil.test/x`: false,
|
||||
`\\evil.test`: false,
|
||||
"#top": false,
|
||||
" /about": false,
|
||||
"/about\n": false,
|
||||
"java\tscript:alert(1)": false,
|
||||
} {
|
||||
if got := classes.AllowedItemURL(u); got != want {
|
||||
t.Errorf("AllowedItemURL(%q) = %v, want %v", u, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user