SECURITY: make find topic by slug adhere to SiteSetting.detailed_404 (#9898)
This commit is contained in:
parent
745d1de40c
commit
b6ff3b6a26
@ -946,6 +946,16 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
|
||||
def redirect_to_correct_topic(topic, post_number = nil)
|
||||
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 << "/#{post_number}" if post_number.to_i > 0
|
||||
url << ".json" if request.format.json?
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# coding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
@ -1405,6 +1406,12 @@ RSpec.describe TopicsController do
|
||||
expect(response.status).to eq(value)
|
||||
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
|
||||
|
||||
context 'without detailed error pages' do
|
||||
|
||||
Reference in New Issue
Block a user