Improved URL sanitizer
This commit is contained in:
parent
abb1b0c3fc
commit
133d01bd11
@ -171,6 +171,8 @@ func (r *renderer) writeText(markdown string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sanitizeURL(linkURL string) string {
|
func sanitizeURL(linkURL string) string {
|
||||||
|
linkURL = strings.TrimSpace(linkURL)
|
||||||
|
|
||||||
if strings.HasPrefix(strings.ToLower(linkURL), "javascript:") {
|
if strings.HasPrefix(strings.ToLower(linkURL), "javascript:") {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ func TestCombined(t *testing.T) {
|
|||||||
func TestSecurity(t *testing.T) {
|
func TestSecurity(t *testing.T) {
|
||||||
assert.Equal(t, markdown.Render("[text](javascript:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
assert.Equal(t, markdown.Render("[text](javascript:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
||||||
assert.Equal(t, markdown.Render("[text](javAscRipt:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
assert.Equal(t, markdown.Render("[text](javAscRipt:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
||||||
assert.Equal(t, markdown.Render("[text](\"><div>html</div>)"), "<p><a href=\""><div>html</div>\">text</a></p>")
|
assert.Equal(t, markdown.Render("[text]( javascript:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
||||||
assert.Equal(t, markdown.Render("[<div>html</div>]()"), "<p><a href=\"\"><div>html</div></a></p>")
|
assert.Equal(t, markdown.Render("[text]('javAscRipt:alert(\"xss\")')"), "<p><a href=\"'javAscRipt:alert("xss")'\">text</a></p>")
|
||||||
|
assert.Equal(t, markdown.Render("[text](\"><script>alert(123)</script>)"), "<p><a href=\""><script>alert(123)</script>\">text</a></p>")
|
||||||
|
assert.Equal(t, markdown.Render("[<script>alert(123)</script>]()"), "<p><a href=\"\"><script>alert(123)</script></a></p>")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user