From 41251715adafaa3a6a5b0e624d92fc53fee525fa Mon Sep 17 00:00:00 2001
From: Martin Probst zz p {} zz <style>p {}</style> zz p {} zz <style>p {}</style> alert() <script>alert()</script> zz alert() zz <script>alert()</script> zz alert() zz <script>alert()</script> alert() <script>alert()</script> zz zz <script src='foo'></script> zz zz <script src=foo></script> '';!--"=&{()} '';!--"<xss>=&{()} <script SRC=http://ha.ckers.org/xss.js></script> <script \nSRC=http://ha.ckers.org/xss.js></script> xss link]*")?(\stitle="[^"<>]*")?\s?\/?>)$`)
// TODO: improve this regexp to catch all possible entities:
htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`)
)
@@ -820,24 +780,6 @@ func findHtmlTagPos(tag []byte, tagname string) (bool, int) {
return false, -1
}
-func sanitizeHtml(html []byte) []byte {
- var result []byte
- for string(html) != "" {
- skip, tag, rest := findHtmlTag(html)
- html = rest
- result = append(result, skip...)
- result = append(result, sanitizeTag(tag)...)
- }
- return append(result, []byte("\n")...)
-}
-
-func sanitizeTag(tag []byte) []byte {
- if tagWhitelist.Match(tag) || anchorClean.Match(tag) || imgClean.Match(tag) {
- return tag
- }
- return []byte("")
-}
-
func skipUntilChar(text []byte, start int, char byte) int {
i := start
for i < len(text) && text[i] != char {
@@ -846,19 +788,6 @@ func skipUntilChar(text []byte, start int, char byte) int {
return i
}
-func findHtmlTag(html []byte) (skip, tag, rest []byte) {
- start := skipUntilChar(html, 0, '<')
- rightAngle := skipUntilCharIgnoreQuotes(html, start, '>')
- if rightAngle > start {
- skip = html[0:start]
- tag = html[start : rightAngle+1]
- rest = html[rightAngle+1:]
- return
- }
-
- return []byte(""), []byte(""), []byte("")
-}
-
func skipSpace(tag []byte, i int) int {
for i < len(tag) && isspace(tag[i]) {
i++
diff --git a/inline.go b/inline.go
index 41225ce..b3aaf0f 100644
--- a/inline.go
+++ b/inline.go
@@ -20,6 +20,7 @@ import (
)
var (
+ urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
anchorRe = regexp.MustCompile(`^(]+")?\s?>` + urlRe + `<\/a>)`)
)
diff --git a/inline_test.go b/inline_test.go
index 478fbe0..1937021 100644
--- a/inline_test.go
+++ b/inline_test.go
@@ -72,135 +72,135 @@ func doTestsInlineParam(t *testing.T, tests []string, extensions, htmlFlags int)
func TestRawHtmlTag(t *testing.T) {
tests := []string{
"zz \n",
- "
`,
- "\n",
+ "
",
- "\n",
+ "
",
- "\n",
+ "
",
- "\n",
+ "
xss link
\n", + "\n", - // XXX: this doesn't pass yet - //`<script>alert("XSS")</script>">
<script/XSS SRC="http://ha.ckers.org/xss.js"></script>
\n", - // XXX: this doesn't pass yet - //"", - //"\n", + "", + "<body onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert("XSS")>
\n", ``, - "\n", + "<script/SRC="http://ha.ckers.org/xss.js"></script>
\n", - // XXX: this doesn't pass yet - //`<`, - //"", + // HTML5 interprets the `, + "<<script>alert("XSS");//<</script>
\n", + // HTML5 parses the within an unclosed