Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
remove markdown onmouseover exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Slowe committed Sep 28, 2009
1 parent c780f09 commit 1f1f060
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions r2/r2/lib/contrib/markdown.py
Expand Up @@ -28,9 +28,14 @@ def htmlquote(text):
text = text.replace('"', """)
return text

def mangle_text(text):
from pylons import g
return md5.new(text + g.SECRET).hexdigest()

def semirandom(seed):
from pylons import g
x = 0
for c in md5.new(seed).digest(): x += ord(c)
for c in md5.new(seed + g.SECRET).digest(): x += ord(c)
return x / (255*16.)

class _Markdown:
Expand All @@ -40,7 +45,7 @@ class _Markdown:
escapechars = '\\`*_{}[]()>#+-.!'
escapetable = {}
for char in escapechars:
escapetable[char] = md5.new(char).hexdigest()
escapetable[char] = mangle_text(char)

r_multiline = re.compile("\n{2,}")
r_stripspace = re.compile(r"^[ \t]+$", re.MULTILINE)
Expand Down Expand Up @@ -155,7 +160,7 @@ def handler(m):
key = key.encode('utf8')
except UnicodeDecodeError:
key = ''.join(k for k in key if ord(k) < 128)
key = md5.new(key).hexdigest()
key = mangle_text(key)
self.html_blocks[key] = m.group(1)
return "\n\n%s\n\n" % key

Expand Down Expand Up @@ -288,7 +293,7 @@ def handler2(m):
res += ">%s</a>" % htmlquote(link_text)
return res

text = self.r_DoAnchors1.sub(handler1, text)
#text = self.r_DoAnchors1.sub(handler1, text)
text = self.r_DoAnchors2.sub(handler2, text)
return text

Expand Down

0 comments on commit 1f1f060

Please sign in to comment.