|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-11-27 00:54 UTC] ndavison85 at gmail dot com
Description:
------------
The PHP function mailparse_rfc822_parse_addresses is parsing the payload "<aaa@bbb.com>xxx@yyy.com" as a valid email address string, returning both "aaa@bbb.com" and "xxx@yyy.com" as valid addresses. I do not believe this is consistent with the RFC.
The reason I have flagged this as a security issue is because I believe this can lead to security flaws in PHP apps where by the app logic may expect a single address in the string (perhaps because the code is first stripping out commas and semi colons from the string), and then proceed to use the output of mailparse_rfc822_parse_addresses on the string to determine the email address, which may not be consistent with the way the backend email system handles the payload.
For example, I'm aware of one popular emailing service that will accept this payload and send the message to "aaa@bbb.com", but if the PHP code handles the output of mailparse_rfc822_parse_addresses and takes the last Array element from its return and uses that to determine which domain the email is being sent to, it will consider the email to be "xxx@yyy.com". In apps that might grant privileges or make access control decisions based on user's email domain, this could be a significant vulnerability.
My research across various languages and their standard ways to parse email addresses leaves mailparse_rfc822_parse_addresses as the only technique which returns a valid value (the rest either return null or raise an error when given this payload). This includes the PEAR Mail_RFC822::parseAddressList(), which returns a validation failure when given this payload.
Test script:
---------------
<?php
$addrs = mailparse_rfc822_parse_addresses("<aaa@bbb.com>xxx@yyy.com");
if ($addrs[0]['address'] === 'aaa@bbb.com') {
echo "contains aaa@bbb.com\n";
}
if ($addrs[1]['address'] === 'xxx@yyy.com') {
echo "contains xxx@yyy.com\n";
}
Expected result:
----------------
I would expect the return to either be empty, null, false etc, or return a single Array element with "aaa@bbb.com" as the valid address (although, I still don't believe the latter is consistent with the RFC).
Actual result:
--------------
An Array with two elements, containing both "aaa@bbb.com" and "xxx@yyy.com" as valid email addresses.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 02:00:01 2025 UTC |
This is a bit unrelated to the original bug (similar threat, different payload), but I've also noticed that mailparse_rfc822_parse_addresses will terminate at a null byte (without error) which could allow an attacker to get an email on one domain but the rest of the PHP code may treat the string to be another domain. Snippet for this: $ php -r 'print_r(mailparse_rfc822_parse_addresses("aaa@bbb.com\x00.ddd.com"));' Array ( [0] => Array ( [display] => aaa@bbb.com [address] => aaa@bbb.com [is_group] => ) ) This wouldn't really be a problem if the output of mailparse_rfc822_parse_addresses is used for both determining the address for app logic and for the mail server, but if for some reason this was only used for one of those, then it could result in vulnerabilities. Should I open a new bug for this?