This project is archived and is in readonly mode.
strip_tags marks as html_safe incorrectly
-
Andreas Mayer
Workaround:
h(String.new(strip_tags("Strip <i>these</i> \"tags\"!"))) -
Andreas Mayer
- Tag changed from rails 3.0.0, html_safe to rails 3.0.0, html_safe, patch
please review
-
Andreas Mayer
- Tag changed from rails 3.0.0, html_safe, patch to rails 3.0.1, actionview, html_safe, patch
-
Christopher Meiklejohn
Just verified this patch applies cleanly to master and has the desired effect.
ree-1.8.7-head :003 > strip_tags("<I>HI \"YOU\" </I>").html_safe? => falseCan we get this pulled in?
-
Christopher Meiklejohn
Actually, disregard.
ActionView::Helpers::SanitizeHelper specifically states that once the string is html_safe it may still contain unescaped characters.
Taken from #sanitize:
Please note that sanitizing user-provided text does not guarantee that the resulting markup is valid (conforming to a document type) or even well-formed. The output may still contain e.g. unescaped ‘<’, ‘>’, ‘&’ characters and confuse browsers.Seems like this isn't an issue, and should be marked invalid.
-
Andreas Mayer
@Christopher: I think it's absolutely OK for strip_tags to return text that is not valid in any form (it only strips tags, and uses a very simple parse for this so no guarantee for anything). However, why has this resulting string to be marked as html_safe? I can't read this in the docs you quoted and it's that what I wrote the patch for.
This report is the result of a problem that really occured and I think it makes no sense that a non-HTML-safe string is marked as html_safe - it means that you
1) can the Rails XSS protection using strip_tags, AND
2) that you always have to write
h(String.new(strip_tags(original_string)))
in your views. -
Andreas Mayer
Typo above, should be:
... 1) can BYPASS the Rails ...
