mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 20:35:40 +08:00
SECURITY: make find topic by slug adhere to SiteSetting.detailed_404 (#9898)
This commit is contained in:
parent
77801aa9be
commit
a9d92f338e
@ -945,7 +945,15 @@ class TopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def redirect_to_correct_topic(topic, post_number = nil)
|
def redirect_to_correct_topic(topic, post_number = nil)
|
||||||
guardian.ensure_can_see!(topic)
|
begin
|
||||||
|
guardian.ensure_can_see!(topic)
|
||||||
|
rescue Discourse::InvalidAccess => ex
|
||||||
|
if !SiteSetting.detailed_404
|
||||||
|
raise Discourse::NotFound
|
||||||
|
else
|
||||||
|
raise ex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
url = topic.relative_url
|
url = topic.relative_url
|
||||||
url << "/#{post_number}" if post_number.to_i > 0
|
url << "/#{post_number}" if post_number.to_i > 0
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# coding: utf-8
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
@ -1357,17 +1358,6 @@ RSpec.describe TopicsController do
|
|||||||
expect(response).to redirect_to(topic.relative_url)
|
expect(response).to redirect_to(topic.relative_url)
|
||||||
end
|
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' do
|
it 'can find a topic when a slug has a number in front' do
|
||||||
another_topic = Fabricate(:post).topic
|
another_topic = Fabricate(:post).topic
|
||||||
|
|
||||||
@ -1463,6 +1453,12 @@ RSpec.describe TopicsController do
|
|||||||
expect(response.status).to eq(value)
|
expect(response.status).to eq(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expected_slug_response = expected[:secure_topic] == 200 ? 301 : expected[:secure_topic]
|
||||||
|
it "will return a #{expected_slug_response} when requesting a secure topic by slug" do
|
||||||
|
get "/t/#{secure_topic.slug}"
|
||||||
|
expect(response.status).to eq(expected_slug_response)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without detailed error pages' do
|
context 'without detailed error pages' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user