aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/output_safety.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-07-31 22:25:54 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2012-07-31 22:26:52 -0300
commitb6ab4417720e03f1551abda2f1e4bd0a392dd04e (patch)
tree26546831441178c40782e3357e1a6961ef4f899c /activesupport/lib/active_support/core_ext/string/output_safety.rb
parentc10202208982bfa02ffd16d1614992228391d781 (diff)
downloadrails-b6ab4417720e03f1551abda2f1e4bd0a392dd04e.tar.gz
rails-b6ab4417720e03f1551abda2f1e4bd0a392dd04e.tar.bz2
rails-b6ab4417720e03f1551abda2f1e4bd0a392dd04e.zip
html_escape should escape single quotes
https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content Closes #7215
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/output_safety.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index 5226ff0cbe..c17d695967 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -3,9 +3,9 @@ require 'active_support/core_ext/kernel/singleton_class'
class ERB
module Util
- HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
+ HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#x27;' }
JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
- HTML_ESCAPE_ONCE_REGEXP = /[\"><]|&(?!([a-zA-Z]+|(#\d+));)/
+ HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
JSON_ESCAPE_REGEXP = /[&"><]/
# A utility method for escaping HTML tag characters.
@@ -21,7 +21,7 @@ class ERB
if s.html_safe?
s
else
- s.encode(s.encoding, :xml => :attr)[1...-1].html_safe
+ s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe
end
end