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
[36746] Unset plain password accessor after saving (#9157)
Oliver Günther2d22930bdb32
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 08cb7bac79c..5b5b73a3eaa 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -136,7 +136,7 @@ class UsersController < ApplicationControllerself_notified: params[:self_notified] == '1',notified_project_ids: params[:notified_project_ids])- if [email protected]? && @user.change_password_allowed?+ if update_params[:password].present? && @user.change_password_allowed?send_information = params[:send_information]if @user.invited?@@ -152,7 +152,7 @@ class UsersController < ApplicationControllerendif @user.active? && send_information- UserMailer.account_information(@user, @user.password).deliver_later+ UserMailer.account_information(@user, update_params[:password]).deliver_laterendenddiff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rbindex cc77349acb3..222bb8a515c 100644--- a/app/models/mail_handler.rb+++ b/app/models/mail_handler.rb@@ -98,10 +98,10 @@ class MailHandler < ActionMailer::Basewhen 'accept'@user = User.anonymouswhen 'create'- @user = MailHandler.create_user_from_email(email)+ @user, password = MailHandler.create_user_from_email(email)if @userlog "[#{@user.login}] account created"- UserMailer.account_information(@user, @user.password).deliver_later+ UserMailer.account_information(@user, password).deliver_laterelselog "could not create account for [#{sender_email}]", :errorreturn false@@ -442,8 +442,9 @@ class MailHandler < ActionMailer::Baseendif addr.present?user = new_user_from_attributes(addr, name)+ password = user.passwordif user.save- user+ [user, password]elselog "failed to create User: #{user.errors.full_messages}", :errornildiff --git a/app/models/user.rb b/app/models/user.rbindex 4633fdfca31..ea3e46a67db 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -166,6 +166,7 @@ class User < Principalpasswords.reloadclean_up_former_passwords+ clean_up_password_attributeendend@@ -731,6 +732,10 @@ class User < Principal(passwords[keep_count..-1] || []).each(&:destroy)end+ def clean_up_password_attribute+ self.password = self.password_confirmation = nil+ end+### Brute force prevention - class methods#diff --git a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rbindex 0c748486ea8..641fed0a40f 100644--- a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb+++ b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb@@ -6,12 +6,11 @@ describe 'Login with 2FA remember cookie',with_2fa_ee: true,with_config: { '2fa': { active_strategies: [:developer], allow_remember_for_days: 30 } },js: true do- let(:user) do- FactoryBot.create(:user)- endlet(:user_password) do- # Works because the user is not reloaded- user.password+ "user!user!"+ end+ let(:user) do+ FactoryBot.create(:user, password: user_password, password_confirmation: user_password)endlet!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true }diff --git a/spec/features/auth/login_spec.rb b/spec/features/auth/login_spec.rbindex 2987b0ddc93..f3affef1d09 100644--- a/spec/features/auth/login_spec.rb+++ b/spec/features/auth/login_spec.rb@@ -68,7 +68,7 @@ describe 'Login', type: :feature docontext 'with leading and trailing space in login' doit 'can still login' do# first login- login_with(" #{user.login} ", user.password)+ login_with(" #{user.login} ", user_password)# on the my pageexpect(page)@@ -83,7 +83,7 @@ describe 'Login', type: :feature doit 'redirects to homescreen after forced password change(with validation error) and first login' do# first login- login_with(user.login, user.password)+ login_with(user.login, user_password)expect(current_path).to eql signin_path# change password page (giving an invalid password)diff --git a/spec/features/users/self_registration_spec.rb b/spec/features/users/self_registration_spec.rbindex 22689df5a8d..eafc101fe57 100644--- a/spec/features/users/self_registration_spec.rb+++ b/spec/features/users/self_registration_spec.rb@@ -29,7 +29,8 @@require 'spec_helper'describe 'user self registration', type: :feature, js: true do- let(:admin) { FactoryBot.create :admin, password: 'Test123Test123', password_confirmation: 'Test123Test123' }+ let(:admin_password) { 'Test123Test123' }+ let(:admin) { FactoryBot.create :admin, password: admin_password, password_confirmation: admin_password }let(:home_page) { Pages::Home.new }context 'with "manual account activation"',@@ -104,7 +105,7 @@ describe 'user self registration', type: :feature, js: true do.to have_content I18n.t(:'account.error_inactive_manual_activation')# activation as admin- login_with admin.login, admin.password+ login_with admin.login, admin_passworduser_page = Pages::Admin::Users::Edit.new(registered_user.id)