Sanitized email addresses are too long, preventing you from saving the user edit form

Created on 18 June 2024, 12 days ago

Problem/Motivation

ACSF runs a custom drush command for sanitizing a db after it's been synced from prod to a dev/test environment. It has this code in it:

    // Avoid collisions between the Factory and site users when scrubbing.
    $connection->update('users_field_data')
      ->expression('mail', "CONCAT('user', uid, '@', SHA2(mail, 256), '.example.com')")
      ->expression('init', "CONCAT('user', uid, '@', SHA2(init, 256), '.example.com')")
      ->condition('uid', $preserved_users, 'NOT IN')
      ->execute();

This creates an email address like this:

user6@a1bf0954aaf56aedb9896e5ad3e492fff040fb0acc1a98cf1137c528b799d717.e...

This is not a valid email. Drupal runs email validation on the field when saving the user profile form and it fails with reason Egulias\EmailValidator\Result\Reason\LabelTooLong because "a1bf0954aaf56aedb9896e5ad3e492fff040fb0acc1a98cf1137c528b799d717" is 64 characters but the max length allowed is 63 characters.

Steps to reproduce

Edit any user account that was sanitized after the site sync process. Try saving and observe error "The email address user6@a1bf0954aaf56aedb9896e5ad3e492fff040fb0acc1a98cf1137c528b799d717.e... is not valid. Use the format user@example.com."

Proposed resolution

Shorten the bit length of the SHA2 hash function from 256 to 224 to reduce the length of the hash.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024