user_synced_attributes_metadata is not syncing email from user profile when LDAP attribute 'mail' is not matching the CaSe of SAML user email
Summary
Please see issue in customer collaboration project (linked) for full details.
"Some users reported that they are able to edit their email address in Gitlab User profile. This can allow users to circumvent 'Push rules' 'Reject unverified users' and 'Check whether the commit author is a GitLab user'. First this is our setup:
- SAML SSO is used for authentication
- omniauth_auto_link_ldap_user is set to true
- LDAP synchronization is enabled and used for AuthZ part
Upon investigation we can see root cause is that email coming from SAML is not matching the case of 'mail' LDAP attribute, thus marking boolean email_synced in UserSyncedAttributesMetadata to false. As an result this property is not considered as read-only and making the email field editable by user. Details of example user"
Steps to reproduce
Example Project
What is the current bug behavior?
What is the expected correct behavior?
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: \\\`sudo gitlab-rake gitlab:env:info\\\`) (For installations from source run and paste the output of: \\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:check SANITIZE=true\`) (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true\`) (we will only investigate if the tests are passing)
Possible fixes
--- user.rb 2024-06-26 10:08:38
+++ user.rb.fix 2024-06-26 10:09:30
@@ -280,7 +280,7 @@
if creating_linked_ldap_user?
metadata.set_attribute_synced(:name, true) if gl_user.name == ldap_person.name
- metadata.set_attribute_synced(:email, true) if gl_user.email == ldap_person.email&.first
+ metadata.set_attribute_synced(:email, true) if gl_user.email.downcase == ldap_person.email&.first.downcase
metadata.provider = ldap_person.provider
end
end
Edited by Katie Bilsborough