mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Better and more secure validation of periods for TopicQuery
Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
This commit is contained in:
@@ -57,8 +57,13 @@ class EmbedController < ApplicationController
|
||||
end
|
||||
|
||||
topic_query = TopicQuery.new(current_user, list_options)
|
||||
top_period = params[:top_period]&.to_sym
|
||||
valid_top_period = TopTopic.periods.include?(top_period)
|
||||
top_period = params[:top_period]
|
||||
begin
|
||||
TopTopic.validate_period(top_period)
|
||||
valid_top_period = true
|
||||
rescue Discourse::InvalidParameters
|
||||
valid_top_period = false
|
||||
end
|
||||
|
||||
@list = if valid_top_period
|
||||
topic_query.list_top_for(top_period)
|
||||
|
||||
@@ -218,6 +218,8 @@ class ListController < ApplicationController
|
||||
@atom_link = "#{Discourse.base_url}/top.rss"
|
||||
@description = I18n.t("rss_description.top")
|
||||
period = params[:period] || SiteSetting.top_page_default_timeframe.to_sym
|
||||
TopTopic.validate_period(period)
|
||||
|
||||
@topic_list = TopicQuery.new(nil).list_top_for(period)
|
||||
|
||||
render 'list', formats: [:rss]
|
||||
|
||||
@@ -90,6 +90,8 @@ class TagsController < ::ApplicationController
|
||||
|
||||
if filter == :top
|
||||
period = params[:period] || SiteSetting.top_page_default_timeframe.to_sym
|
||||
TopTopic.validate_period(period)
|
||||
|
||||
@list = TopicQuery.new(current_user, list_opts).public_send("list_top_for", period)
|
||||
@list.for_period = period
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user