Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Prevent error reports from being sent with short feedback (#2635)

Adam Rutkowskif678cfab25b5
diff --git a/lib/plausible_web/controllers/error_report_controller.ex b/lib/plausible_web/controllers/error_report_controller.ex
index 7d48f1a57c..b830047765 100644
--- a/lib/plausible_web/controllers/error_report_controller.ex
+++ b/lib/plausible_web/controllers/error_report_controller.ex
@@ -6,10 +6,12 @@ defmodule PlausibleWeb.ErrorReportController do
def submit_error_report(conn, %{
"error" => %{"trace_id" => trace_id, "user_feedback" => feedback}
}) do
- reported_by = "#{conn.assigns.current_user.name} <#{conn.assigns.current_user.email}>"
- email_template = PlausibleWeb.Email.error_report(reported_by, trace_id, feedback)
+ if String.length(String.trim(feedback)) > 5 do
+ reported_by = "#{conn.assigns.current_user.name} <#{conn.assigns.current_user.email}>"
+ email_template = PlausibleWeb.Email.error_report(reported_by, trace_id, feedback)
- Plausible.Mailer.deliver_later(email_template)
+ Plausible.Mailer.deliver_later(email_template)
+ end
thanks(conn)
end
diff --git a/test/plausible_web/controllers/error_report_controller_test.exs b/test/plausible_web/controllers/error_report_controller_test.exs
index fe269837fc..fd97957d20 100644
--- a/test/plausible_web/controllers/error_report_controller_test.exs
+++ b/test/plausible_web/controllers/error_report_controller_test.exs
@@ -68,6 +68,22 @@ defmodule PlausibleWeb.ErrorReportControllerTest do
})
end
+ test "short feedback is not sent", %{conn: conn} do
+ action_path = Routes.error_report_path(Endpoint, :submit_error_report)
+
+ conn =
+ post(conn, action_path, %{
+ "error" => %{"trace_id" => "some-trace-id", "user_feedback" => "short"}
+ })
+
+ assert html = html_response(conn, 200)
+ assert html =~ "Your report has been submitted"
+
+ refute_email_delivered_with(%{
+ subject: "Feedback to Sentry Trace some-trace-id"
+ })
+ end
+
test "submitting no feedback for authenticated user", %{conn: conn} do
action_path = Routes.error_report_path(Endpoint, :submit_error_report)