File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed
Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -3726,14 +3726,31 @@ public function set_modifiable_text( string $plaintext_content ): bool {
37263726 switch ( $ this ->get_tag () ) {
37273727 case 'SCRIPT ' :
37283728 /*
3729- * This is over-protective, but ensures the update doesn't break
3730- * out of the SCRIPT element. A more thorough check would need to
3731- * ensure that the script closing tag doesn't exist, and isn't
3732- * also "hidden" inside the script double-escaped state.
3729+ * SCRIPT tag contents can be dangerous.
37333730 *
3734- * It may seem like replacing `</script` with `<\/script` would
3735- * properly escape these things, but this could mask regex patterns
3736- * that previously worked. Resolve this by not sending `</script`
3731+ * The text `</script>` could close the SCRIPT element prematurely.
3732+ *
3733+ * The text `<script>` could enter the "script data double escaped state", preventing the
3734+ * SCRIPT element from closing as expected, for example:
3735+ *
3736+ * <script>
3737+ * // If this "<!--" then "<script>" the closing tag will not be recognized.
3738+ * </script>
3739+ * <h1>This appears inside the preceding SCRIPT element.</h1>
3740+ *
3741+ * The relevant state transitions happen on text like:
3742+ * 1. <
3743+ * 2. / (optional)
3744+ * 3. script (case-insensitive)
3745+ * 4. One of the following characters:
3746+ * - \t
3747+ * - \n
3748+ * - \f
3749+ * - " " (U+0020 SPACE)
3750+ * - /
3751+ * - >
3752+ *
3753+ * @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escaped-state
37373754 */
37383755 if (
37393756 false !== stripos ( $ plaintext_content , '</script ' ) ||
You can’t perform that action at this time.
0 commit comments