feat: sanitize user email input with wp_unslash() in email notificati…#9283
feat: sanitize user email input with wp_unslash() in email notificati…#9283kushagra-goyal-14 wants to merge 2 commits intoWordPress:trunkfrom
Conversation
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. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
Fix Email Escaping Bug in WordPress Notifications
Overview
This pull request fixes a critical bug where WordPress was incorrectly escaping special characters (like apostrophes) in email addresses for certain notifications, resulting in malformed email addresses with backslashes (e.g.,
o\'connor@example.cominstead ofo'connor@example.com).This addresses the inconsistent email handling where some notifications worked correctly while others failed validation or delivery for email addresses containing special characters.
Trac Ticket: #54416
Issue Fixed
Email Addresses With Special Characters Show Backslashes in Notifications
Problem:
Email addresses containing special characters (apostrophes, quotes, etc.) were being escaped in certain WordPress notifications:
$_POST['email']data directly$user['user_email']data directly$user['user_email']data directlyo\'connor@example.com) or emails failed validation entirelyRoot Cause:
WordPress's
add_magic_quotes()function adds slashes to all$_POSTdata and user arrays, but the affected email functions were using this slashed data directly without callingwp_unslash()first.Solution:
Applied
wp_unslash()to all email address usages in the affected functions to ensure clean, properly formatted email addresses in all notifications.Code Changes
1. Email Change Confirmation (
send_confirmation_on_profile_email)2. Email Change Notification (
wp_update_user)3. Password Change Notification (
wp_update_user)Testing Instructions
Test Case 1: Email Change Confirmation
user@example.com)o'connor@example.com)o'connor@example.com(without backslashes)o'connor@example.com(without backslashes)Test Case 2: Email Change Notification
user@example.com)o'connor@example.com(without backslashes)Test Case 3: Password Change Notification
user's.email@example.com)user's.email@example.com(without backslashes)user's.email@example.com(without backslashes)