Make WordPress Core


Ignore:
Timestamp:
08/27/2025 10:32:57 AM (2 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-audio.php

    r56597 r60681  
    161161            sprintf(
    162162                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
    163                 wp_json_encode( $this->id_base ),
    164                 wp_json_encode( $exported_schema )
     163                wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     164                wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    165165            )
    166166        );
     
    173173                    wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
    174174                ',
    175                 wp_json_encode( $this->id_base ),
    176                 wp_json_encode( $this->widget_options['mime_type'] ),
    177                 wp_json_encode( $this->l10n )
     175                wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     176                wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
     177                wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    178178            )
    179179        );
Note: See TracChangeset for help on using the changeset viewer.