-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mongoose .orFail()
does not work when permissions are implicitly denied
#218
Comments
Could you please show the implementation of |
Query.prototype.orFail = function(err) {
this.map(res => {
switch (this.op) {
case 'find':
if (res.length === 0) {
throw _orFailError(err, this);
}
break;
case 'findOne':
if (res == null) {
throw _orFailError(err, this);
}
break;
case 'update':
case 'updateMany':
case 'updateOne':
if (get(res, 'result.nModified') === 0) {
throw _orFailError(err, this);
}
break;
case 'findOneAndDelete':
if (get(res, 'lastErrorObject.n') === 0) {
throw _orFailError(err, this);
}
break;
case 'findOneAndUpdate':
case 'findOneAndReplace':
if (get(res, 'lastErrorObject.updatedExisting') === false) {
throw _orFailError(err, this);
}
break;
case 'deleteMany':
case 'deleteOne':
case 'remove':
if (res.n === 0) {
throw _orFailError(err, this);
}
break;
default:
break;
}
return res;
});
return this;
}; or you can view it at https://github.com/Automattic/mongoose/blob/b0fd1b0f9036505f1556155479d207c1fd3c4a8e/lib/query.js |
Thanks, I didn't know about I think this is a bug but I'll need some time to confirm this. |
Sorry, for the long response. So, yes it's a bug. Update: According to implementation details |
fixed in Thanks for the issue! |
I ran into this issue accidentally today, but the way my application is set up, it expends models not found to throw an error.
ex:
When the permission to view users is set, it works fine and dandy. The conditions for this query were
{ _id: '5d600d0ea21964033b4fc1bb', '$and': [ {} ] }
.But if the permission is implicitly denied, the conditions are
{ _id: '5d600d0ea21964033b4fc1bb', __forbiddenByCasl__: 1 }
. The problem is though that theuser
variable is returning null, and not throwing an exception.The text was updated successfully, but these errors were encountered: