-
Notifications
You must be signed in to change notification settings - Fork 0
Potential fix for code scanning alert no. 9: Exposure of private information #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,21 @@ | |||||
| private readonly EmailAccountConfig _emailAccountConfig; | ||||||
| private readonly ILogger<EmailService> _logger; | ||||||
|
|
||||||
| private static string MaskEmail(string email) | ||||||
| { | ||||||
| if (string.IsNullOrWhiteSpace(email)) return string.Empty; | ||||||
|
|
||||||
| var atIndex = email.IndexOf('@'); | ||||||
| if (atIndex <= 0 || atIndex == email.Length - 1) return "***"; | ||||||
|
|
||||||
| var localPart = email.Substring(0, atIndex); | ||||||
| var domainPart = email.Substring(atIndex + 1); | ||||||
|
|
||||||
| if (localPart.Length <= 1) | ||||||
| return "*@" + domainPart; | ||||||
|
|
||||||
| return localPart[0] + new string('*', Math.Max(1, localPart.Length - 1)) + "@" + domainPart; | ||||||
| } | ||||||
|
|
||||||
| public EmailService(ILogger<EmailService> logger, IOptions<EmailAccountConfig> options) | ||||||
| { | ||||||
|
|
@@ -21,7 +36,8 @@ | |||||
| public async Task<MessageSentEventArgs> SendEmailAsync(string subject, string body, string toName, string toAddress) | ||||||
| { | ||||||
| var sanitizedToAddress = toAddress.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", ""); | ||||||
| _logger.LogDebug("Sending email, subject: {Subject}, recipient: {ToAddress}", subject, sanitizedToAddress); | ||||||
| var maskedToAddress = MaskEmail(sanitizedToAddress); | ||||||
| _logger.LogDebug("Sending email, subject: {Subject}, recipient: {ToAddress}", subject, maskedToAddress); | ||||||
Check warningCode scanning / CodeQL Exposure of private information Medium
Private data returned by
access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by access to parameter email Error loading related location Loading Private data returned by call to method MaskEmail Error loading related location Loading |
||||||
|
|
||||||
| body += $"<br><p>This message was automatically sent by {BlogLink}, no need to reply.</p>"; | ||||||
| return await EmailUtils.SendEmailAsync(_emailAccountConfig, subject, body, toName, toAddress); | ||||||
|
||||||
| return await EmailUtils.SendEmailAsync(_emailAccountConfig, subject, body, toName, toAddress); | |
| return await EmailUtils.SendEmailAsync(_emailAccountConfig, subject, body, toName, sanitizedToAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaskEmailpreserves the full domain (and local-part length), which can still be considered private information (e.g., corporate domains) and may still match email-detection rules in code scanning. Consider masking the domain as well (e.g., keep only the TLD/first char) or logging a non-reversible identifier (hash) instead of any recognizable email form.