Making WordPress.org


Ignore:
Timestamp:
05/17/2024 02:09:30 AM (2 years ago)
Author:
dd32
Message:

Plugins: Add a hotfix for two semi-annoying PHP warnings that invalid requests trigger.

See ​https://github.com/GlotPress/GlotPress/pull/1835
See ​https://core.trac.wordpress.org/ticket/60261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-bad-request.php

    r12884 r13720  
    183183
    184184/**
     185 * Detect invalid charsets to trackbacks.
     186 * Hotfix for https://core.trac.wordpress.org/ticket/60261
     187 */
     188add_action( 'template_redirect', function() {
     189        if ( ! is_trackback() ) {
     190                return;
     191        }
     192
     193        $charset = str_replace( array( ',', ' ' ), '', strtoupper( trim( $_POST['charset'] ?? '' ) ) );
     194
     195        if ( function_exists( 'mb_list_encodings' ) && ! in_array( $charset, mb_list_encodings(), true ) ) {
     196                die_bad_request( 'Invalid Charset' );
     197        }
     198} );
     199
     200/**
     201 * Detect invalid requests to GlotPress
     202 *
     203 * Hotfix for https://github.com/GlotPress/GlotPress/pull/1835
     204 */
     205add_action( 'gp_init', function() {
     206        $only_array_values = [ 'filter', 'sort' ];
     207
     208        foreach ( $only_array_values as $query_var ) {
     209                if ( isset( $_GET[ $query_var ] ) && ! is_array( $_GET[ $query_var ] ) ) {
     210                        if ( empty( $_GET[ $query_var ] ) ) {
     211                                // If it's not set to anything, just silently discard the value.
     212                                unset( $_GET[ $query_var ], $_REQUEST[ $query_var ] );
     213                                continue;
     214                        }
     215
     216                        die_bad_request( "non-array $query_var in GlotPress" );
     217                }
     218        }
     219} );
     220
     221/**
    185222 * Die with a 400 Bad Request.
    186223 *
Note: See TracChangeset for help on using the changeset viewer.