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:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
@@ -22,7 +23,8 @@ import (
|
||||
// its url items; with --append the URLs are added after every existing item.
|
||||
// The definition is always the one /sitemap.xml serves (theme default);
|
||||
// --theme is accepted for PHP compatibility and a theme other than default
|
||||
// is reported.
|
||||
// is reported. An entry whose url is not a path or an http(s) URL
|
||||
// (classes.AllowedItemURL) is refused, as the admin form refuses it.
|
||||
func Import(app *backpack.App) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: "sitemap:import",
|
||||
@@ -67,6 +69,9 @@ func ImportFile(ctx context.Context, db *gorm.DB, file, theme string, appendMode
|
||||
if fields["url"] == nil || err != nil || phpEmpty(fields["url"]) {
|
||||
return fmt.Errorf("Entry %s is missing a 'url' field", labels[i])
|
||||
}
|
||||
if !classes.AllowedItemURL(models.Text(url)) {
|
||||
return fmt.Errorf("Entry %s has a url that is not a path or an http(s) URL", labels[i])
|
||||
}
|
||||
item := models.DefinitionItem{Type: models.ItemTypeURL, URL: url}
|
||||
item.Changefreq = textOr(fields["changefreq"], "monthly")
|
||||
item.Priority = textOr(fields["priority"], "0.5")
|
||||
|
||||
Reference in New Issue
Block a user