loopback
loopback copied to clipboard
BUG: registerResolver not blocking access?
Bug or feature request
- [x] Bug
- [ ] Feature request
Description of feature (or steps to reproduce if bug)
- Create a registerResolver for a role of your choice.
- Do a few database lookups, and return cb(null, false) and notice that access is still allowed
Link to sample repo to reproduce issue (if bug)
I will need to work on getting this together, as I am working on a private repo, but it is very repeatable if you do any lookups. Also the resolver is called twice which seems odd to me as well.
Expected result
Dynamic Role Resolver should block access
Actual result (if bug)
My simple ACL's
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "superadmin",
"permission": "ALLOW"
}
Role.registerResolver('superadmin', function(role, context, cb) {
var userId = Utils.getCurrentUserId();
if (userId > 0) {
var OrgModel = app.models.Organization;
OrgModel.findOne({where: {superorg: true}}, function(error, instance) {
//IF I add this---- return process.nextTick(() => cb(null, false)); ------here
//It will still allow access even though it clearly setup as false
if (error || !instance) {
Utils.logError('No SuperOrg Found: ' + error, 'RoleResolver', 'Errror');
return cb(null, false);
}
else {
//Find any Users that are orgadmins of this organization
var UserOrg = app.models.UserOrganization;
UserOrg.findOne({where: {userid: userId, organizationid: instance.id}},
function(error, instance) {
if (error || !instance) {
//This does not work, it returns and allows access
//Also using process nextTick it still allows access, when it shouldn't
return cb(null, false); --Still returns result when this user is not found?
}
else if (instance.orgadmin) {
return cb(null, true);
}
else {
return cb(null, false);
}
});
}
});
}
else {
console.log('Rejecting access because no data is found');
//This works, and blocks access correctly
return process.nextTick(() => cb(null, false));
}
});
Additional information (Node.js version, LoopBack version, etc)
Node Version 6.4.0 Loopback 2.34.1 and tested on 2.36
Sorry, figured it out, apparently if you derive from another model all ACL's come through, I caught this when walking through which ACL's were getting pushed.
Is there an easier way to see what ACL's are active for a given model?