Skip to content

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

[#65505] Use ScimClient specific session key for storing oauth client plaintext secret.

Pavel Balashoua5977f670421
diff --git a/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb b/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
index 9c8ec4d2453..96f65374f0c 100644
--- a/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
+++ b/app/components/admin/scim_clients/created_client_credentials_dialog_component.rb
@@ -35,9 +35,9 @@ module Admin
TEST_SELECTOR = "op-scim-clients--created-client-credentials-dialog"
- def initialize(model = nil, **options)
+ def initialize(model = nil, plaintext_secret:, **options)
super
- @plaintext_secret = options.fetch(:plaintext_secret)
+ @plaintext_secret = plaintext_secret
end
def system_arguments
diff --git a/app/controllers/admin/scim_clients_controller.rb b/app/controllers/admin/scim_clients_controller.rb
index bd41d18fb7c..f751bf4a7ba 100644
--- a/app/controllers/admin/scim_clients_controller.rb
+++ b/app/controllers/admin/scim_clients_controller.rb
@@ -64,7 +64,7 @@ module Admin
result.on_success do
flash[:notice] = t(:notice_successful_create)
plaintext_secret = result.result.oauth_application&.plaintext_secret
- session[:oauth_secret] = plaintext_secret if plaintext_secret.present?
+ session[oauth_secret_session_key(result.result)] = plaintext_secret if plaintext_secret.present?
redirect_to(edit_admin_scim_client_path(result.result, first_time_setup: true))
end
end
@@ -117,10 +117,9 @@ module Admin
@setup_token = ::ScimClients::GenerateStaticTokenService.new(scim_client).call.result
end
when "oauth2_client"
- # Ensuring that the client secret can't infinitely be accessed by calling with ?first_time_setup=true long after
- # the initial setup (there is no other persisted marker showing us, that this is the first time)
- if scim_client.oauth_application.created_at > 1.minute.ago
- @setup_client_secret = session.delete(:oauth_secret)
+ key = oauth_secret_session_key(scim_client)
+ if session.key?(key)
+ @setup_client_secret = session.delete(key)
end
end
end
@@ -129,5 +128,9 @@ module Admin
update_via_turbo_stream(component: Admin::ScimClients::FormComponent.new(@scim_client))
respond_with_turbo_streams(&)
end
+
+ def oauth_secret_session_key(scim_client)
+ "scim-client-#{scim_client.id}-oauth-secret"
+ end
end
end