jmazzi / crypt_keeper

Transparent ActiveRecord encryption
http://jmazzi.github.com/crypt_keeper/
MIT License
288 stars 99 forks source link

Filters sql from ActiveRecord::StatementInvalid #142

Closed fabiokr closed 7 years ago

fabiokr commented 7 years ago

This updates the postgres provider to filter ActiveRecord::StatementInvalid messages to remove the keys.

This was the simplest fix I could come up with for encrypt and decrypt. The search method is harder, because that returns an ActiveRecord::Relation, and the query is only triggered at a later point, so we can't easily rescue.

I think a better fix for this would be to move them all to use sql prepared statements instead of raw sql, that way the exception would only get the prepared statement query without any actual keys. I started looking into that, but this path would need more changes on crypt keeper, so I changed to this simpler fix for now instead (https://github.com/fabiokr/crypt_keeper/pull/1 log messages would be different, would have to reworks the log subscriber, etc).

itspriddle commented 7 years ago

:+1: overall, but I agree we should move to prepared statements or some better way to scrub this stuff. It feels like we're starting to fight Rails a little too much there.

jmazzi commented 7 years ago

@fabiokr this looks good. Has it run in production yet? :trollface: