Skip to content

Commit e0774e4

Browse files
committed
fixing utf8 escape vulerability
1 parent 60f783d commit e0774e4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

activesupport/lib/active_support/core_ext/string/output_safety.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def html_escape(s)
1919
if s.html_safe?
2020
s
2121
else
22-
s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }.html_safe
22+
s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;").html_safe
2323
end
2424
end
2525

activesupport/test/core_ext/string_ext_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
require 'date'
33
require 'abstract_unit'
44
require 'inflector_test_cases'
5+
require 'active_support/core_ext/string/output_safety'
56

67
class StringInflectionsTest < Test::Unit::TestCase
78
include InflectorTestCases
89

10+
def test_erb_escape
11+
string = [192, 60].pack('CC')
12+
expected = 192.chr + "&lt;"
13+
assert_equal expected, ERB::Util.html_escape(string)
14+
end
15+
916
def test_pluralize
1017
SingularToPlural.each do |singular, plural|
1118
assert_equal(plural, singular.pluralize)

0 commit comments

Comments
 (0)