OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remember back_url/origin as RelayState in saml
Oliver Günthera9c98a2fb4ab
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rbindex efb866c8966..d04dd76a9ab 100644--- a/app/controllers/concerns/accounts/omniauth_login.rb+++ b/app/controllers/concerns/accounts/omniauth_login.rb@@ -47,7 +47,7 @@ module Accounts::OmniauthLoginenddef omniauth_login- params[:back_url] = request.env["omniauth.origin"] if remember_back_url?+ params[:back_url] = omniauth_back_url if remember_back_url?# Extract auth info and perform check / login or activate userauth_hash = request.env["omniauth.auth"]@@ -75,11 +75,16 @@ module Accounts::OmniauthLogin# Avoid remembering the back_url if we're coming from the login pagedef remember_back_url?- provided_back_url = request.env["omniauth.origin"]- return if provided_back_url.blank?+ return if omniauth_back_url.blank?account_routes = /\/(login|account)/- omniauth_direct_login? || !provided_back_url.match?(account_routes)+ omniauth_direct_login? || !omniauth_back_url.match?(account_routes)+ end++ # In case of SAML post bindings, we lose our session information+ # so we need to store it in the RelayState parameter+ def omniauth_back_url+ request.env["omniauth.origin"].presence || params[:RelayState]enddef show_error(error)diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rbindex 8dbf4c9b9ca..4696da7892d 100644--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb@@ -63,6 +63,9 @@ module OpenProject# Remember saml session values when logging in userh[:retain_from_session] = %w[saml_uid saml_session_index saml_transaction_id]+ # remember the origin in RelayState+ h[:idp_sso_target_url_runtime_params] = { origin: :RelayState }+h[:single_sign_out_callback] = Proc.new do |prev_session, _prev_user|next unless h[:idp_slo_target_url]next unless prev_session[:saml_uid] && prev_session[:saml_session_index]diff --git a/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb b/modules/auth_saml/spec/requests/saml_provider_callback_spec.rbindex 18f901de5fc..628a636d18b 100644--- a/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb+++ b/modules/auth_saml/spec/requests/saml_provider_callback_spec.rb@@ -106,4 +106,25 @@ RSpec.describe "SAML provider callback", with_ee: %i[openid_providers] doit_behaves_like "request fails"end++ context "with a RelayState present" do+ let(:body) do+ { SAMLResponse: saml_response, RelayState: "/projects?some_param=true" }+ end++ it "redirects the user to 2FA, but with back_url present in session" do+ expect(subject.status).to eq(302)+ expect(subject.headers["Location"]).to eq("http://example.org/two_factor_authentication/request")++ session = Sessions::SqlBypass.lookup_data(subject.cookies["_open_project_session"].first)+ expect(session["back_url"]).to eq "/projects?some_param=true"+ end++ context "when 2FA is disabled", :skip_2fa_stage do+ it "redirects directly" do+ expect(subject.status).to eq(302)+ expect(subject.headers["Location"]).to eq("http://example.org/projects?some_param=true")+ end+ end+ endend