FIX: respond with 400 error on invalid redirect param
This commit is contained in:
parent
59e84e8e05
commit
863d8014d0
|
@ -89,8 +89,10 @@ class StaticController < ApplicationController
|
||||||
|
|
||||||
destination = path("/")
|
destination = path("/")
|
||||||
|
|
||||||
redirect_location = params[:redirect].to_s
|
redirect_location = params[:redirect]
|
||||||
if redirect_location.present? && !redirect_location.match(login_path)
|
if redirect_location.present? && !redirect_location.is_a?(String)
|
||||||
|
raise Discourse::InvalidParameters.new(:redirect)
|
||||||
|
elsif redirect_location.present? && !redirect_location.match(login_path)
|
||||||
begin
|
begin
|
||||||
forum_uri = URI(Discourse.base_url)
|
forum_uri = URI(Discourse.base_url)
|
||||||
uri = URI(redirect_location)
|
uri = URI(redirect_location)
|
||||||
|
|
|
@ -286,7 +286,12 @@ describe StaticController do
|
||||||
context 'with an array' do
|
context 'with an array' do
|
||||||
it "redirects to the root" do
|
it "redirects to the root" do
|
||||||
post "/login.json", params: { redirect: ["/foo"] }
|
post "/login.json", params: { redirect: ["/foo"] }
|
||||||
expect(response).to redirect_to('/')
|
expect(response.status).to eq(400)
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["errors"]).to be_present
|
||||||
|
expect(json["errors"]).to include(
|
||||||
|
I18n.t("invalid_params", message: "redirect")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue