Repository navigation
Conversation
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.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| 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>"; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
And if the email is less than 6 characters, is_email() returns false always. (Ahem, unless the is_email filter overrides this.)
There was a problem hiding this comment.
inasmuch as Core is able to determine “valid”
Co-Authored-By: Weston Ruter <westonruter@git.wordpress.org>
| * replace the sender and add a recipient when read as email headers, or | ||
| * which look like part of the notification when read in the email body. | ||
| * | ||
| * @return array[] |
There was a problem hiding this comment.
| * @return array[] | |
| * @return array<non-falsy-string, array{ string, string, string }> |
| * | ||
| * @return array[] | ||
| */ | ||
| public static function data_line_break_injections() { |
There was a problem hiding this comment.
| public static function data_line_break_injections() { | |
| public static function data_line_break_injections(): array { |
| * These sources refuse such submissions before saving them, so a valid | ||
| * address replaces those emails to still test the other fields. | ||
| * | ||
| * @return array[] |
There was a problem hiding this comment.
| * @return array[] | |
| * @return array<non-falsy-string, array{ string, string, string }> |
| * | ||
| * @return array[] | ||
| */ | ||
| public static function data_line_break_injections_with_valid_email() { |
There was a problem hiding this comment.
| public static function data_line_break_injections_with_valid_email() { | |
| public static function data_line_break_injections_with_valid_email(): array { |
| * @param string $email Author email address containing some form of line feed. | ||
| * @param string $url Author URL containing some form of line feed. | ||
| */ | ||
| public function test_rest_api_comment_cannot_inject_into_comment_notifications( $author, $email, $url ) { |
There was a problem hiding this comment.
| public function test_rest_api_comment_cannot_inject_into_comment_notifications( $author, $email, $url ) { | |
| public function test_rest_api_comment_cannot_inject_into_comment_notifications( string $author, string $email, string $url ) { |
| * @param string $email User email address containing some form of line feed. | ||
| * @param string $url User URL containing some form of line feed. | ||
| */ | ||
| public function test_logged_in_comment_form_cannot_inject_into_comment_notifications( $author, $email, $url ) { |
There was a problem hiding this comment.
| public function test_logged_in_comment_form_cannot_inject_into_comment_notifications( $author, $email, $url ) { | |
| public function test_logged_in_comment_form_cannot_inject_into_comment_notifications( string $author, string $email, string $url ) { |
| * @param string $email Author email address containing some form of line feed. | ||
| * @param string $url Author URL containing some form of line feed. | ||
| */ | ||
| public function test_comment_form_cannot_inject_into_comment_notifications( $author, $email, $url ) { |
There was a problem hiding this comment.
| public function test_comment_form_cannot_inject_into_comment_notifications( $author, $email, $url ) { | |
| public function test_comment_form_cannot_inject_into_comment_notifications( string $author, string $email, string $url ) { |
| * @param string $email Author email address containing some form of line feed. | ||
| * @param string $url Author URL containing some form of line feed. | ||
| */ | ||
| public function test_xmlrpc_comment_cannot_inject_into_comment_notifications( $author, $email, $url ) { |
There was a problem hiding this comment.
| public function test_xmlrpc_comment_cannot_inject_into_comment_notifications( $author, $email, $url ) { | |
| public function test_xmlrpc_comment_cannot_inject_into_comment_notifications( string $author, string $email, string $url ) { |
| * @param string $email Unused, since trackbacks have no author email address. | ||
| * @param string $url Linking page URL containing some form of line feed. | ||
| */ | ||
| public function test_trackback_cannot_inject_into_comment_notifications( $author, $email, $url ) { |
There was a problem hiding this comment.
| public function test_trackback_cannot_inject_into_comment_notifications( $author, $email, $url ) { | |
| public function test_trackback_cannot_inject_into_comment_notifications( string $author, string $email, string $url ) { |
SirLouen
left a comment
There was a problem hiding this comment.
Very nice catch👍
Apart from these little nitpicks, I feel that if this could be happening elsewhere or if the anonymous functions need a bit more tweaking, a named function may serve a better purpose.
Also thinking about this a little further, I think I've stumbled upon a security issue. I'm going to report it to the security team.
| $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); | ||
| $comment_content = wp_specialchars_decode( $comment->comment_content ); | ||
|
|
||
| /* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 @ignore and @access private and something very specific, like _wp_ioslate_email_header_field_corrupting_violations()
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.
There was a problem hiding this comment.
Still, I'm not sure which is the difference from a release perspective. Maybe I'm missing some rule.
There was a problem hiding this comment.
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 @ignore.
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
| <element value="CharSet"/> | ||
| <element value="ContentType"/> | ||
| <element value="Encoding"/> | ||
| <element value="From"/> |
There was a problem hiding this comment.
Are these a leftover? I think they are already covered by phpcs:disable
There was a problem hiding this comment.
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.
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: #16113 Discussed in: https://core.trac.wordpress.org/ticket/66769 Props dmsnell, sirlouen, westonruter. Fixes #66769. git-svn-id: https://develop.svn.wordpress.org/trunk@65744 602fd350-edb4-49c9-b593-d223f7449a82
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: WordPress/wordpress-develop#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
Trac ticket: Core-66769
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.