mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
Rename escape_slash in script_safe and also escape E+2028 and E+2029
It is rather common to directly interpolate JSON string inside <script> tags in HTML as to provide configuration or parameters to a script. However this may lead to XSS vulnerabilities, to prevent that 3 characters need to be escaped: - `/` (forward slash) - `U+2028` (LINE SEPARATOR) - `U+2029` (PARAGRAPH SEPARATOR) The forward slash need to be escaped to prevent closing the script tag early, and the other two are valid JSON but invalid Javascript and can be used to break JS parsing. Given that the intent of escaping forward slash is the same than escaping U+2028 and U+2029, I chos to rename and repurpose the existing `escape_slash` option.
This commit is contained in:
parent
698cb84062
commit
0dfeb17296
5 changed files with 74 additions and 29 deletions
|
@ -285,6 +285,15 @@ require 'json/common'
|
|||
# # Raises JSON::NestingError (nesting of 2 is too deep):
|
||||
# JSON.generate(obj, max_nesting: 2)
|
||||
#
|
||||
# ====== Escaping Options
|
||||
#
|
||||
# Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
|
||||
# and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
|
||||
# tags.
|
||||
#
|
||||
# Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
|
||||
# should be escaped.
|
||||
#
|
||||
# ====== Output Options
|
||||
#
|
||||
# The default formatting options generate the most compact
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue