Closed mk-pmb closed 8 years ago
We escape them because they can possibly contribute to an XSS attack, when the source is directly embedded in an HTML <script>
tag.
Yes, there are two types of character we escape in this way:
\u2028
and \u2029
) - needed to prevent bugs<
, >
, /
) - needed to prevent XSSWe don't escape characters that are already escaped by JSON.stringify, or don't fit into one of the two categories above.
I noticed that
js-stringify
replaces low ASCII control characters with Unicode hex escapes. Should it do similar for some others, like U+0090 device control or U+FEFF zero width no-break space? My Firefox has no problem with them, as it has no problem with U+0002, so that's probably not the criterion. How do you decide?PS: In case it helps, here's a list of characters I consider suspicious.