Skip to content
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

Sharedaddy: Protect against malformed from names. #6769

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/sharedaddy/sharedaddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ function sharing_email_send_post( $data ) {
/** This filter is documented in core/src/wp-includes/pluggable.php */
$from_email = apply_filters( 'wp_mail_from', 'wordpress@' . $sitename );

if ( ! empty( $data['name'] ) ) {
$s_name = (string) $data['name'];
$name_needs_encoding_regex =
'/[' .
// SpamAssasin's list of characters which "need MIME" encoding
'\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff' .
// Our list of "unsafe" characters
'<\r\n' .
']/';

$needs_encoding =
// If it contains any blacklisted chars,
preg_match( $name_needs_encoding_regex, $s_name ) ||
// Or if we can't use `mb_convert_encoding`
! function_exists( 'mb_convert_encoding' ) ||
// Or if it's not already ASCII
mb_convert_encoding( $data['name'], 'ASCII' ) !== $s_name;

if ( $needs_encoding ) {
$data['name'] = sprintf( '=?UTF-8?B?%s?=', base64_encode( $data['name'] ) );
}
}

$headers[] = sprintf( 'From: %1$s <%2$s>', $data['name'], $from_email );
$headers[] = sprintf( 'Reply-To: %1$s <%2$s>', $data['name'], $data['source'] );

Expand Down