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:
2026-10-12 21:28:28 +02:00
parent 4e55939a1f
commit c42bc265c8
12 changed files with 257 additions and 11 deletions

View File

@@ -164,6 +164,31 @@ func TestImportWinter(t *testing.T) {
}
})
t.Run("url and pattern checks", func(t *testing.T) {
bad := writeFile(t, dir, "bad-urls.jsonl", row(7, "t", `[{"type":"url","url":"javascript://%0aalert(1)%0a//x"},`+
`{"type":"url","url":"/ok"},`+
`{"type":"acme-post","reference":"7","urlPattern":"//evil.test/:slug"}]`))
report, out, err := run(console.WinterOptions{DefinitionsFile: bad, Force: true})
if err != nil {
t.Fatalf("import: %v\n%s", err, out)
}
if report.Kept != 2 || report.Dropped != 1 {
t.Fatalf("report = %+v\n%s", report, out)
}
for _, line := range []string{
"item 0 (type 'url', url 'javascript://%0aalert(1)%0a//x'): dropped (the url is not a path or an http(s) URL)",
"item 2 (type 'acme-post', reference '7'): urlPattern '//evil.test/:slug' cleared (not a path starting with a single /)",
} {
if !strings.Contains(out, line) {
t.Errorf("output lacks %q:\n%s", line, out)
}
}
got := stored(t)
if len(got) != 2 || models.Text(got[0].URL) != "/ok" || got[1].URLPattern != nil {
t.Fatalf("stored = %+v", got)
}
})
t.Run("settings upsert", func(t *testing.T) {
first := writeFile(t, dir, "settings.json", `{"frontend_url":"https://www.example.test","enable_priority_tiers":"1","priority_blog":0.7,"unknown":"x"}`)
report, out, err := run(console.WinterOptions{SettingsFile: first})