Make WordPress Core


Ignore:
Timestamp:
08/27/2025 10:32:57 AM (6 months ago)
Author:
jonsurrell
Message:

Scripts: Use appropriate JSON encoding flags for script tags.

wp_json_encode() with default arguments is insufficient to safely escape JSON for script tags. Use JSON_HEX_TAG | JSON_UNESCAPED_SLASHES flags.

Developed in https://github.com/WordPress/wordpress-develop/pull/9557.

Props devasheeshkaul, jonsurrell, siliconforks.
Fixes #63851.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-media-image.php

    r59120 r60681  
    324324            sprintf(
    325325                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
    326                 wp_json_encode( $this->id_base ),
    327                 wp_json_encode( $exported_schema )
     326                wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     327                wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    328328            )
    329329        );
     
    336336                    wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
    337337                ',
    338                 wp_json_encode( $this->id_base ),
    339                 wp_json_encode( $this->widget_options['mime_type'] ),
    340                 wp_json_encode( $this->l10n )
     338                wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     339                wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     340                wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    341341            )
    342342        );
Note: See TracChangeset for help on using the changeset viewer.