FIX: Make serverside and clientside omniauth origin redirects consistent
Previously external domains were allowed in the client-side redirects, but not the server-side redirects. Now the behavior is to only allow local origins.
This commit is contained in:
parent
64e81f0549
commit
1299c94a52
|
@ -44,18 +44,18 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
@auth_result = authenticator.after_authenticate(auth)
|
@auth_result = authenticator.after_authenticate(auth)
|
||||||
end
|
end
|
||||||
|
|
||||||
origin = request.env['omniauth.origin']
|
preferred_origin = request.env['omniauth.origin']
|
||||||
|
|
||||||
if SiteSetting.enable_sso_provider && payload = cookies.delete(:sso_payload)
|
if SiteSetting.enable_sso_provider && payload = cookies.delete(:sso_payload)
|
||||||
origin = session_sso_provider_url + "?" + payload
|
preferred_origin = session_sso_provider_url + "?" + payload
|
||||||
elsif cookies[:destination_url].present?
|
elsif cookies[:destination_url].present?
|
||||||
origin = cookies[:destination_url]
|
preferred_origin = cookies[:destination_url]
|
||||||
cookies.delete(:destination_url)
|
cookies.delete(:destination_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
if origin.present?
|
if preferred_origin.present?
|
||||||
parsed = begin
|
parsed = begin
|
||||||
URI.parse(origin)
|
URI.parse(preferred_origin)
|
||||||
rescue URI::Error
|
rescue URI::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
@origin = Discourse.base_uri("/")
|
@origin = Discourse.base_uri("/")
|
||||||
end
|
end
|
||||||
|
|
||||||
@auth_result.destination_url = origin
|
@auth_result.destination_url = @origin
|
||||||
|
|
||||||
if @auth_result.failed?
|
if @auth_result.failed?
|
||||||
flash[:error] = @auth_result.failed_reason.html_safe
|
flash[:error] = @auth_result.failed_reason.html_safe
|
||||||
|
|
|
@ -119,7 +119,7 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the right response' do
|
it 'should return the right response' do
|
||||||
destination_url = 'http://thisisasite.com/somepath'
|
destination_url = '/somepath'
|
||||||
Rails.application.env_config["omniauth.origin"] = destination_url
|
Rails.application.env_config["omniauth.origin"] = destination_url
|
||||||
|
|
||||||
get "/auth/google_oauth2/callback.json"
|
get "/auth/google_oauth2/callback.json"
|
||||||
|
@ -138,7 +138,7 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should include destination url in response' do
|
it 'should include destination url in response' do
|
||||||
destination_url = 'http://thisisasite.com/somepath'
|
destination_url = '/cookiepath'
|
||||||
cookies[:destination_url] = destination_url
|
cookies[:destination_url] = destination_url
|
||||||
|
|
||||||
get "/auth/google_oauth2/callback.json"
|
get "/auth/google_oauth2/callback.json"
|
||||||
|
@ -353,6 +353,9 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
|
|
||||||
expect(response.status).to eq 302
|
expect(response.status).to eq 302
|
||||||
expect(response.location).to eq "http://test.localhost/"
|
expect(response.location).to eq "http://test.localhost/"
|
||||||
|
|
||||||
|
cookie_data = JSON.parse(response.cookies['authentication_data'])
|
||||||
|
expect(cookie_data["destination_url"]).to eq('/')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to internal origin" do
|
it "redirects to internal origin" do
|
||||||
|
@ -361,6 +364,9 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
|
|
||||||
expect(response.status).to eq 302
|
expect(response.status).to eq 302
|
||||||
expect(response.location).to eq "http://test.localhost/t/123"
|
expect(response.location).to eq "http://test.localhost/t/123"
|
||||||
|
|
||||||
|
cookie_data = JSON.parse(response.cookies['authentication_data'])
|
||||||
|
expect(cookie_data["destination_url"]).to eq('/t/123')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to relative origin" do
|
it "redirects to relative origin" do
|
||||||
|
@ -369,6 +375,9 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
|
|
||||||
expect(response.status).to eq 302
|
expect(response.status).to eq 302
|
||||||
expect(response.location).to eq "http://test.localhost/t/123"
|
expect(response.location).to eq "http://test.localhost/t/123"
|
||||||
|
|
||||||
|
cookie_data = JSON.parse(response.cookies['authentication_data'])
|
||||||
|
expect(cookie_data["destination_url"]).to eq('/t/123')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects with query" do
|
it "redirects with query" do
|
||||||
|
@ -377,6 +386,9 @@ RSpec.describe Users::OmniauthCallbacksController do
|
||||||
|
|
||||||
expect(response.status).to eq 302
|
expect(response.status).to eq 302
|
||||||
expect(response.location).to eq "http://test.localhost/t/123?foo=bar"
|
expect(response.location).to eq "http://test.localhost/t/123?foo=bar"
|
||||||
|
|
||||||
|
cookie_data = JSON.parse(response.cookies['authentication_data'])
|
||||||
|
expect(cookie_data["destination_url"]).to eq('/t/123?foo=bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes authentication_data cookie on logout" do
|
it "removes authentication_data cookie on logout" do
|
||||||
|
|
Loading…
Reference in New Issue