Skip to content
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

Sync failed for updated docs from a local encrypted db #42

Open
AndreasHohnholt opened this issue Mar 3, 2017 · 3 comments
Open

Sync failed for updated docs from a local encrypted db #42

AndreasHohnholt opened this issue Mar 3, 2017 · 3 comments

Comments

@AndreasHohnholt
Copy link
Contributor

Hi,

if I update a doc and then try to sync this doc to a remote db - pouchdb throw this exception:
Error: There was a problem getting docs.
at finishBatch (pouchdb-6.1.1.js:13009)

If I create a new doc in an empty db (local and remote) the first sync works well.

Here is the code of my crypto transform (I am using sjcl because it works well on iOS Safari) :

localDB.transform({
            incoming: function (doc) {
              Object.keys(doc).forEach(function (field) {
                if (field !== '_id' && field !== '_rev' && field !== '_revisions' && field !== '_attachments') {
                    var password = appuser.GetDBPassword();
                    var fieldValue = sjcl.encrypt(password,angular.toJson(doc[field]));
                    doc[field] = fieldValue;
                }
              });
              return doc;
            },
            outgoing: function (doc) {
              Object.keys(doc).forEach(function (field) {
                if (field !== '_id' && field !== '_rev' && field !== '_revisions' && field !== '_attachments') {
                  var password = appuser.GetDBPassword();
                  var fieldValue = angular.fromJson(sjcl.decrypt(password,doc[field]));
                  doc[field] = fieldValue;
                }
              });
              return doc;
            }
        });  
@AndreasHohnholt
Copy link
Contributor Author

the reason for this issue may be the same as here:
calvinmetcalf/crypto-pouch#44

@rasgo-cc
Copy link

rasgo-cc commented Nov 3, 2020

3 years later, and one afternoon later in my case:
paulsutherland/polyonic-secure-pouch#12

I believe the issue here is the same:
https://github.com/calvinmetcalf/crypto-pouch/blob/master/index.js#L158

In summary: don't blacklist the keys you don't want to encrypt, instead whitelist the keys you want to encrypt. Doc has more

@paweu
Copy link

paweu commented Nov 18, 2022

It seems that in some cases (some adapters?) the PouchDB's bulkGet() internally calls get(). This is not detected by transform-pouch, which in turn calls outgoing() on the returned document two times - at get() and at bulkGet().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants