@@ -1841,17 +1841,30 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
18411841 $ blogname = wp_specialchars_decode ( get_option ( 'blogname ' ), ENT_QUOTES );
18421842 $ comment_content = wp_specialchars_decode ( $ comment ->comment_content );
18431843
1844+ /*
1845+ * Line breaks in the comment author fields would end the header or line they
1846+ * are placed in, letting the comment author add email headers or lines of their own.
1847+ */
1848+ $ isolate_header_value = static function ( $ value ): string {
1849+ $ is_stringy = is_string ( $ value ) || ( is_object ( $ value ) && method_exists ( $ value , '__toString ' ) );
1850+ $ value = $ is_stringy ? (string ) $ value : '' ;
1851+ return trim ( (string ) preg_replace ( '/[\r\n]+/ ' , ' ' , $ value ) );
1852+ };
1853+ $ comment_author = $ isolate_header_value ( $ comment ->comment_author );
1854+ $ comment_author_email = $ isolate_header_value ( $ comment ->comment_author_email );
1855+ $ comment_author_url = $ isolate_header_value ( $ comment ->comment_author_url );
1856+
18441857 $ wp_email = 'wordpress@ ' . preg_replace ( '#^www\.# ' , '' , wp_parse_url ( network_home_url (), PHP_URL_HOST ) );
18451858
1846- if ( '' === $ comment -> comment_author ) {
1859+ if ( '' === $ comment_author ) {
18471860 $ from = "From: \"$ blogname \" < $ wp_email> " ;
1848- if ( '' !== $ comment -> comment_author_email ) {
1849- $ reply_to = "Reply-To: $ comment -> comment_author_email " ;
1861+ if ( is_email ( $ comment_author_email ) ) {
1862+ $ reply_to = "Reply-To: $ comment_author_email " ;
18501863 }
18511864 } else {
1852- $ from = "From: \"$ comment -> comment_author \" < $ wp_email> " ;
1853- if ( '' !== $ comment -> comment_author_email ) {
1854- $ reply_to = "Reply-To: \"$ comment -> comment_author_email \" < $ comment -> comment_author_email > " ;
1865+ $ from = "From: \"$ comment_author \" < $ wp_email> " ;
1866+ if ( is_email ( $ comment_author_email ) ) {
1867+ $ reply_to = "Reply-To: \"$ comment_author_email \" < $ comment_author_email> " ;
18551868 }
18561869 }
18571870
@@ -1886,9 +1899,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
18861899 /* translators: %s: Post title. */
18871900 $ notify_message = sprintf ( __ ( 'New trackback on your post "%s" ' ), $ post ->post_title ) . "\r\n" ;
18881901 /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1889- $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
1902+ $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
18901903 /* translators: %s: Trackback/pingback/comment author URL. */
1891- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
1904+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
18921905 /* translators: %s: Comment text. */
18931906 $ notify_message .= sprintf ( __ ( 'Comment: %s ' ), "\r\n" . $ comment_content ) . "\r\n\r\n" ;
18941907 $ notify_message .= __ ( 'You can see all trackbacks on this post here: ' ) . "\r\n" ;
@@ -1900,9 +1913,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
19001913 /* translators: %s: Post title. */
19011914 $ notify_message = sprintf ( __ ( 'New pingback on your post "%s" ' ), $ post ->post_title ) . "\r\n" ;
19021915 /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
1903- $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
1916+ $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
19041917 /* translators: %s: Trackback/pingback/comment author URL. */
1905- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
1918+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
19061919 /* translators: %s: Comment text. */
19071920 $ notify_message .= sprintf ( __ ( 'Comment: %s ' ), "\r\n" . $ comment_content ) . "\r\n\r\n" ;
19081921 $ notify_message .= __ ( 'You can see all pingbacks on this post here: ' ) . "\r\n" ;
@@ -1914,9 +1927,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
19141927 /* translators: %s: Post title. */
19151928 $ notify_message = sprintf ( __ ( 'New note on your post "%s" ' ), $ post ->post_title ) . "\r\n" ;
19161929 /* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
1917- $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
1930+ $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
19181931 /* translators: %s: Note author email. */
1919- $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment -> comment_author_email ) . "\r\n" ;
1932+ $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment_author_email ) . "\r\n" ;
19201933 /* translators: %s: Note text. */
19211934 $ notify_message .= sprintf ( __ ( 'Note: %s ' ), "\r\n" . ( empty ( $ comment_content ) ? __ ( 'resolved/reopened ' ) : $ comment_content ) ) . "\r\n\r\n" ;
19221935 $ notify_message .= __ ( 'You can see all notes on this post here: ' ) . "\r\n" ;
@@ -1928,11 +1941,11 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
19281941 /* translators: %s: Post title. */
19291942 $ notify_message = sprintf ( __ ( 'New comment on your post "%s" ' ), $ post ->post_title ) . "\r\n" ;
19301943 /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
1931- $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
1944+ $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
19321945 /* translators: %s: Comment author email. */
1933- $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment -> comment_author_email ) . "\r\n" ;
1946+ $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment_author_email ) . "\r\n" ;
19341947 /* translators: %s: Trackback/pingback/comment author URL. */
1935- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
1948+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
19361949
19371950 if ( $ comment ->comment_parent && user_can ( $ post ->post_author , 'edit_comment ' , $ comment ->comment_parent ) ) {
19381951 /* translators: Comment moderation. %s: Parent comment edit URL. */
@@ -2056,6 +2069,19 @@ function wp_notify_moderator( $comment_id ) {
20562069 $ blogname = wp_specialchars_decode ( get_option ( 'blogname ' ), ENT_QUOTES );
20572070 $ comment_content = wp_specialchars_decode ( $ comment ->comment_content );
20582071
2072+ /*
2073+ * Line breaks in the comment author fields would end the header or line they
2074+ * are placed in, letting the comment author add email headers or lines of their own.
2075+ */
2076+ $ isolate_header_value = static function ( $ value ): string {
2077+ $ is_stringy = is_string ( $ value ) || ( is_object ( $ value ) && method_exists ( $ value , '__toString ' ) );
2078+ $ value = $ is_stringy ? (string ) $ value : '' ;
2079+ return trim ( (string ) preg_replace ( '/[\r\n]+/ ' , ' ' , $ value ) );
2080+ };
2081+ $ comment_author = $ isolate_header_value ( $ comment ->comment_author );
2082+ $ comment_author_email = $ isolate_header_value ( $ comment ->comment_author_email );
2083+ $ comment_author_url = $ isolate_header_value ( $ comment ->comment_author_url );
2084+
20592085 $ message_headers = '' ;
20602086
20612087 /**
@@ -2093,9 +2119,9 @@ function wp_notify_moderator( $comment_id ) {
20932119 $ notify_message = sprintf ( __ ( 'A new trackback on the post "%s" is waiting for your approval ' ), $ post ->post_title ) . "\r\n" ;
20942120 $ notify_message .= get_permalink ( $ comment ->comment_post_ID ) . "\r\n\r\n" ;
20952121 /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
2096- $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
2122+ $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
20972123 /* translators: %s: Trackback/pingback/comment author URL. */
2098- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
2124+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
20992125 /* translators: %s: Trackback excerpt text. */
21002126 $ notify_message .= sprintf ( __ ( 'Trackback excerpt: %s ' ), "\r\n" . $ comment_content ) . "\r\n\r\n" ;
21012127 break ;
@@ -2105,9 +2131,9 @@ function wp_notify_moderator( $comment_id ) {
21052131 $ notify_message = sprintf ( __ ( 'A new pingback on the post "%s" is waiting for your approval ' ), $ post ->post_title ) . "\r\n" ;
21062132 $ notify_message .= get_permalink ( $ comment ->comment_post_ID ) . "\r\n\r\n" ;
21072133 /* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
2108- $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
2134+ $ notify_message .= sprintf ( __ ( 'Website: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
21092135 /* translators: %s: Trackback/pingback/comment author URL. */
2110- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
2136+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
21112137 /* translators: %s: Pingback excerpt text. */
21122138 $ notify_message .= sprintf ( __ ( 'Pingback excerpt: %s ' ), "\r\n" . $ comment_content ) . "\r\n\r\n" ;
21132139 break ;
@@ -2117,11 +2143,11 @@ function wp_notify_moderator( $comment_id ) {
21172143 $ notify_message = sprintf ( __ ( 'A new comment on the post "%s" is waiting for your approval ' ), $ post ->post_title ) . "\r\n" ;
21182144 $ notify_message .= get_permalink ( $ comment ->comment_post_ID ) . "\r\n\r\n" ;
21192145 /* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
2120- $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment -> comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
2146+ $ notify_message .= sprintf ( __ ( 'Author: %1$s (IP address: %2$s, %3$s) ' ), $ comment_author , $ comment ->comment_author_IP , $ comment_author_domain ) . "\r\n" ;
21212147 /* translators: %s: Comment author email. */
2122- $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment -> comment_author_email ) . "\r\n" ;
2148+ $ notify_message .= sprintf ( __ ( 'Email: %s ' ), $ comment_author_email ) . "\r\n" ;
21232149 /* translators: %s: Trackback/pingback/comment author URL. */
2124- $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment -> comment_author_url ) . "\r\n" ;
2150+ $ notify_message .= sprintf ( __ ( 'URL: %s ' ), $ comment_author_url ) . "\r\n" ;
21252151
21262152 if ( $ comment ->comment_parent ) {
21272153 /* translators: Comment moderation. %s: Parent comment edit URL. */
0 commit comments