Rename escape_slash in script_safe and also escape E+2028 and E+2029 #525
+144
−65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: #215
Fix:#214
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 chose to rename and repurpose the existing
escape_slash
option.cc @hsbt @nurse
This could be used to very significantly speedup
ActiveSupport::JSON
(cc @jhawthorn)