diff --git a/eng/Versions.props b/eng/Versions.props
index d739bd35d783e5..5f1fcbcd517fb8 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -233,7 +233,7 @@
8.0.0-rtm.25625.2
- 2.4.16
+ 2.4.17
16.0.5-alpha.1.25311.1
16.0.5-alpha.1.25311.1
diff --git a/eng/pipelines/common/xplat-setup.yml b/eng/pipelines/common/xplat-setup.yml
index 5292eb6fc2bada..58a8ee2e7a1461 100644
--- a/eng/pipelines/common/xplat-setup.yml
+++ b/eng/pipelines/common/xplat-setup.yml
@@ -171,7 +171,7 @@ jobs:
# Official Build Linux Pool
${{ if and(or(in(parameters.osGroup, 'linux', 'freebsd', 'android', 'tizen'), eq(parameters.jobParameters.hostedOs, 'linux')), ne(variables['System.TeamProject'], 'public')) }}:
name: $(DncEngInternalBuildPool)
- demands: ImageOverride -equals 1es-ubuntu-2204
+ demands: ImageOverride -equals build.azurelinux.3.amd64
os: linux
# OSX Public Build Pool (we don't have on-prem OSX BuildPool).
diff --git a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs
index de5a86a64ac8c0..a8f9ea5abcec73 100644
--- a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs
+++ b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs
@@ -7,9 +7,6 @@ namespace System.ComponentModel.DataAnnotations
AllowMultiple = false)]
public sealed class EmailAddressAttribute : DataTypeAttribute
{
- private static bool EnableFullDomainLiterals { get; } =
- AppContext.TryGetSwitch("System.Net.AllowFullDomainLiterals", out bool enable) ? enable : false;
-
public EmailAddressAttribute()
: base(DataType.EmailAddress)
{
@@ -30,7 +27,7 @@ public override bool IsValid(object? value)
return false;
}
- if (!EnableFullDomainLiterals && (valueAsString.Contains('\r') || valueAsString.Contains('\n')))
+ if (valueAsString.Contains('\r') || valueAsString.Contains('\n'))
{
return false;
}
diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs
index 644f7502ff7763..2942e6fba0d90e 100644
--- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs
+++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs
@@ -15,9 +15,6 @@ namespace System.Net.Mail
//
public partial class MailAddress
{
- private static bool EnableFullDomainLiterals { get; } =
- AppContext.TryGetSwitch("System.Net.AllowFullDomainLiterals", out bool enable) ? enable : false;
-
// These components form an e-mail address when assembled as follows:
// "EncodedDisplayname"
private readonly Encoding _displayNameEncoding;
@@ -220,7 +217,7 @@ private string GetHost(bool allowUnicode)
}
}
- if (!EnableFullDomainLiterals && domain.AsSpan().IndexOfAny('\r', '\n') >= 0)
+ if (domain.AsSpan().IndexOfAny('\r', '\n') >= 0)
{
throw new SmtpException(SR.Format(SR.SmtpInvalidHostName, Address));
}
diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressParser.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressParser.cs
index fe57dd93c14591..252a9520c26957 100644
--- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressParser.cs
+++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressParser.cs
@@ -68,6 +68,20 @@ private static bool TryParseAddress(string data, bool expectMultipleAddresses, r
Debug.Assert(!string.IsNullOrEmpty(data));
Debug.Assert(index >= 0 && index < data.Length, $"Index out of range: {index}, {data.Length}");
+ // Check for CR or LF characters which are not allowed in mail addresses.
+ // Only scan on the first call (index == data.Length - 1) to avoid repeated O(n) scans
+ // when parsing multiple addresses from the same string.
+ if (index == data.Length - 1 && MailBnfHelper.HasCROrLF(data))
+ {
+ if (throwExceptionIfFail)
+ {
+ throw new FormatException(SR.MailAddressInvalidFormat);
+ }
+
+ parseAddressInfo = default;
+ return false;
+ }
+
// Parsed components to be assembled as a MailAddress later
string? displayName;
diff --git a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs
index a9cf0bca251ce8..c2cf89efb6d76b 100644
--- a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs
+++ b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs
@@ -14,10 +14,8 @@
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Sockets;
-using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.DotNet.RemoteExecutor;
using Systen.Net.Mail.Tests;
using System.Net.Test.Common;
using Xunit;
@@ -578,58 +576,19 @@ public void TestGssapiAuthentication()
Assert.Equal("GSSAPI", server.AuthMethodUsed, StringComparer.OrdinalIgnoreCase);
}
- [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
- [InlineData("foo@[\r\n bar]")]
- [InlineData("foo@[bar\r\n ]")]
- [InlineData("foo@[bar\r\n baz]")]
- public void MultiLineDomainLiterals_Enabled_Success(string input)
- {
- RemoteExecutor.Invoke(static (string @input) =>
- {
- AppContext.SetSwitch("System.Net.AllowFullDomainLiterals", true);
-
- var address = new MailAddress(@input);
-
- // Using address with new line breaks the protocol so we cannot easily use LoopbackSmtpServer
- // Instead we call internal method that does the extra validation.
- string? host = (string?)typeof(MailAddress).InvokeMember("GetAddress", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, address, new object[] { true });
- Assert.Equal(input, host);
- }, input).Dispose();
- }
-
[Theory]
[MemberData(nameof(SendMail_MultiLineDomainLiterals_Data))]
- public async Task SendMail_MultiLineDomainLiterals_Disabled_Throws(string from, string to, bool asyncSend)
+ public void SendMail_MultiLineDomainLiterals_Disabled_Throws(string from, string to)
{
- using var server = new LoopbackSmtpServer();
-
- using SmtpClient client = server.CreateClient();
- client.Credentials = new NetworkCredential("Foo", "Bar");
-
- using var msg = new MailMessage(@from, @to, "subject", "body");
-
- await Assert.ThrowsAsync(async () =>
- {
- if (asyncSend)
- {
- await client.SendMailAsync(msg).WaitAsync(TimeSpan.FromSeconds(30));
- }
- else
- {
- client.Send(msg);
- }
- });
+ Assert.Throws(() => new MailMessage(@from, @to, "subject", "body"));
}
public static IEnumerable