I am currently using Meteor and I have some concerns regarding security vulnerabilities. My main goal is to restrict users from creating or modifying certain fields in the database. Specifically, I only want users to be able to add or update the name
and description
fields for a party.
Parties.allow({
insert: function (userId, party) {
return userId && party.owner === userId;
},
update: function (userId, party, fields, modifier) {
return userId && party.owner === userId;
},
});
I came across similar code in an Angular Meteor tutorial. However, it seems like individuals could potentially add any arbitrary field through the browser console using Minimongo. Is there a straightforward way for me to specify which fields are acceptable, and reject any inserts or updates that do not adhere to those defined fields? For updates, I thought of implementing a basic function:
function ensureFieldsAreOk(acceptableFields, fieldsInQuestion){
for(i = 0; i < fieldsInQuestion.length; ++i){
if(acceptableFields.indexOf(fieldsInQuestion[i]) === -1){
console.log("Hacking attempt detected");
return false;
}
}
return true;
}
A similar approach could be used for the insert command by utilizing the same function with Object.keys(party)
as the list of acceptable fields.
I highly doubt that I am the first person to encounter this issue, so there must be a standard method for addressing this concern.