Repository navigation
Closed
Labels
Description
i have static ACL rules inside my model named 'Event'
this are the acl in my Event.json
"acls": [
{
"model": "*",
"property": "*",
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"model": "*",
"property": "*",
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}`
it works properly during rest calls to that model
but , i have custom route for that model . During that route i check with "ACL.checkpermission" to verify permission for principal manually . This is my custom route in my boot script
module.exports = function(app){
app.get('/getEvents', function(req, res, next){
app.models.RoleMapping.findOne({
where : {principalId: request.accessToken.userId},
include: {relation: 'role', fields: ['name']}
}).then(function(map){
var principal = map.role().name;
var principalType = 'ROLE';
app.models.ACL.checkPermission(principalType, principal, 'Event', '*', 'READ',
function(err, result){
if(!err){ console.log(JSON.stringify(result)); }
});
}in console i got this ,
loopback:security:acl The following ACLs were searched: +0ms
loopback:security:acl ---Resolved--- +1ms
loopback:security:acl The following ACLs were searched: +8s
loopback:security:acl ---ACL--- +1ms
loopback:security:acl model Event +0ms
loopback:security:acl property * +0ms
loopback:security:acl principalType ROLE +0ms
loopback:security:acl principalId admin +0ms
loopback:security:acl accessType * +0ms
loopback:security:acl permission ALLOW +0ms
loopback:security:acl with score: +0ms 8020
loopback:security:acl ---ACL--- +0ms
loopback:security:acl model Event +0ms
loopback:security:acl property * +0ms
loopback:security:acl principalType ROLE +0ms
loopback:security:acl principalId $everyone +0ms
loopback:security:acl accessType * +0ms
loopback:security:acl permission DENY +0ms
loopback:security:acl with score: +0ms 8007
loopback:security:acl Permission denied by statically resolved permission +0ms
loopback:security:acl Resolved Permission: {"model":"Event","property":"*","accessType":"READ","permission":"DENY","methodNames":[]} +0ms
{"model":"Event","property":"*","accessType":"READ","permission":"DENY","methodNames":[]}Later while i check with 'function checkpermission' in acl.js.
i found that issue is with ''resolvePermission" invoked inside checkpermission ,
the issue is missing 'break' statement refer code below at '@issuehere'
ACL.resolvePermission = function resolvePermission(acls, req) {
if (!(req instanceof AccessRequest)) {
req = new AccessRequest(req);
}
// Sort by the matching score in descending order
acls = acls.sort(function(rule1, rule2) {
return ACL.getMatchingScore(rule2, req) - ACL.getMatchingScore(rule1, req);
});
var permission = ACL.DEFAULT;
var score = 0;
for (var i = 0; i < acls.length; i++) {
var candidate = acls[i];
score = ACL.getMatchingScore(candidate, req);
if (score < 0) {
// the highest scored ACL did not match
break;
}
if (!req.isWildcard()) {
// We should stop from the first match for non-wildcard
permission = candidate.permission;
break;
} else {
if (req.exactlyMatches(candidate)) {
permission = candidate.permission;
break;
}
// For wildcard match, find the strongest permission
var candidateOrder = AccessContext.permissionOrder[candidate.permission];
var permissionOrder = AccessContext.permissionOrder[permission];
if (candidateOrder > permissionOrder) {
permission = candidate.permission;
//@issuehere
break; //This is the fix
}
}
}
if (debug.enabled) {
debug('The following ACLs were searched: ');
acls.forEach(function(acl) {
acl.debug();
debug('with score:', acl.score(req));
});
}
var res = new AccessRequest(req.model, req.property, req.accessType,
permission || ACL.DEFAULT);
return res;
};
Activity
richardpringle commentedon Mar 22, 2016
@vkeyrockz would you like to submit a PR for the fix?
loay commentedon Nov 3, 2016
Hi @vkeyrockz
As mentioned above, can you please submit a PR for the fix?
Please follow this for reference: http://loopback.io/doc/en/contrib/code-contrib.htm
Thanks.
[-]ACL checkpermission not working properly [/-][+]ACL checkpermission not working properly[/+]faridnsh commentedon Mar 18, 2017
I made a pull request(#3293) for this.
ebarault commentedon Mar 18, 2017
@vkeyrockz @alFReD-NSH : it would be better to reproduce your issue before investigating further in the proposed fix.
The log trace with debug string
loopback:securitywould be more appropriate also.May i ask why you are setting the custom route this way rather then building a custom remote method (hence reusing the built-in loopback access-control system?)
The ACL.checkPermission() method is not meant to be used directly. It's only used in LoopBack to resolve permissions associated to scopes which is used for authorizing apps to perform requests, not users. It's not used in the main access control method ACL.checkAccessForContext() which you are sort of mocking in your code snippet.
I'd highly recommend not using this method to enforce access control in your app.
If you still think there's an uncovered issue, could you reproduce your issue using the loopback sandbox?
https://github.com/strongloop/loopback-sandbox
stale commentedon Aug 23, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
stale commentedon Sep 6, 2017
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the
CODEOWNERSfile at the top-level of this repository.