diff --git a/reader/rewrite/rewrite_functions.go b/reader/rewrite/rewrite_functions.go index 6ce96937..667f3591 100644 --- a/reader/rewrite/rewrite_functions.go +++ b/reader/rewrite/rewrite_functions.go @@ -6,6 +6,7 @@ package rewrite // import "miniflux.app/reader/rewrite" import ( "fmt" + "html" "regexp" "strings" @@ -32,7 +33,7 @@ func addImageTitle(entryURL, entryContent string) string { srcAttr, _ := img.Attr("src") titleAttr, _ := img.Attr("title") - img.ReplaceWithHtml(`` + titleAttr + ``) + img.ReplaceWithHtml(`` + html.EscapeString(titleAttr) + ``) }) output, _ := doc.Find("body").First().Html() diff --git a/reader/rewrite/rewriter_test.go b/reader/rewrite/rewriter_test.go index fe37b539..9bd83e84 100644 --- a/reader/rewrite/rewriter_test.go +++ b/reader/rewrite/rewriter_test.go @@ -61,6 +61,15 @@ func TestRewriteWithXkcdLink(t *testing.T) { } } +func TestRewriteWithXkcdLinkHtmlInjection(t *testing.T) { + description := `` + output := Rewriter("https://xkcd.com/1912/", description, ``) + expected := `<foo>` + if expected != output { + t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected) + } +} + func TestRewriteWithXkcdLinkAndImageNoTitle(t *testing.T) { description := `` output := Rewriter("https://xkcd.com/1912/", description, ``)
` + titleAttr + `
` + html.EscapeString(titleAttr) + `
<foo>