-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decryption doesn't work for records created with Model.findOrCreate method #4302
Comments
Hi @ahmedrad! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:
As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks! *If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com |
“Ok, fixed! |
Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again. *If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com |
ok this time fixed for real! |
@ahmedrad Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
Thanks @ahmedrad -- this is definitely a possible bug, encrypt/decrypt is a new feature. We'll check this out, but in the meantime the easy workaround (especially w/ Node 8) is:
It should be equally performant as this is basically what Waterline is doing behind the scenes. |
@ahmedrad thanks, reproduced and looking into it |
Looks like the issue is that it's inserted incorrectly in that case (works fine for looking up an already-existing record-- but when it creates, it does it wrong) |
@ahmedrad this is a tough one to solve without making the implementation a lot messier. I'm tempted to just add an error message that prevents you from using |
It sounds like you're saying that records created using |
I already implemented the workaround thanks @sgress454! @mikermcneil my personal opinion is that an error message is not sufficient as creating the record and retrieving it are not gonna always happen in the same place. In my case I was creating an Oauth record that will be used later on for API calls and could not retrieve the actual Oauth keys when the api calls were needed as I could not decrypt them. If there's no short term solution for the bug then I'd go with disabling findOrCreate on any model with an encrypted attribute. Not that it's a great solution either as people might add an encrypted attribute to a model they've been using for a while and suddenly find themselves having to go remove all these findOrCreate calls :( |
@ahmedrad @sgress454 thanks for your help! After a fresh look, it wasn't as bad to fix as I thought. The real issue is that F2SQ wasn't actually idempotent (because it does encryption now, in some cases), but we were treating it as such in the case of findOrCreate(). Simplest solution was to provide a private way of disabling encryption (see linked commit). That new flag should not be relied upon by userland other than for experimental use (it could change at any time). This is resolved and published in waterline 0.13.1. @ahmedrad Would you mind verifying that everything looks good from your end? I'll leave it to you to close this issue. Thanks! |
looks like it's fixed! thanks for the support. |
Sails version: 1.0.0-46
Node version: 8.6.0
NPM version: 5.6.0
DB adapter name: sails-postgresql
DB adapter version: 1.0.0-12
Operating system: OS X sierra 10.12.6
I've spent quite some time on this and I've come to the conclusion that I can't correctly decrypt any records created with the
findOrCreate
method called on any model while records created with thecreate
method decrypt fine. There's really not much else to add. Here's a repo to reproduce the issue:https://github.com/ahmedrad/sails-bug
The text was updated successfully, but these errors were encountered: