A platform for community discussion. Free, open, simple.
SECURITY: missing security check prior to redirect
Sam Saffron5bfb6830c972
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 211e94ce8df..bca0bde2dee 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -945,6 +945,8 @@ class TopicsController < ApplicationControllerenddef redirect_to_correct_topic(topic, post_number = nil)+ guardian.ensure_can_see!(topic)+url = topic.relative_urlurl << "/#{post_number}" if post_number.to_i > 0url << ".json" if request.format.json?diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 9649f57f5ba..bc80fa92833 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1357,6 +1357,17 @@ RSpec.describe TopicsController doexpect(response).to redirect_to(topic.relative_url)end+ it 'will return a 403 if you try to redirect to a topic you have no access to' do+ category = Fabricate(:category)+ category.set_permissions(Group::AUTO_GROUPS[:staff] => :full)+ category.save!++ topic.update!(category_id: category.id)+ get "/t/#{topic.slug}"++ expect(response.status).to eq(403)+ end+it 'can find a topic when a slug has a number in front' doanother_topic = Fabricate(:post).topic