Repository navigation
Email: Guard against line feeds in untrusted header sources. #16113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bacfb42
3dcfb71
7f5f476
1864a54
2b0889c
7b84ee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1841,17 +1841,30 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { | |
| $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); | ||
| $comment_content = wp_specialchars_decode( $comment->comment_content ); | ||
|
|
||
| /* | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that having the exact same anonymus function here and in L2072 could lead in the future, to one deviating unnecessarily from the other (although AI tends to catch all coincidences pretty wel). Still I would rather opt to extract both and move it into a common place.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my use of the anonymous function was an attempt to avoid new abstractions during the release cycle for WordPress 7.2. I’m happy to expand these afterwards, but I think we want to be careful about creating a name for this transformation which is very specific to mail header fields. if nothing else, I would want probably for the WordPress 7.2 release I will want to keep it the same. I hesitated to abstract it at all into a closure after @westonruter’s comment, but I think it was reasonable to ask that the behavior be repeatable.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still, I'm not sure which is the difference from a release perspective. Maybe I'm missing some rule.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the difference is that now we have the release candidate and are focusing on fixing issues that arose during the period since WordPress 7.1. Adding a new function raises questions about the interface and how best to design it, which is work for the normal release cycle. Adding one now adds a new function to the global namespace and invites usage by plugins which can lock it into place even if it’s the “wrong” interface. as I hesitated to even add the closure, for fear of over-eager abstraction, I am less interested in tossing something last-minute into public view, even if it comes with I appreciate the desire though. when I started this work I started with a slightly more complete question: how can we properly communicate email header fields? and that escalated so I pared back the patch. it would be lovely if we could move into an even-more nuanced approach for setting these fields, in WordPress 7.3 or later |
||
| * 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>"; | ||
| } | ||
| } | ||
|
Comment on lines
-1846
to
1869
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good. So previously it was just checking if the email was a non-empty-string. Now it's also checking if it is an actual valid email.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if the email is less than 6 characters,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inasmuch as Core is able to determine “valid” |
||
|
|
||
|
|
@@ -1886,9 +1899,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { | |
| /* 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 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { | |
| /* 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 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { | |
| /* 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 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { | |
| /* 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 @@ function wp_notify_moderator( $comment_id ) { | |
| $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 @@ function wp_notify_moderator( $comment_id ) { | |
| $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 @@ function wp_notify_moderator( $comment_id ) { | |
| $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 @@ function wp_notify_moderator( $comment_id ) { | |
| $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. */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these a leftover? I think they are already covered by
phpcs:disableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, they might be, but Core should be aware that they are valid fields. PHPCS nagged me about them and tried to get me to introduce defects because of it.