mirror of https://github.com/xwiki-labs/cryptpad
ignore metadata commands which add invalid owners
This commit is contained in:
parent
61e66e9add
commit
69e61ec2f2
|
@ -15,6 +15,10 @@ var deduplicate = require("./deduplicate");
|
|||
|
||||
var commands = {};
|
||||
|
||||
var isValidOwner = function (owner) {
|
||||
return typeof(owner) === 'string' && owner.length === 44;
|
||||
};
|
||||
|
||||
// ["ADD_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
|
||||
commands.ADD_OWNERS = function (meta, args) {
|
||||
// bail out if args isn't an array
|
||||
|
@ -30,6 +34,7 @@ commands.ADD_OWNERS = function (meta, args) {
|
|||
|
||||
var changed = false;
|
||||
args.forEach(function (owner) {
|
||||
if (!isValidOwner(owner)) { return; }
|
||||
if (meta.owners.indexOf(owner) >= 0) { return; }
|
||||
meta.owners.push(owner);
|
||||
changed = true;
|
||||
|
@ -90,6 +95,7 @@ commands.ADD_PENDING_OWNERS = function (meta, args) {
|
|||
}
|
||||
// or fill it
|
||||
args.forEach(function (owner) {
|
||||
if (!isValidOwner(owner)) { return; }
|
||||
if (meta.pending_owners.indexOf(owner) >= 0) { return; }
|
||||
meta.pending_owners.push(owner);
|
||||
changed = true;
|
||||
|
@ -134,7 +140,7 @@ commands.RESET_OWNERS = function (meta, args) {
|
|||
}
|
||||
|
||||
// overwrite the existing owners with the new one
|
||||
meta.owners = deduplicate(args);
|
||||
meta.owners = deduplicate(args.filter(isValidOwner));
|
||||
return true;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue