mogilvie / EncryptBundle

Encryption bundle
82 stars 27 forks source link

Possible issues with multiples encrypted fields on one entity #35

Closed madrzejewski closed 1 year ago

madrzejewski commented 1 year ago

Firstly, I would like to thank you for this project. I created something similar for one of my project, but I'm using ciphersweet for the encryption & keep the ability to search (at least partly) on encrypted field (using blind indexes). So I looked at your code to improve mine. I was using different events, and your way of doing is more efficient.

On my project, by reusing some of your logic inside the Doctrine Subscriber I came across an issue. When an entity has multiple encrypted fields, only the "last" field is encrypted for INSERT.

I didn't try on your project because I did not use it as is. But I think you may have the same issue.

This issue is on the DoctrineEncryptSubscriber Line 183.

On my side, it didn't work for the insert because of the setValue that come after. When you have multiple encrypted field, by setting the value here, it seems to messes up the recomputeSingleEntityChangeSet that detect another change. So I end up with the last field of my entity to be encrypted.

So the solution is to re-set the object value in the end or just like the postUpdate.