{"thread":{"id":"63355","subject":"[PATCH] send-mail: improve checks for valid_fqdn","startedAt":"2025-04-26T18:15:36Z","lastAt":"2025-04-26T18:15:36Z","messageCount":1,"participants":["Aditya Garg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"516852","messageId":"PN0PR01MB9588EBBF200EA002E558D4E0B8872@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","threadId":"63355","inReplyTo":null,"subject":"[PATCH] send-mail: improve checks for valid_fqdn","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-04-26T18:15:12Z","receivedAt":"2025-04-26T18:15:36Z","isPatch":true,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"The current implementation of a valid Fully Qualified Domain Name\nis not that strict. It just checks whether it has a dot (.) and\nif using macOS, it should not end with .local. As per RFC1035[1],\nfrom what I understood, the following checks need to be done:\n\n- The domain must contain atleast one dot\n- Each label (separated by dots) must be 1-63 characters long\n- Labels must start and end with an alphanumeric character\n- Labels can contain alphanumeric characters and hyphens\n\nHere are some examples of valid and invalid labels:\n\n'example.com',          # Valid\n'sub.example.com',      # Valid\n'my-domain.org',        # Valid\n'localhost',            # Invalid (no dot)\n'MacBook..',            # Invalid (double dots)\n'-example.com',         # Invalid (starts with a hyphen)\n'example-.com',         # Invalid (ends with a hyphen)\n'example..com',         # Invalid (double dots)\n'example',              # Invalid (no TLD)\n'example.local',        # Invalid on macOS\n'valid-domain.co.uk',   # Valid\n'123.example.com',      # Valid\n'example.com.',         # Invalid (trailing dot)\n'toolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabel.com', # Invalid (label > 63 chars)\n\nDue to current implementation, I was not able to send emails from\nUbuntu. Upon debugging, I found that the SMTP domain was coming out\nto be \"MacBook..\" and was being considered as valid. As a result\nthe script was failing. The debug logs with the failed script are\nbelow:\n\nNet::SMTP>>> Net::SMTP(3.15)\nNet::SMTP>>>   Net::Cmd(3.15)\nNet::SMTP>>>     Exporter(5.77)\nNet::SMTP>>>   IO::Socket::IP(0.4101)\nNet::SMTP>>>     IO::Socket(1.52)\nNet::SMTP>>>       IO::Handle(1.52)\nNet::SMTP=GLOB(0x5db4351225f8)<<< 220 BMXPR01CA0083.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 26 Apr 2025 18:06:30 +0000 [08DD842467C8274D]\nNet::SMTP=GLOB(0x5db4351225f8)>>> EHLO MacBook..\nNet::SMTP=GLOB(0x5db4351225f8)<<< 501 5.5.4 Invalid domain name [BMXPR01CA0083.INDPRD01.PROD.OUTLOOK.COM 2025-04-26T18:06:35.781Z 08DD842467C8274D]\nNet::SMTP=GLOB(0x5db4351225f8)>>> HELO MacBook..\nNet::SMTP=GLOB(0x5db4351225f8)<<< 501 5.5.4 Invalid domain name [BMXPR01CA0083.INDPRD01.PROD.OUTLOOK.COM 2025-04-26T18:06:40.828Z 08DD842467C8274D]\nUnable to initialize SMTP properly. Check config and use --smtp-debug. VALUES: server=smtp.office365.com encryption=tls hello=MacBook.. port=587 at ../git-send-email.perl line 1727.\n\nWith this patch, it was fixed and was being considered as an invalid\ndomain. Logs after this patch:\n\nNet::SMTP>>> Net::SMTP(3.15)\nNet::SMTP>>>   Net::Cmd(3.15)\nNet::SMTP>>>     Exporter(5.77)\nNet::SMTP>>>   IO::Socket::IP(0.4101)\nNet::SMTP>>>     IO::Socket(1.52)\nNet::SMTP>>>       IO::Handle(1.52)\nNet::SMTP=GLOB(0x58c8af71e930)<<< 220 PN4P287CA0064.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 26 Apr 2025 18:08:13 +0000 [08DD84B323498C1A]\nNet::SMTP=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897]\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-PIPELINING\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-DSN\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-STARTTLS\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-8BITMIME\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-BINARYMIME\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250-CHUNKING\nNet::SMTP=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8\nNet::SMTP=GLOB(0x58c8af71e930)>>> STARTTLS\nNet::SMTP=GLOB(0x58c8af71e930)<<< 220 2.0.0 SMTP server ready\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897]\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PIPELINING\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-DSN\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-AUTH LOGIN XOAUTH2\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-8BITMIME\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-BINARYMIME\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-CHUNKING\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897]\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PIPELINING\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-DSN\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-AUTH LOGIN XOAUTH2\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-8BITMIME\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-BINARYMIME\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-CHUNKING\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)>>> AUTH XOAUTH2 (OAuth2 access token removed for security)\nNet::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 235 2.7.0 Authentication successful\n\n[1]: https://datatracker.ietf.org/doc/html/rfc1035\nSigned-off-by: Aditya Garg <gargaditya08@live.com>\n---\n git-send-email.perl | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 618474916e..f14b25d718 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1354,7 +1354,8 @@ sub process_address_list {\n \n sub valid_fqdn {\n \tmy $domain = shift;\n-\treturn defined $domain && !($^O eq 'darwin' && $domain =~ /\\.local$/) && $domain =~ /\\./;\n+\treturn defined $domain && !($^O eq 'darwin' && $domain =~ /\\.local$/)\n+\t\t&& $domain  =~ /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\\.[A-Za-z0-9-]{1,63})+$/;\n }\n \n sub maildomain_net {\n-- \n2.43.0\n\n"}]}