Make WordPress Core


Ignore:
Timestamp:
08/28/2026 12:04:49 AM (7 weeks ago)
Author:
dmsnell
Message:

HTML API: Refactor wp_get_admin_notice().

Refactors wp_get_admin_notice() to rely on the HTML API for HTML generation. This provides more reliable parsing and hardening for and against the provided arguments, but introduces behavioral changes that should only affect already-broken cases.

Namely, the function previously generated its output and then mandated that calling code run it through wp_kses(). This meant that certain kinds of corruption were possible which would break boundaries within the generated HTML and result in mangled output through wp_kses(). Now, the function preserves all boundaries when generating the output, meaning that wp_kses() will receive already-normalized content.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13273
Discussed in: https://core.trac.wordpress.org/ticket/65984

Props dmsnell, joedolson, johnbillion, jorbin.
See #65984.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpAdminNotice.php

    r57100 r63380  
    2626                $actual = ob_get_clean();
    2727
    28                 $this->assertSame( $expected, $actual );
     28                $this->assertEqualHTML( $expected, $actual );
    2929        }
    3030
    … …  
    155155                                        'type' => '"><script>alert("Howdy,admin!");</script>',
    156156                                ),
    157                                 'expected' => '<div class="notice notice-">alert("Howdy,admin!");"&gt;<p>A notice with an unsafe type.</p></div>',
     157                                'expected' => '<div class="notice notice-&quot;><script>alert(&quot;Howdy,admin!&quot;);</script>"><p>A notice with an unsafe type.</p></div>',
    158158                        ),
    159159                        'an unsafe ID'                              => array(
    … …  
    162162                                        'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice',
    163163                                ),
    164                                 'expected' => '<div id="">alert( "Howdy, admin!" ); <div class="notice"><p>A notice with an unsafe ID.</p></div>',
     164                                'expected' => '<div id="&quot;><script>alert( &quot;Howdy, admin!&quot; );</script> <div class=&quot;notice" class="notice"><p>A notice with an unsafe ID.</p></div>',
    165165                        ),
    166166                        'unsafe additional classes'                 => array(
    … …  
    169169                                        'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ),
    170170                                ),
    171                                 'expected' => '<div class="notice ">alert( "Howdy, admin!" ); <div class="notice"><p>A notice with unsafe additional classes.</p></div>',
     171                                'expected' => '<div class="notice &quot;><script>alert( &quot;Howdy, admin!&quot; );</script> <div class=&quot;notice"><p>A notice with unsafe additional classes.</p></div>',
    172172                        ),
    173173                        'a type that is not a string'               => array(
Note: See TracChangeset for help on using the changeset viewer.