Skip to content

Commit

Permalink
fix(ZNTA-544): incoming email message to plaintext
Browse files Browse the repository at this point in the history
Incoming messages should be plaintext, to avoid malicious links
hidden in anchors
  • Loading branch information
djansen-redhat committed May 16, 2018
1 parent 262358c commit 6d4d331
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Expand Up @@ -52,8 +52,9 @@ public Map<String, Object> makeContext(Map<String, Object> genericContext,
InternetAddress[] toAddresses) {
Map<String, Object> context =
super.makeContext(genericContext, toAddresses);
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage);
return context.put("ipAddress", ipAddress).put("htmlMessage", safeHTML);
String plainText = HtmlUtil.htmlToText(
HtmlUtil.SANITIZER.sanitize(htmlMessage));
return context.put("ipAddress", ipAddress).put("htmlMessage", plainText);
}

@java.beans.ConstructorProperties({ "ipAddress", "userSubject",
Expand Down
Expand Up @@ -59,10 +59,11 @@ public Map<String, Object> makeContext(Map<String, Object> genericContext,
InternetAddress[] toAddresses) {
Map<String, Object> context =
super.makeContext(genericContext, toAddresses);
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage);
String plainText = HtmlUtil.htmlToText(
HtmlUtil.SANITIZER.sanitize(htmlMessage));
return context.put("fromLoginName", fromLoginName)
.put("fromName", fromName).put("replyEmail", replyEmail)
.put("htmlMessage", safeHTML);
.put("htmlMessage", plainText);
}

@java.beans.ConstructorProperties({ "fromLoginName", "fromName",
Expand Down
Expand Up @@ -62,13 +62,14 @@ public Map<String, Object> makeContext(Map<String, Object> genericContext,
InternetAddress[] toAddresses) {
Map<String, Object> context =
super.makeContext(genericContext, toAddresses);
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage);
String plainText = HtmlUtil.htmlToText(
HtmlUtil.SANITIZER.sanitize(htmlMessage));
return context.put("receiver", receiver)
.put("fromLoginName", fromLoginName)
.put("fromName", fromName).put("replyEmail", replyEmail)
.put("localeId", localeId)
.put("localeNativeName", localeNativeName)
.put("htmlMessage", safeHTML);
.put("htmlMessage", plainText);
}

@java.beans.ConstructorProperties({ "receiver", "fromLoginName", "fromName",
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.zanata.i18n.Messages;
import org.zanata.util.HtmlUtil;
import javax.mail.internet.InternetAddress;

import static org.zanata.email.Addresses.getReplyTo;

/**
Expand Down Expand Up @@ -63,12 +64,13 @@ public Map<String, Object> makeContext(Map<String, Object> genericContext,
InternetAddress[] toAddresses) {
Map<String, Object> context =
super.makeContext(genericContext, toAddresses);
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage);
String plainText = HtmlUtil.htmlToText(
HtmlUtil.SANITIZER.sanitize(htmlMessage));
return context.put("fromLoginName", fromLoginName)
.put("fromName", fromName).put("replyEmail", replyEmail)
.put("localeId", localeId)
.put("localeNativeName", localeNativeName)
.put("htmlMessage", safeHTML)
.put("htmlMessage", plainText)
.put("requestAsTranslator", requestAsTranslator)
.put("requestAsReviewer", requestAsReviewer)
.put("requestAsCoordinator", requestAsCoordinator);
Expand Down
Expand Up @@ -62,12 +62,13 @@ public Map<String, Object> makeContext(Map<String, Object> genericContext,
InternetAddress[] toAddresses) {
Map<String, Object> context =
super.makeContext(genericContext, toAddresses);
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage);
String plainText = HtmlUtil.htmlToText(
HtmlUtil.SANITIZER.sanitize(htmlMessage));
return context.put("fromLoginName", fromLoginName)
.put("fromName", fromName).put("replyEmail", replyEmail)
.put("groupName", groupName).put("versionGroupSlug", groupSlug)
.put("projectIterationIds", projectIterationIds)
.put("htmlMessage", safeHTML);
.put("htmlMessage", plainText);
}

@java.beans.ConstructorProperties({ "fromLoginName", "fromName",
Expand Down

0 comments on commit 6d4d331

Please sign in to comment.