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

[33696] Retain autologin cookied request in session

Oliver Günther6881f3d3479f
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 031b0512691..2fa70f7709e 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -457,13 +457,14 @@ class AccountController < ApplicationController
end
def login_user!(user)
- # Valid user
- self.logged_user = user
# generate a key and set cookie if autologin
- if params[:autologin] && Setting.autologin?
+ if Setting.autologin? && (params[:autologin] || session.delete(:autologin_requested))
set_autologin_cookie(user)
end
+ # Set the logged user, resetting their session
+ self.logged_user = user
+
call_hook(:controller_account_success_authentication_after, user: user)
redirect_after_login(user)
diff --git a/app/controllers/concerns/accounts/authentication_stages.rb b/app/controllers/concerns/accounts/authentication_stages.rb
index 888184d54cd..ca1db60f0c0 100644
--- a/app/controllers/concerns/accounts/authentication_stages.rb
+++ b/app/controllers/concerns/accounts/authentication_stages.rb
@@ -59,6 +59,9 @@ module Accounts::AuthenticationStages
# but don't use the referer
session[:back_url] = params[:back_url]
+ # Remember the autologin cookie decision
+ session[:autologin_requested] = params[:autologin]
+
stages
end
diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rb
index b42f95ea851..8a646779f77 100644
--- a/spec/features/auth/consent_auth_stage_spec.rb
+++ b/spec/features/auth/consent_auth_stage_spec.rb
@@ -70,6 +70,19 @@ describe 'Authentication Stages', type: :feature do
expect(page).to have_no_selector('.account-consent')
expect_logged_in
end
+
+ it 'keeps the autologin request (Regression #33696)',
+ with_settings: { autologin: '1' } do
+ expect(Setting.autologin?).to eq true
+
+ login_with user.login, user_password, autologin: true
+ expect(page).to have_no_selector('.account-consent')
+
+ expect_logged_in
+ cookies = Capybara.current_session.driver.request.cookies
+ expect(cookies).to have_key '_open_project_session'
+ expect(cookies).to have_key 'autologin'
+ end
end
context 'when enabled, but no consent info', with_settings: { consent_info: {} } do
@@ -192,6 +205,28 @@ describe 'Authentication Stages', type: :feature do
expect_logged_in
end
+ it 'keeps the autologin request (Regression #33696)',
+ with_settings: { autologin: '1' } do
+ expect(Setting.autologin?).to eq true
+
+ login_with user.login, user_password, autologin: true
+
+ expect(page).to have_selector('.account-consent')
+ expect(page).to have_selector('h2', text: 'Consent')
+
+ # Confirm consent
+ check 'consent_check'
+ click_on I18n.t(:button_continue)
+
+ expect_logged_in
+
+ manager = page.driver.browser.manage
+ autologin_cookie = manager.cookie_named('autologin')
+ expect(autologin_cookie[:name]).to eq 'autologin'
+ # Cookie always expires in 1 year, check is made with the token expiry date
+ expect(autologin_cookie[:expires].to_date).to eq (Date.today + 1.year)
+ end
+
context 'with contact mail address', with_settings: { consent_decline_mail: '[email protected]' } do
it 'shows that address to users when declining' do
login_with user.login, user_password