mirror of
https://github.com/bitwarden/server
synced 2025-12-29 22:54:00 +00:00
[PM-27766] Add policy for blocking account creation from claimed domains. (#6537)
* Add policy for blocking account creation from claimed domains. * dotnet format * check as part of email verification * add feature flag * fix tests * try to fix dates on database integration tests * PR feedback from claude * remove claude local settings * pr feedback * format * fix test * create or alter * PR feedback * PR feedback * Update src/Core/Constants.cs Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * fix merge issues * fix tests --------- Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net.Mail;
|
||||
using System.Text.RegularExpressions;
|
||||
using Bit.Core.Exceptions;
|
||||
using MimeKit;
|
||||
|
||||
namespace Bit.Core.Utilities;
|
||||
@@ -41,4 +43,22 @@ public static class EmailValidation
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the domain portion from an email address and normalizes it to lowercase.
|
||||
/// </summary>
|
||||
/// <param name="email">The email address to extract the domain from.</param>
|
||||
/// <returns>The domain portion of the email address in lowercase (e.g., "example.com").</returns>
|
||||
/// <exception cref="BadRequestException">Thrown when the email address format is invalid.</exception>
|
||||
public static string GetDomain(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new MailAddress(email).Host.ToLower();
|
||||
}
|
||||
catch (Exception ex) when (ex is FormatException || ex is ArgumentException)
|
||||
{
|
||||
throw new BadRequestException("Invalid email address format.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user