diff options
author | Robert Newson <rnewson@apache.org> | 2022-02-28 19:04:28 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2022-03-01 09:15:06 +0000 |
commit | 874625bd9710198388dce6e92f6861827b5479fc (patch) | |
tree | 95c46a6a36f15e2bc463053d3f99285007c00f2b | |
parent | e4b8a4624fc7ae09b4649aac9a8d68226208cd8b (diff) | |
download | couchdb-replicator_vdu_special_fields.tar.gz |
Prevent users from modifying the reserved _replication_* fieldsreplicator_vdu_special_fields
Only the replicator is permitted to do this. This PR enhances the
existing VDU to prohibit users from modifying the fields, in case the
user mistakenly believes that such edits are understood as
instructions to the replicator.
-rw-r--r-- | src/couch_replicator/src/couch_replicator_js_functions.hrl | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/couch_replicator/src/couch_replicator_js_functions.hrl b/src/couch_replicator/src/couch_replicator_js_functions.hrl index d41043309..1c49f5212 100644 --- a/src/couch_replicator/src/couch_replicator_js_functions.hrl +++ b/src/couch_replicator/src/couch_replicator_js_functions.hrl @@ -58,6 +58,21 @@ return; } + // Only the replicator may change these fields, though any authorised + // user may delete them. + if (oldDoc) { + var keys = Object.keys(newDoc) + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (key.indexOf('_replication_') === 0 && + typeof(oldDoc[key]) === 'string' && + typeof(newDoc[key]) === 'string' && + oldDoc[key] != newDoc[key]) { + reportError('Only the replicator may modify the ' + key + ' field.'); + } + } + } + if (newDoc._replication_state === 'failed') { // Skip validation in case when we update the document with the // failed state. In this case it might be malformed. However, |