Make WordPress Core


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

    r60522 r60681  
    160160                        'LLLL' => null,
    161161                    ),
    162                 )
     162                ),
     163                JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
    163164            )
    164165        ),
     
    385386                wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer );
    386387            } ) ();',
    387             wp_json_encode( $preload_data ),
     388            wp_json_encode( $preload_data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
    388389            $user_id
    389390        )
     
    478479                        'abbr'            => $timezone_abbr,
    479480                    ),
    480                 )
     481                ),
     482                JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
    481483            )
    482484        ),
     
    641643    $script = 'window.wpEditorL10n = {
    642644        tinymce: {
    643             baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ',
     645            baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ',
    644646            suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ',
    645647            settings: ' . $init_obj . ',
     
    11561158                        'mejs.yiddish'             => __( 'Yiddish' ),
    11571159                    ),
    1158                 )
     1160                ),
     1161                JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
    11591162            )
    11601163        ),
     
    20002003            'firstDay'        => absint( get_option( 'start_of_week' ) ),
    20012004            'isRTL'           => $wp_locale->is_rtl(),
    2002         )
     2005        ),
     2006        JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
    20032007    );
    20042008
     
    28102814                '   wp.blocks.registerBlockStyle( \'%s\', %s );',
    28112815                $block_name,
    2812                 wp_json_encode( $block_style )
     2816                wp_json_encode( $block_style, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    28132817            );
    28142818        }
Note: See TracChangeset for help on using the changeset viewer.