Skip to content

Commit db04727

Browse files
authored
Merge pull request #13054 from demarche-numerique/security/profil-email-domain-anchor
ETQ tech, ancrer la vérification de domaine email sur le domaine complet
2 parents cd70b7b + 1c052b0 commit db04727

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

app/controllers/users/profil_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ def requested_email
115115
end
116116

117117
def target_email_allowed?
118-
LEGIT_ADMIN_DOMAINS.any? { |d| requested_email.end_with?(d) }
118+
domain = requested_email.to_s.split('@', 2).last&.downcase
119+
return false if domain.blank?
120+
121+
LEGIT_ADMIN_DOMAINS.any? do |d|
122+
legit = d.to_s.downcase
123+
domain == legit || domain.end_with?(".#{legit}")
124+
end
119125
end
120126

121127
def next_owner_email

spec/controllers/users/profil_controller_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@
119119
expect(flash.alert).to include('contactez le support')
120120
end
121121
end
122+
123+
context 'when the requested email is on a domain that only matches a legit suffix without an `@` boundary' do
124+
let(:requested_email) { 'admin@evilgouv.fr' }
125+
126+
it 'rejects the email change' do
127+
expect(user.unconfirmed_email).to be_nil
128+
expect(response).to redirect_to(profil_path)
129+
expect(flash.alert).to include('contactez le support')
130+
end
131+
end
122132
end
123133

124134
context 'when the user has an administrateur role but no instructeur role' do

0 commit comments

Comments
 (0)