Make WordPress Core


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

    r60678 r60681  
    32753275    </ol>
    32763276    </noscript>
    3277     <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ); ?></script>
     3277    <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?></script>
    32783278</div>
    32793279    <?php
     
    44364436    );
    44374437
    4438     $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';';
     4438    $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ';';
    44394439
    44404440    if ( $data ) {
Note: See TracChangeset for help on using the changeset viewer.