A platform for community discussion. Free, open, simple.
SECURITY: do not show private topic title on /unsubscribed page
Arpit Jalana1ef455c785d
diff --git a/app/controllers/email_controller.rb b/app/controllers/email_controller.rbindex 8fd9e9bbcf6..cff20ff7c05 100644--- a/app/controllers/email_controller.rb+++ b/app/controllers/email_controller.rb@@ -110,10 +110,11 @@ class EmailController < ApplicationControllerdef unsubscribed@email = params[:email]+ @topic_id = params[:topic_id]user = User.find_by_email(params[:email])raise Discourse::NotFound unless user- @topic = Topic.find_by(id: params[:topic_id].to_i) if params[:topic_id]- raise Discourse::NotFound unless Guardian.new(user).can_see?(@topic)+ topic = Topic.find_by(id: params[:topic_id].to_i) if @topic_id+ @topic = topic if topic && Guardian.new(nil).can_see?(topic)endenddiff --git a/app/views/email/unsubscribed.html.erb b/app/views/email/unsubscribed.html.erbindex a593bfed31b..e57a2a14eba 100644--- a/app/views/email/unsubscribed.html.erb+++ b/app/views/email/unsubscribed.html.erb@@ -7,8 +7,8 @@</p><% if @topic %>- <p>- <%=t("unsubscribed.topic_description", link: render_topic_title(@topic)).html_safe%>- </p>+ <p><%=t("unsubscribed.topic_description", link: render_topic_title(@topic)).html_safe%></p>+ <% elsif @topic_id %>+ <p><%=t("unsubscribed.private_topic_description")%></p><% end %></div>diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 879b47c916f..2c4ac31006d 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -798,6 +798,7 @@ en:title: "Unsubscribed!"description: "<b>%{email}</b> has been unsubscribed. To change your email settings <a href='%{url}'>visit your user preferences</a>."topic_description: "To re-subscribe to %{link}, use the notification control at the bottom or right of the topic."+ private_topic_description: "To re-subscribe, use the notification control at the bottom or right of the topic."unsubscribe:title: "Unsubscribe"diff --git a/spec/requests/email_controller_spec.rb b/spec/requests/email_controller_spec.rbindex c6d7119481d..c51aa276f21 100644--- a/spec/requests/email_controller_spec.rb+++ b/spec/requests/email_controller_spec.rb@@ -1,6 +1,10 @@require 'rails_helper'RSpec.describe EmailController do+ let(:user) { Fabricate(:user) }+ let(:topic) { Fabricate(:topic) }+ let(:private_topic) { Fabricate(:private_message_topic) }+describe '#unsubscribed' dodescribe 'when email is invalid' doit 'should return the right response' do@@ -8,5 +12,21 @@ RSpec.describe EmailController doexpect(response.status).to eq(404)endend++ describe 'when topic is public' do+ it 'should return the right response' do+ get '/email/unsubscribed', params: { email: user.email, topic_id: topic.id }+ expect(response).to be_success+ expect(response.body).to include(topic.title)+ end+ end++ describe 'when topic is private' do+ it 'should return the right response' do+ get '/email/unsubscribed', params: { email: user.email, topic_id: private_topic.id }+ expect(response).to be_success+ expect(response.body).to_not include(private_topic.title)+ end+ endendend