update bluemonday to v1.0.5 to fix https://github.com/microcosm-cc/bluemonday/issues/111
This commit is contained in:
@@ -67,6 +67,12 @@ func TestComment_Sanitize(t *testing.T) {
|
||||
out: Comment{Text: "blah blah",
|
||||
Locator: Locator{URL: "/p/2021/03/23/prep-747/#remark42__comment-1b365913-7056-4920-b9ad-01304bdda085"}},
|
||||
},
|
||||
{
|
||||
inp: Comment{Text: "<scrİpt><img src=x onerror=alert(1)>",
|
||||
Locator: Locator{URL: "/p/2021/03/23/prep-747/#remark42__comment-1b365913-7056-4920-b9ad-01304bdda085"}},
|
||||
out: Comment{Text: "<img src=x onerror=alert(1)>",
|
||||
Locator: Locator{URL: "/p/2021/03/23/prep-747/#remark42__comment-1b365913-7056-4920-b9ad-01304bdda085"}},
|
||||
},
|
||||
}
|
||||
|
||||
for n, tt := range tbl {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ require (
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/hashicorp/go-multierror v1.1.0
|
||||
github.com/kyokomi/emoji v2.2.1+incompatible
|
||||
github.com/microcosm-cc/bluemonday v1.0.4
|
||||
github.com/microcosm-cc/bluemonday v1.0.5
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rakyll/statik v0.1.7
|
||||
github.com/rs/xid v1.2.1
|
||||
|
||||
@@ -179,6 +179,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
|
||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4 h1:p0L+CTpo/PLFdkoPcJemLXG+fpMD7pYOoDEq1axMbGg=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.5 h1:cF59UCKMmmUgqN1baLvqU/B1ZsMori+duLVTLpgiG3w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.5/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
|
||||
|
||||
+24
-4
@@ -229,7 +229,7 @@ func (p *Policy) sanitize(r io.Reader) *bytes.Buffer {
|
||||
|
||||
case html.StartTagToken:
|
||||
|
||||
mostRecentlyStartedToken = strings.ToLower(token.Data)
|
||||
mostRecentlyStartedToken = normaliseElementName(token.Data)
|
||||
|
||||
aps, ok := p.elsAndAttrs[token.Data]
|
||||
if !ok {
|
||||
@@ -272,7 +272,7 @@ func (p *Policy) sanitize(r io.Reader) *bytes.Buffer {
|
||||
|
||||
case html.EndTagToken:
|
||||
|
||||
if mostRecentlyStartedToken == strings.ToLower(token.Data) {
|
||||
if mostRecentlyStartedToken == normaliseElementName(token.Data) {
|
||||
mostRecentlyStartedToken = ""
|
||||
}
|
||||
|
||||
@@ -350,11 +350,11 @@ func (p *Policy) sanitize(r io.Reader) *bytes.Buffer {
|
||||
|
||||
if !skipElementContent {
|
||||
switch mostRecentlyStartedToken {
|
||||
case "script":
|
||||
case `script`:
|
||||
// not encouraged, but if a policy allows JavaScript we
|
||||
// should not HTML escape it as that would break the output
|
||||
buff.WriteString(token.Data)
|
||||
case "style":
|
||||
case `style`:
|
||||
// not encouraged, but if a policy allows CSS styles we
|
||||
// should not HTML escape it as that would break the output
|
||||
buff.WriteString(token.Data)
|
||||
@@ -887,3 +887,23 @@ func (p *Policy) matchRegex(elementName string) (map[string]attrPolicy, bool) {
|
||||
}
|
||||
return aps, matched
|
||||
}
|
||||
|
||||
|
||||
// normaliseElementName takes a HTML element like <script> which is user input
|
||||
// and returns a lower case version of it that is immune to UTF-8 to ASCII
|
||||
// conversion tricks (like the use of upper case cyrillic i scrİpt which a
|
||||
// strings.ToLower would convert to script). Instead this func will preserve
|
||||
// all non-ASCII as their escaped equivalent, i.e. \u0130 which reveals the
|
||||
// characters when lower cased
|
||||
func normaliseElementName(str string) string {
|
||||
// that useful QuoteToASCII put quote marks at the start and end
|
||||
// so those are trimmed off
|
||||
return strings.TrimSuffix(
|
||||
strings.TrimPrefix(
|
||||
strings.ToLower(
|
||||
strconv.QuoteToASCII(str),
|
||||
),
|
||||
`"`),
|
||||
`"`,
|
||||
)
|
||||
}
|
||||
Vendored
+1
-1
@@ -168,7 +168,7 @@ github.com/klauspost/compress/zstd/internal/xxhash
|
||||
# github.com/kyokomi/emoji v2.2.1+incompatible
|
||||
## explicit
|
||||
github.com/kyokomi/emoji
|
||||
# github.com/microcosm-cc/bluemonday v1.0.4
|
||||
# github.com/microcosm-cc/bluemonday v1.0.5
|
||||
## explicit
|
||||
github.com/microcosm-cc/bluemonday
|
||||
# github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022
|
||||
|
||||
Reference in New Issue
Block a user