mirror of
https://github.com/miniflux/v2.git
synced 2025-07-02 16:38:37 +00:00
addImageTitle: Fix HTML injection
This rewrite rule would change this: <img title="<foo>"> to this: <figure><img><figcaption><foo></figcaption></figure> The image title needs to be properly escaped.
This commit is contained in:
parent
3a39d110f0
commit
ea2b6e3608
2 changed files with 11 additions and 1 deletions
|
@ -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(`<figure><img src="` + srcAttr + `" alt="` + altAttr + `"/><figcaption><p>` + titleAttr + `</p></figcaption></figure>`)
|
||||
img.ReplaceWithHtml(`<figure><img src="` + srcAttr + `" alt="` + altAttr + `"/><figcaption><p>` + html.EscapeString(titleAttr) + `</p></figcaption></figure>`)
|
||||
})
|
||||
|
||||
output, _ := doc.Find("body").First().Html()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue