Background information

This was originally reported as a private security issue, but has been approved for handling in the public queue by the Drupal Security Team.

Problem/Motivation

We have a website with a list field that is encrypted. The available options for this field are public but the association between a user and the selected value is sensitive data. We noticed that the encrypted value varies based on the length of the selected value. This means that if an attacker can get a dump of the database, they can deduce the selected values for this field without having to break the encryption.

Steps to reproduce

1. Enable the module
2. Create a bundle with a list field with two allowed values (_short_ and _loooooooong_ for example) and enable encryption on this field
3. Create some nodes in this bundle
4. Run this SQL query:

SELECT nid, LENGTH(encrypted_field_storage__value) FROM `node_field_data`; 

The short value is always encrypted as a 396 characters string and the long value has a 416 characters string. (I tested with AES.)

Proposed resolution

I suppose a solution could be to pad the encrypted value so it has always the same length.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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

prudloff created an issue. See original summary.

ptmkenny’s picture

Thank you for this report.

I was able to reproduce the issue as described. My view is that this is a configuration issue that can be handled in the docs.

Rationale/Evidence

  • The encryption is not broken; the module does not claim on the project page or in the README that the encrypted data is padded sufficiently in all cases, so I see this as a feature request.
  • Despite the name "Field Encrypt", the module stores encrypted data at the entity level; all encrypted field values for an entity are stored together in a single column per translation, so this issue of discernible values only occurs in a case where there the only fields configured have allowed values that have very different lengths.

How to Fix This

I would suggest improving the documentation, noting specifically:

  • Encryption is at the entity level, so if you are encrypting only a single field value for an entity, then it may be possible to infer things based on the length of the encrypted field data.
  • If you are using a list (list_string, list_integer, list_float), you can mitigate this by ensuring that the list keys (machine names of the list items) are all the same length.

ptmkenny’s picture

Status: Active » Needs review
ptmkenny’s picture

Please let me know what you think of the README text and I'll add it to the module page as well.