Merge pull request #3541 from evazion/fix-3539
Fix #3539: Open redirect vulnerabilities
This commit is contained in:
@@ -196,17 +196,19 @@ class ApplicationController < ActionController::Base
|
|||||||
@page_title = Danbooru.config.app_name + "/#{params[:controller]}"
|
@page_title = Danbooru.config.app_name + "/#{params[:controller]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Remove blank `search` params from the url.
|
||||||
|
#
|
||||||
|
# /tags?search[name]=touhou&search[category]=&search[order]=
|
||||||
|
# => /tags?search[name]=touhou
|
||||||
def normalize_search
|
def normalize_search
|
||||||
if request.get?
|
if request.get?
|
||||||
if params[:search].blank?
|
if params[:search].blank?
|
||||||
params[:search] = {}
|
params[:search] = ActionController::Parameters.new
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:search].is_a?(Hash)
|
if params[:search].is_a?(ActionController::Parameters) && params[:search].values.any?(&:blank?)
|
||||||
changed = params[:search].reject! {|k,v| v.blank?}
|
params[:search].reject! {|k,v| v.blank?}
|
||||||
unless changed.nil?
|
redirect_to url_for(params: params.except(:controller, :action, :index).permit!)
|
||||||
redirect_to url_for(params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ module PaginationHelper
|
|||||||
|
|
||||||
if records.any?
|
if records.any?
|
||||||
if params[:page] =~ /[ab]/ && !records.is_first_page?
|
if params[:page] =~ /[ab]/ && !records.is_first_page?
|
||||||
html << '<li>' + link_to("< Previous", params.merge(:page => "a#{records[0].id}"), :rel => "prev") + '</li>'
|
html << '<li>' + link_to("< Previous", nav_params_for("a#{records[0].id}"), :rel => "prev") + '</li>'
|
||||||
end
|
end
|
||||||
|
|
||||||
unless records.is_last_page?
|
unless records.is_last_page?
|
||||||
html << '<li>' + link_to("Next >", params.merge(:page => "b#{records[-1].id}"), :rel => "next") + '</li>'
|
html << '<li>' + link_to("Next >", nav_params_for("b#{records[-1].id}"), :rel => "next") + '</li>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ module PaginationHelper
|
|||||||
window = 4
|
window = 4
|
||||||
|
|
||||||
if records.current_page >= 2
|
if records.current_page >= 2
|
||||||
html << "<li class='arrow'>" + link_to("<<", params.merge(:page => records.current_page - 1), :rel => "prev") + "</li>"
|
html << "<li class='arrow'>" + link_to("<<", nav_params_for(records.current_page - 1), :rel => "prev") + "</li>"
|
||||||
else
|
else
|
||||||
html << "<li class='arrow'><span>" + "<<" + "</span></li>"
|
html << "<li class='arrow'><span>" + "<<" + "</span></li>"
|
||||||
end
|
end
|
||||||
@@ -69,7 +69,7 @@ module PaginationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
if records.current_page < records.total_pages && records.size > 0
|
if records.current_page < records.total_pages && records.size > 0
|
||||||
html << "<li class='arrow'>" + link_to(">>", params.merge(:page => records.current_page + 1), :rel => "next") + "</li>"
|
html << "<li class='arrow'>" + link_to(">>", nav_params_for(records.current_page + 1), :rel => "next") + "</li>"
|
||||||
else
|
else
|
||||||
html << "<li class='arrow'><span>" + ">>" + "</span></li>"
|
html << "<li class='arrow'><span>" + ">>" + "</span></li>"
|
||||||
end
|
end
|
||||||
@@ -100,9 +100,16 @@ module PaginationHelper
|
|||||||
html << "</li>"
|
html << "</li>"
|
||||||
else
|
else
|
||||||
html << "<li class='numbered-page'>"
|
html << "<li class='numbered-page'>"
|
||||||
html << link_to(page, params.merge(:page => page))
|
html << link_to(page, nav_params_for(page))
|
||||||
html << "</li>"
|
html << "</li>"
|
||||||
end
|
end
|
||||||
html.join.html_safe
|
html.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def nav_params_for(page)
|
||||||
|
query_params = params.except(:controller, :action, :id).merge(page: page).permit!
|
||||||
|
{ params: query_params }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,17 +5,13 @@ module PostsHelper
|
|||||||
|
|
||||||
def next_page_url
|
def next_page_url
|
||||||
current_page = (params[:page] || 1).to_i
|
current_page = (params[:page] || 1).to_i
|
||||||
dup_params = params.dup
|
url_for(nav_params_for(current_page + 1)).html_safe
|
||||||
dup_params[:page] = current_page + 1
|
|
||||||
url_for(dup_params).html_safe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prev_page_url
|
def prev_page_url
|
||||||
current_page = (params[:page] || 1).to_i
|
current_page = (params[:page] || 1).to_i
|
||||||
if current_page >= 2
|
if current_page >= 2
|
||||||
dup_params = params.dup
|
url_for(nav_params_for(current_page - 1)).html_safe
|
||||||
dup_params[:page] = current_page - 1
|
|
||||||
url_for(dup_params).html_safe
|
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
@@ -135,4 +131,11 @@ module PostsHelper
|
|||||||
|
|
||||||
html.html_safe
|
html.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def nav_params_for(page)
|
||||||
|
query_params = params.except(:controller, :action, :id).merge(page: page).permit!
|
||||||
|
{ params: query_params }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ class TagsControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with blank search parameters" do
|
||||||
|
should "strip the blank parameters with a redirect" do
|
||||||
|
get :index, { search: { name: "touhou", category: "" } }
|
||||||
|
|
||||||
|
assert_redirected_to tags_path(search: { name: "touhou" })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "autocomplete action" do
|
context "autocomplete action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user