mogilvie / EncryptBundle

Encryption bundle
89 stars 29 forks source link

Twig decryption not automatic since v3.2.0 #56

Closed tsiatka closed 3 months ago

tsiatka commented 3 months ago

In version 3.1.0, encrypted values ​​were automatically decrypted in "twig" templates. Since version 3.2.0, I have to use the "decrypt" filter manually. I don't know which version has the correct behavior.

Twig : 3.10.3 Symfony : 6.4.8 PHP : 8.2 Doctrine : 2.19.5

mogilvie commented 3 months ago

Thanks, I'll look into it.

mogilvie commented 3 months ago

I have been unable to replicate your issue, however, there are two desired behaviours

  1. Entities should decrypt on the PostLoad event from Doctrine when an entity is loaded to the EntityManager. No need to do anything in Twig other than render the value.
  2. Values queried with DQL or SQL do not trigger the postLoad event and remain encrypted. You can then either render the encrypted value in the twig template using the Decrypt twig filter extension, or dispatch bundle EncryptEvent to decrypt the value in PHP.

Version 3.2.0. contains a dependency injection configuration parameter to enable/disable the twig filter extension. This allows packages not using Twig to skip that service definition. However, this configuration parameter defaults to Enabled, and then confirms the presence of twig by checking for \Twig\Environment class.

Can you check against these behaviours please?

mogilvie commented 3 months ago

Thanks @tsiatka, i was able to replicate last night. v3.2.0 changed the method of finding entity class names, and dropped decrypting for lazy loaded entities in the subscriber.

So it was the PostLoad event subscriber that wasn't working correctly. I've updated now in v3.2.1.