mirror of
https://github.com/google/nomulus.git
synced 2025-08-14 21:44:05 +02:00
Make sure unsafe names can be sent in emails (#2169)
Surround the dot in unsafe domain names with a square bracket. This is suggested by Gmail abuse-detection and allows outgoing messages to pass Gmail's check. This should also help with recipients' checks.
This commit is contained in:
parent
2da8ea0185
commit
bd0d8af7b3
2 changed files with 18 additions and 12 deletions
|
@ -171,7 +171,7 @@ public class Spec11EmailUtils {
|
||||||
gmailClient.sendEmail(
|
gmailClient.sendEmail(
|
||||||
EmailMessage.newBuilder()
|
EmailMessage.newBuilder()
|
||||||
.setSubject(subject)
|
.setSubject(subject)
|
||||||
.setBody(getContent(date, soyTemplateInfo, registrarThreatMatches))
|
.setBody(getEmailBody(date, soyTemplateInfo, registrarThreatMatches))
|
||||||
.setContentType(MediaType.HTML_UTF_8)
|
.setContentType(MediaType.HTML_UTF_8)
|
||||||
.setFrom(outgoingEmailAddress)
|
.setFrom(outgoingEmailAddress)
|
||||||
.addRecipient(getEmailAddressForRegistrar(registrarThreatMatches.clientId()))
|
.addRecipient(getEmailAddressForRegistrar(registrarThreatMatches.clientId()))
|
||||||
|
@ -179,7 +179,7 @@ public class Spec11EmailUtils {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getContent(
|
private String getEmailBody(
|
||||||
LocalDate date,
|
LocalDate date,
|
||||||
SoyTemplateInfo soyTemplateInfo,
|
SoyTemplateInfo soyTemplateInfo,
|
||||||
RegistrarThreatMatches registrarThreatMatches) {
|
RegistrarThreatMatches registrarThreatMatches) {
|
||||||
|
@ -190,7 +190,7 @@ public class Spec11EmailUtils {
|
||||||
.map(
|
.map(
|
||||||
threatMatch ->
|
threatMatch ->
|
||||||
ImmutableMap.of(
|
ImmutableMap.of(
|
||||||
"domainName", threatMatch.domainName(),
|
"domainName", toEmailSafeString(threatMatch.domainName()),
|
||||||
"threatType", threatMatch.threatType()))
|
"threatType", threatMatch.threatType()))
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
|
|
||||||
|
@ -205,6 +205,12 @@ public class Spec11EmailUtils {
|
||||||
return renderer.render();
|
return renderer.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mutates a known bad domain to pass spam checks by Email sender and clients, as suggested by
|
||||||
|
// the Gmail abuse-detection team.
|
||||||
|
private String toEmailSafeString(String knownUnsafeDomain) {
|
||||||
|
return knownUnsafeDomain.replace(".", "[.]");
|
||||||
|
}
|
||||||
|
|
||||||
/** Sends an e-mail indicating the state of the spec11 pipeline, with a given subject and body. */
|
/** Sends an e-mail indicating the state of the spec11 pipeline, with a given subject and body. */
|
||||||
void sendAlertEmail(String subject, String body) {
|
void sendAlertEmail(String subject, String body) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -165,7 +165,7 @@ class Spec11EmailUtilsTest {
|
||||||
"the.registrar@example.com",
|
"the.registrar@example.com",
|
||||||
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
|
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedContents.get(1),
|
capturedContents.get(1),
|
||||||
|
@ -175,7 +175,7 @@ class Spec11EmailUtilsTest {
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(
|
String.format(
|
||||||
MONTHLY_EMAIL_FORMAT,
|
MONTHLY_EMAIL_FORMAT,
|
||||||
"<tr><td>b.com</td><td>MALWARE</td></tr><tr><td>c.com</td><td>MALWARE</td></tr>"),
|
"<tr><td>b[.]com</td><td>MALWARE</td></tr><tr><td>c[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedContents.get(2),
|
capturedContents.get(2),
|
||||||
|
@ -203,7 +203,7 @@ class Spec11EmailUtilsTest {
|
||||||
"the.registrar@example.com",
|
"the.registrar@example.com",
|
||||||
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
||||||
"Super Cool Registry Daily Threat Detector [2018-07-15]",
|
"Super Cool Registry Daily Threat Detector [2018-07-15]",
|
||||||
String.format(DAILY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
|
String.format(DAILY_EMAIL_FORMAT, "<tr><td>a[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(1),
|
capturedMessages.get(1),
|
||||||
|
@ -213,7 +213,7 @@ class Spec11EmailUtilsTest {
|
||||||
"Super Cool Registry Daily Threat Detector [2018-07-15]",
|
"Super Cool Registry Daily Threat Detector [2018-07-15]",
|
||||||
String.format(
|
String.format(
|
||||||
DAILY_EMAIL_FORMAT,
|
DAILY_EMAIL_FORMAT,
|
||||||
"<tr><td>b.com</td><td>MALWARE</td></tr><tr><td>c.com</td><td>MALWARE</td></tr>"),
|
"<tr><td>b[.]com</td><td>MALWARE</td></tr><tr><td>c[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(2),
|
capturedMessages.get(2),
|
||||||
|
@ -244,7 +244,7 @@ class Spec11EmailUtilsTest {
|
||||||
"new.registrar@example.com",
|
"new.registrar@example.com",
|
||||||
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>c.com</td><td>MALWARE</td></tr>"),
|
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>c[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedContents.get(1),
|
capturedContents.get(1),
|
||||||
|
@ -277,7 +277,7 @@ class Spec11EmailUtilsTest {
|
||||||
"the.registrar@example.com",
|
"the.registrar@example.com",
|
||||||
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
|
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedContents.get(1),
|
capturedContents.get(1),
|
||||||
|
@ -287,7 +287,7 @@ class Spec11EmailUtilsTest {
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(
|
String.format(
|
||||||
MONTHLY_EMAIL_FORMAT,
|
MONTHLY_EMAIL_FORMAT,
|
||||||
"<tr><td>b.com</td><td>MALWARE</td></tr><tr><td>c.com</td><td>MALWARE</td></tr>"),
|
"<tr><td>b[.]com</td><td>MALWARE</td></tr><tr><td>c[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedContents.get(2),
|
capturedContents.get(2),
|
||||||
|
@ -332,7 +332,7 @@ class Spec11EmailUtilsTest {
|
||||||
"the.registrar@example.com",
|
"the.registrar@example.com",
|
||||||
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
ImmutableList.of("abuse@test.com", "bcc@test.com"),
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a.com</td><td>MALWARE</td></tr>"),
|
String.format(MONTHLY_EMAIL_FORMAT, "<tr><td>a[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(1),
|
capturedMessages.get(1),
|
||||||
|
@ -342,7 +342,7 @@ class Spec11EmailUtilsTest {
|
||||||
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
"Super Cool Registry Monthly Threat Detector [2018-07-15]",
|
||||||
String.format(
|
String.format(
|
||||||
MONTHLY_EMAIL_FORMAT,
|
MONTHLY_EMAIL_FORMAT,
|
||||||
"<tr><td>b.com</td><td>MALWARE</td></tr><tr><td>c.com</td><td>MALWARE</td></tr>"),
|
"<tr><td>b[.]com</td><td>MALWARE</td></tr><tr><td>c[.]com</td><td>MALWARE</td></tr>"),
|
||||||
Optional.of(MediaType.HTML_UTF_8));
|
Optional.of(MediaType.HTML_UTF_8));
|
||||||
validateMessage(
|
validateMessage(
|
||||||
capturedMessages.get(2),
|
capturedMessages.get(2),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue