Make WordPress Core

Changeset 49271


Ignore:
Timestamp:
10/22/2020 02:40:06 AM (3 years ago)
Author:
peterwilsoncc
Message:

XML-RPC: Fix length validation of anonymous commenter's email address.

Fix the first step of validating an anonymous commenters in which the length is checked prior to running regular expressions.

Follow up to [47808].
Fixes #51595.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r49183 r49271  
    39143914
    39153915            if ( get_option( 'require_name_email' ) ) {
    3916                 if ( strlen( $comment['comment_author_email'] < 6 ) || '' === $comment['comment_author'] ) {
     3916                if ( strlen( $comment['comment_author_email'] ) < 6 || '' === $comment['comment_author'] ) {
    39173917                    return new IXR_Error( 403, __( 'Comment author name and email are required.' ) );
    39183918                } elseif ( ! is_email( $comment['comment_author_email'] ) ) {
  • trunk/tests/phpunit/tests/xmlrpc/wp/newComment.php

    r49268 r49271  
    9797        $this->assertSame( 403, $result->code );
    9898    }
     99
     100    /**
     101     * Ensure anonymous comments can be made via XML-RPC.
     102     *
     103     * @ticket 51595
     104     */
     105    function test_allowed_anon_comments() {
     106        add_filter( 'xmlrpc_allow_anonymous_comments', '__return_true' );
     107
     108        $comment_args = array(
     109            1,
     110            '',
     111            '',
     112            self::$post->ID,
     113            array(
     114                'author'       => 'WordPress',
     115                'author_email' => 'noreply@wordpress.org',
     116                'content'      => 'Test Anon Comments',
     117            ),
     118        );
     119
     120        $result = $this->myxmlrpcserver->wp_newComment( $comment_args );
     121        $this->assertNotIXRError( $result );
     122        $this->assertInternalType( 'int', $result );
     123    }
     124
     125    /**
     126     * Ensure anonymous XML-RPC comments require a valid email.
     127     *
     128     * @ticket 51595
     129     */
     130    function test_anon_comments_require_email() {
     131        add_filter( 'xmlrpc_allow_anonymous_comments', '__return_true' );
     132
     133        $comment_args = array(
     134            1,
     135            '',
     136            '',
     137            self::$post->ID,
     138            array(
     139                'author'       => 'WordPress',
     140                'author_email' => 'noreply at wordpress.org',
     141                'content'      => 'Test Anon Comments',
     142            ),
     143        );
     144
     145        $result = $this->myxmlrpcserver->wp_newComment( $comment_args );
     146        $this->assertIXRError( $result );
     147        $this->assertSame( 403, $result->code );
     148    }
     149
     150    /**
     151     * Ensure valid users don't use the anon flow.
     152     *
     153     * @ticket 51595
     154     */
     155    function test_username_avoids_anon_flow() {
     156        add_filter( 'xmlrpc_allow_anonymous_comments', '__return_true' );
     157
     158        $comment_args = array(
     159            1,
     160            'administrator',
     161            'administrator',
     162            self::$post->ID,
     163            array(
     164                'author'       => 'WordPress',
     165                'author_email' => 'noreply at wordpress.org',
     166                'content'      => 'Test Anon Comments',
     167            ),
     168        );
     169
     170        $result  = $this->myxmlrpcserver->wp_newComment( $comment_args );
     171        $comment = get_comment( $result );
     172        $user_id = get_user_by( 'login', 'administrator' )->ID;
     173
     174        $this->assertSame( $user_id, (int) $comment->user_id );
     175    }
    99176}
Note: See TracChangeset for help on using the changeset viewer.