-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 Conflicts: actionpack/test/controller/new_base/render_template_test.rb actionpack/test/template/asset_tag_helper_test.rb actionpack/test/template/erb_util_test.rb actionpack/test/template/javascript_helper_test.rb actionpack/test/template/template_test.rb activesupport/lib/active_support/core_ext/string/output_safety.rb activesupport/test/core_ext/string_ext_test.rb railties/test/application/assets_test.rb
- Loading branch information
1 parent
f07c708
commit 780a718
Showing
10 changed files
with
64 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ | |
|
||
class ERB | ||
module Util | ||
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' } | ||
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jshraibman-mdsol
|
||
JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' } | ||
|
||
# A utility method for escaping HTML tag characters. | ||
# This method is also aliased as <tt>h</tt>. | ||
# | ||
# In your ERb templates, use this method to escape any unsafe content. For example: | ||
# In your ERB templates, use this method to escape any unsafe content. For example: | ||
# <%=h @person.name %> | ||
# | ||
# ==== Example: | ||
|
@@ -20,7 +20,7 @@ def html_escape(s) | |
if s.html_safe? | ||
s | ||
else | ||
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<").html_safe | ||
s.gsub(/[&"'><]/n) { |special| HTML_ESCAPE[special] }.html_safe | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Was this necessary to fix CVE-2013-0333? All of a sudden strings with single quotes stuck into input boxes are being doubly escaped, like so: