Sync failed for updated docs from a local encrypted db
AndreasHohnholt opened this issue · 3 comments
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;
}
});
the reason for this issue may be the same as here:
calvinmetcalf/crypto-pouch#44
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
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().