Commit ab8a6600de for wordpress.org

commit ab8a6600dec15cccfd2bed4545ff755373d8b42f
Author: dmsnell <dmsnell@git.wordpress.org>
Date:   Mon Nov 23 18:51:52 2026 +0000

    Mail: Guard against line feeds in untrusted header sources.

    Email-sending functions should ensure that header fields are guarded against untrusted inputs, and that they should not bleed into new headers or into the email body.

    This patch adds these guards by removing line feeds in the inputs to these header values. This will result in some minor corruption of already-corrupt data, but will prevent unwanted structural injetions into the outbound emails.

    Developed in: https://github.com/WordPress/wordpress-develop/pull/16113
    Discussed in: https://core.trac.wordpress.org/ticket/66769

    Props dmsnell, sirlouen, westonruter.
    Fixes #66769.

    Built from https://develop.svn.wordpress.org/trunk@65744


    git-svn-id: http://core.svn.wordpress.org/trunk@64774 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php
index 0aaeabbb3b..94aab93a98 100644
--- a/wp-includes/pluggable.php
+++ b/wp-includes/pluggable.php
@@ -1841,17 +1841,30 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
 		$blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
 		$comment_content = wp_specialchars_decode( $comment->comment_content );

+		/*
+		 * Line breaks in the comment author fields would end the header or line they
+		 * are placed in, letting the comment author add email headers or lines of their own.
+		 */
+		$isolate_header_value = static function ( $value ): string {
+			$is_stringy = is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) );
+			$value      = $is_stringy ? (string) $value : '';
+			return trim( (string) preg_replace( '/[\r\n]+/', ' ', $value ) );
+		};
+		$comment_author       = $isolate_header_value( $comment->comment_author );
+		$comment_author_email = $isolate_header_value( $comment->comment_author_email );
+		$comment_author_url   = $isolate_header_value( $comment->comment_author_url );
+
 		$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) );

-		if ( '' === $comment->comment_author ) {
+		if ( '' === $comment_author ) {
 			$from = "From: \"$blogname\" <$wp_email>";
-			if ( '' !== $comment->comment_author_email ) {
-				$reply_to = "Reply-To: $comment->comment_author_email";
+			if ( is_email( $comment_author_email ) ) {
+				$reply_to = "Reply-To: $comment_author_email";
 			}
 		} else {
-			$from = "From: \"$comment->comment_author\" <$wp_email>";
-			if ( '' !== $comment->comment_author_email ) {
-				$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
+			$from = "From: \"$comment_author\" <$wp_email>";
+			if ( is_email( $comment_author_email ) ) {
+				$reply_to = "Reply-To: \"$comment_author_email\" <$comment_author_email>";
 			}
 		}

@@ -1886,9 +1899,9 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
 					/* translators: %s: Post title. */
 					$notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
 					/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
-					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
 					/* translators: %s: Comment text. */
 					$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
 					$notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
@@ -1900,9 +1913,9 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
 					/* translators: %s: Post title. */
 					$notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
 					/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
-					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
 					/* translators: %s: Comment text. */
 					$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
 					$notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
@@ -1914,9 +1927,9 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
 					/* translators: %s: Post title. */
 					$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
 					/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
-					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Note author email. */
-					$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
+					$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
 					/* translators: %s: Note text. */
 					$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $comment_content ) ) . "\r\n\r\n";
 					$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
@@ -1928,11 +1941,11 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
 					/* translators: %s: Post title. */
 					$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
 					/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
-					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Comment author email. */
-					$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
+					$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";

 					if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) {
 						/* translators: Comment moderation. %s: Parent comment edit URL. */
@@ -2056,6 +2069,19 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
 		$blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
 		$comment_content = wp_specialchars_decode( $comment->comment_content );

+		/*
+		 * Line breaks in the comment author fields would end the header or line they
+		 * are placed in, letting the comment author add email headers or lines of their own.
+		 */
+		$isolate_header_value = static function ( $value ): string {
+			$is_stringy = is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) );
+			$value      = $is_stringy ? (string) $value : '';
+			return trim( (string) preg_replace( '/[\r\n]+/', ' ', $value ) );
+		};
+		$comment_author       = $isolate_header_value( $comment->comment_author );
+		$comment_author_email = $isolate_header_value( $comment->comment_author_email );
+		$comment_author_url   = $isolate_header_value( $comment->comment_author_url );
+
 		$message_headers = '';

 		/**
@@ -2093,9 +2119,9 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
 					$notify_message  = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
 					$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
 					/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
-					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
 					/* translators: %s: Trackback excerpt text. */
 					$notify_message .= sprintf( __( 'Trackback excerpt: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
 					break;
@@ -2105,9 +2131,9 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
 					$notify_message  = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
 					$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
 					/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
-					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
 					/* translators: %s: Pingback excerpt text. */
 					$notify_message .= sprintf( __( 'Pingback excerpt: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
 					break;
@@ -2117,11 +2143,11 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
 					$notify_message  = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
 					$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
 					/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
-					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
+					$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
 					/* translators: %s: Comment author email. */
-					$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
+					$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
 					/* translators: %s: Trackback/pingback/comment author URL. */
-					$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
+					$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";

 					if ( $comment->comment_parent ) {
 						/* translators: Comment moderation. %s: Parent comment edit URL. */
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 407bc7b189..36a309b1e9 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-RC2-65743';
+$wp_version = '7.2-RC2-65744';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.