From 8221dd39cfb62203d888981ac40dbcd6c69fab81 Mon Sep 17 00:00:00 2001
From: Artur Plysyuk
Date: Tue, 1 Sep 2020 00:04:31 +0300
Subject: [PATCH] Fix XSS in email viewer
---
lib/bamboo/plug/sent_email_viewer/index.html.eex | 12 ++++++++----
lib/mix/start_sent_email_viewer_task.ex | 4 ++--
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/lib/bamboo/plug/sent_email_viewer/index.html.eex b/lib/bamboo/plug/sent_email_viewer/index.html.eex
index 9d765833..5ec51434 100644
--- a/lib/bamboo/plug/sent_email_viewer/index.html.eex
+++ b/lib/bamboo/plug/sent_email_viewer/index.html.eex
@@ -145,18 +145,22 @@
">
- <%= email.subject %>
+
+ <%= Plug.HTML.html_escape(email.subject) %>
+
<%= Bamboo.SentEmailViewerPlug.Helper.format_email_address(email.from) %>
to <%= Bamboo.SentEmailViewerPlug.Helper.email_addresses(email) %>
- <%= email.text_body %>
+
+ <%= Plug.HTML.html_escape(email.text_body) %>
+
<% end %>
- <%= @selected_email.subject %>
+ <%= Plug.HTML.html_escape(@selected_email.subject) %>
From <%= Bamboo.SentEmailViewerPlug.Helper.format_email_address(@selected_email.from) %>
to <%= Bamboo.SentEmailViewerPlug.Helper.email_addresses(@selected_email) %>
@@ -183,7 +187,7 @@
Text Body
- <%= @selected_email.text_body %>
+ <%= Plug.HTML.html_escape(@selected_email.text_body) %>
diff --git a/lib/mix/start_sent_email_viewer_task.ex b/lib/mix/start_sent_email_viewer_task.ex
index 7f332876..0ccf7bb4 100644
--- a/lib/mix/start_sent_email_viewer_task.ex
+++ b/lib/mix/start_sent_email_viewer_task.ex
@@ -15,7 +15,7 @@ defmodule Mix.Tasks.Bamboo.StartSentEmailViewer do
Bamboo.Email.new_email(
from: "me@gmail.com",
to: "someone@foo.com",
- subject: "#{index} - This is a long subject for testing truncation",
+ subject: "#{index} - This is a long subject for testing truncation",
html_body: """
Check different tag styling
@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Bamboo.StartSentEmailViewer do
long to see how it expands on to the next line
Sincerely,
- Me
+ Me and html tag
"""
)
|> Bamboo.Mailer.normalize_addresses()