Problem/Motivation
I'm working on a Commerce site and would like to use drush sql:sanitize to remove PII.
Proposed resolution
I was wondering if people thought it might make sense to sanitize any address fields directly attached to user or profile entities (similar to how sql:sanitize by default randomizes all text fields on a user entity)? I realize this might be considered out of scope for the address module, but by the same token I thought it might be able to catch a whole host of potential PII issues in one fell swoop, so thought I'd throw it out there (:
Remaining tasks
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | address-sanitize-3189074-30.patch | 10.17 KB | hungdo |
| #18 | Screenshot 2023-11-14 at 17.37.48.png | 22.31 KB | the_g_bomb |
| #10 | address-3189074-10.patch | 10.13 KB | eheller |
| #9 | address-3189074-9.patch | 9.93 KB | eheller |
Issue fork address-3189074
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andyf commentedI've added a simple plugin that just overwrites the following fields with
[Sanitized]if they're not empty:It respects the
allowlist-fieldsoption for cases where folk want to opt out individual fields.I appreciate it's very primitive, open to feedback (:
Thanks!
Comment #4
andyf commentedComment #5
andyf commentedI'm just uploading a patch for composer.json against the MR at
c999754a9a010fcc78bd558b02ee2325e9b00e0d. Thanks!Comment #6
andyf commentedComment #7
andyf commentedI'm just uploading a patch for composer.json against the MR at
1ff4c3985fd1e079f10eafa66d3a37a6794ba026. Thanks!Comment #8
andyf commentedI'm just uploading a patch for composer.json against the MR at
a49a04c176d7fba76b3eba3647dd59aae50e6f6b. Thanks!Comment #9
eheller commented@AndyF This patch is great. I made a few changes in this version:
FIELD_COLUMNScountry_codefield. A nice-to-have would be to determine the field length dynamically, rather than hard-coding this field specifically.I'm also using this as the basis for a sanitization plugin for telephone numbers: https://www.drupal.org/project/drupal/issues/3205630
Comment #10
eheller commentedPatch #9 was showing this error on individual order admin pages on the Drupal Commerce site I've been using this on:
Notice: Undefined index: [] in Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter->viewElement() (line 157 of modules/contrib/address/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php).The new approach sets default values for country, administrative area and postal code that fit the expected formatting for those fields.Comment #11
kerasai commentedNot a "formal" review, but noting that I've been running the patch in #10 without issue for several months.
Comment #13
primsi commentedUpdated the version requirement for drush to a more up to date version. Also rebased - I've never done this on a d.o merge request though ... I hope that's ok.
Comment #16
bojanz commentedMerged (and added address_line3 for the 2.0.x commit). Thanks, everyone!
Comment #18
the_g_bomb commentedIs this supposed to also sanitize addresses that are not related to user details, such as public office addresses?

Comment #19
bojanz commentedYes, it doesn't (and can't) differentiate.
Comment #20
berdirYou can use the confusingly named allowlist-fields option, which in this case means that the fields are allowed to *not* be sanitized. Note that the setting is shared with other sanitize steps like user fields, so if you have an address field that you don't want to sanitize and a user field of the same name that you *do* want to sanitize you're going to run into a bit of a conflict.
I think it would be nice if that setting supported something like node.field_address, but that would be a new feature at this point.
Comment #21
the_g_bomb commentedI wonder if this could be a setting that could be switched on or off. If you have no user related data, you don't need to sanitise the addresses.
A stage environment may look strange with all the satellite office snow having redacted addresses on the contact forms.
Perhaps it could have been a submodule that doesn't need to be enabled.
Comment #22
the_g_bomb commentedAlso what if US addresses are not valid in the settings, you are replacing all sanitized addresses with a US postcode and country code.
The OP requested any address fields directly attached to user or profile entities. This does more than that.
Comment #23
bojanz commentedLet's gather some more feedback.
This feature has not made it into a release so I would be fine with reverting it if it's controversial.
Comment #26
bojanz commentedUpon further consideration, I have decided to revert this feature.
This module has almost 100 000 installs, which calls for some conservatism, so I'd rather err on the side of not having a feature than introducing a feature that goes too far. Especially since the original request called for a smaller scope and could be done in Commerce directly.
Please create a contrib module with this plugin, and I will happily link to it from the project page.
Apologies to everyone disappointed by this.
Comment #28
c_archer commentedThe latest patch fails against the 2.0.1 version of the module
Comment #29
khiminrm commentedThe fixes were improved to just sanitize address fields in profiles and merged into the new project commerce_sql_sanitize https://www.drupal.org/project/commerce_sql_sanitize/issues/3424078
Comment #30
hungdo commentedReroll the patch file to make it works with 2.0.1 version.