Merge pull request #10659 from colinux/fix-devise-confirmation-leak

ETQ usager, redirige les utilisateurs déjà confirmés qui réutilisent le lien de confirmation
This commit is contained in:
Colin Darie 2024-07-29 12:15:21 +00:00 committed by GitHub
commit 25014a71b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 3 deletions

View file

@ -13,9 +13,19 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
def show
super do
# When email was already confirmed, default is to render :new with a specific error.
# Because our :new is customized with the email and a form to resend a confirmation,
# we redirect to after confirmation page instead.
if resource.errors.of_kind?(:email, :already_confirmed)
respond_with_navigational(resource) do
flash.notice = t('.email_already_confirmed')
redirect_to after_confirmation_path_for(resource_name, resource) and return
end
end
end
end
# protected

View file

@ -6,3 +6,7 @@ en:
sessions:
signed_in_multiple_profile: "You are connected ! You can switch between your multiple profiles : %{roles}."
signed_out: You are now disconnected.
users:
confirmations:
show:
email_already_confirmed: 'Your account has already been activated.'

View file

@ -6,3 +6,7 @@ fr:
sessions:
signed_in_multiple_profile: "Vous êtes connecté(e) ! Vous pouvez à tout moment alterner entre vos différents profils : %{roles}."
signed_out: Vous êtes maintenant déconnecté(e).
users:
confirmations:
show:
email_already_confirmed: 'Votre compte a déjà été activé.'

View file

@ -5,3 +5,11 @@ User-agent: *
Disallow: /commencer*
Disallow: /rails/
Disallow: /super_admins/
Disallow: /manager/
Disallow: /users/
Allow: /users/sign_in
Allow: /users/sign_up
Disallow: /connexion-par-jeton/
Disallow: */reset-link-sent*
Disallow: /lien-envoye
Disallow: /france_connect/

View file

@ -51,5 +51,21 @@ describe Users::ConfirmationsController, type: :controller do
expect(subject).to redirect_to(new_user_session_path)
end
end
context 'when account was already confirmed long time ago' do
let!(:user) { create(:user, confirmed_at: 3.hours.ago, confirmation_sent_at: 4.hours.ago, confirmation_token: "mytoken") }
render_views
subject do
get :show, params: { confirmation_token: confirmation_token }
end
it 'redirect and does not expose the email' do
expect(user).to be_confirmed
expect(subject).to redirect_to(new_user_session_path)
expect(subject.body).not_to include(user.email)
expect(flash.notice).to include("Votre compte a déjà été activé")
end
end
end
end