Skip to content

Commit

Permalink
FIX: handle array in redirect param
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Jun 11, 2019
1 parent f4fd75a commit e2636f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def enter

destination = path("/")

if params[:redirect].present? && !params[:redirect].match(login_path)
redirect_location = params[:redirect].to_s
if redirect_location.present? && !redirect_location.match(login_path)
begin
forum_uri = URI(Discourse.base_url)
uri = URI(params[:redirect])
uri = URI(redirect_location)

if uri.path.present? &&
(uri.host.blank? || uri.host == forum_uri.host) &&
Expand Down
7 changes: 7 additions & 0 deletions spec/requests/static_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@
end
end

context 'with an array' do
it "redirects to the root" do
post "/login.json", params: { redirect: ["/foo"] }
expect(response).to redirect_to('/')
end
end

context 'when the redirect path is the login page' do
it 'redirects to the root url' do
post "/login.json", params: { redirect: login_path }
Expand Down

2 comments on commit e2636f0

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SamSaffron posted:

Hmmm but why? To me this feels like an abuse of the API, instead we should simply do a 400 here no cause you are sending in invalid params.

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.