Skip to content

Commit

Permalink
Some validation of existence of OUJS accounts for collaboration
Browse files Browse the repository at this point in the history
* This has resurfaced with another Author misunderstanding collaboration and potentially opening up a security hole with their script being edited by others. So at least we can check to see if the account(s) currently exists. They are still responsible for any unauthorized edits if they type the incorrect existing username.
* Also fixes a feature with unhandled casing... probably best to leave it exact unlike URLs to user homepages. Really don't need different casings floating around in these labels i.e. symmetry.

Post OpenUserJS#285
  • Loading branch information
Martii committed Jul 27, 2019
1 parent b5cb5c9 commit 259fe62
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,75 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
}

aInnerCallback(null);
}
},
function (aInnerCallback) {
// OpenUserJS `@author` validations
var author = null;

author = findMeta(aMeta, 'OpenUserJS.author.0.value');

if (author) {
User.findOne({
name: author
}, function (aErr, aUser) {
if (aErr) {
aInnerCallback(new statusError({
message: 'DB error finding `@author` in OpenUserJS block',
code: 500
}), null);
return;
}

if (!aUser) {
aInnerCallback(new statusError({
message: '`@author ' + author +
'` in OpenUserJS block does not exist or is incorrectly cased.',
code: 400
}), null);
return;
}

aInnerCallback(null);
});
} else {
aInnerCallback(null);
}
},
function (aOuterCallback) {
// OpenUserJS block `@collaborator` validations
var collaborators = null;

collaborators = findMeta(aMeta, 'OpenUserJS.collaborator.value');
if (collaborators) {
async.eachSeries(collaborators, function (aCollaborator, aInnerCallback) {
User.findOne({
name: aCollaborator
}, function (aErr, aUser) {
if (aErr) {
aOuterCallback(new statusError({
message: 'DB error finding `@collaborator` ' +
aCollaborator + ' in OpenUserJS block',
code: 500
}), null);
return;
}

if (!aUser) {
aOuterCallback(new statusError({
message: '`@collaborator ' + aCollaborator +
'` in OpenUserJS block does not exist or is incorrectly cased',
code: 400
}), null);
return;
}

aInnerCallback();
});
}, aOuterCallback);
} else {
aOuterCallback(null);
}
}

], function (aErr, aResults) {
var author = null;
Expand Down

0 comments on commit 259fe62

Please sign in to comment.