Encode the double quote (`"`) in StringUtil::encodeJS()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 4 Jan 2022 10:50:50 +0000 (11:50 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 4 Jan 2022 10:50:50 +0000 (11:50 +0100)
commit0ee8130667035c5211206c018d1f1b17b2f74b63
tree9ad3b1ad9904686ff4f3140580b4367f6a74e8ec
parentef51185048a57609df35b06a5d08b7f3f68f7d44
Encode the double quote (`"`) in StringUtil::encodeJS()

`encodeJSON()` is currently broken, because while it HTML-encodes the double
quote, it does not actually add the backslash in front of it. Depending on
whether the HTML entity is interpreted by the browser in that specific location
or not, this either results in an incorrect string (with a literal `&quot;`
instead of `"`) or in a syntax error (because the `"` ends the string
prematurely).

The latter might even allow for the injection of JavaScript, if `encodeJSON` is
used in a `<script>` tag that is not just LD-JSON metadata.

Fix this issue by escaping the double quote in `encodeJS` which is used
internally by `encodeJSON`. This should not cause issues, as an escaped double
quote is valid syntax within a JavaScript string.
wcfsetup/install/files/lib/util/StringUtil.class.php