Skip to content

fix html_regexp leak#4

Open
liweinan wants to merge 1 commit into
defunkt:masterfrom
liweinan:html_regexp_leak
Open

fix html_regexp leak#4
liweinan wants to merge 1 commit into
defunkt:masterfrom
liweinan:html_regexp_leak

Conversation

@liweinan
Copy link
Copy Markdown

@liweinan liweinan commented Mar 7, 2012

acts_as_textiled is currently vulnerable to improperly closed quotes html tag. Here is an example:

<pre class='bad_quote/>a</pre>
b
<pre class="c">d</pre>

If user input the above messages to website that is using acts_as_textiled, and if the website wants to show the message in :plain format, then ruby will hit CPU usage to 100% and blocks the http thread. And the http server goes down.

The cause is because of the regexp used in lib/acts_as_textiled.rb:

    def html_regexp
        %r{<(?:[^>"']+|"(?:\\.|[^\\"]+)*"|'(?:\\.|[^\\']+)*')*>}xm
    end

It cannot deal with the dirty quotes in html properly. I've tested it on:

ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

And here is the code to reproduce the problem:

str = "<pre class='bad_quote/>a</pre>\r\n<pre class=\"c\">d</pre>"

def html_regexp
        %r{<(?:[^>"']+|"(?:\\.|[^\\"]+)*"|'(?:\\.|[^\\']+)*')*>}xm
end

str.dup.gsub(html_regexp, '')

midu referenced this pull request in challengepost/acts_as_sanitiled Apr 24, 2012
Little tweak to make it work with Rails 3.0.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant