Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions common/models/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ module.exports = function(ACL) {
* @param {AccessRequest} req The access request
* @returns {AccessRequest} result The resolved access request
*/
ACL.resolvePermission = function resolvePermission(acls, req) {
ACL.resolvePermission = function resolvePermission(acls, req, principalType, principalId) {
if (!(req instanceof AccessRequest)) {
req.registry = this.registry;
req = new AccessRequest(req);
Expand All @@ -231,6 +231,16 @@ module.exports = function(ACL) {
}
if (!req.isWildcard()) {
// We should stop from the first match for non-wildcard
permission = candidate.permission;

// Not really. We must find the first permission that matches our request
var new_candidate = acls.find((acl) => {
return ((acl.principalType === principalType) && (acl.principalId === principalId));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried out this PR as a monkey patch on my system. I had to add this condition:

(acl.accessType === req.accessType)

otherwise the permissions check would do things like allow write access when only read access was granted.

});
if (new_candidate) {
candidate = new_candidate;
}

permission = candidate.permission;
break;
} else {
Expand All @@ -244,6 +254,7 @@ module.exports = function(ACL) {
if (candidateOrder > permissionOrder) {
permission = candidate.permission;
}
break;
}
}

Expand Down Expand Up @@ -348,7 +359,7 @@ module.exports = function(ACL) {
var acls = this.getStaticACLs(model, property);

// resolved is an instance of AccessRequest
var resolved = this.resolvePermission(acls, req);
var resolved = this.resolvePermission(acls, req, principalType, principalId);

if (resolved && resolved.permission === ACL.DENY) {
debug('Permission denied by statically resolved permission');
Expand All @@ -368,7 +379,7 @@ module.exports = function(ACL) {
}
acls = acls.concat(dynACLs);
// resolved is an instance of AccessRequest
resolved = self.resolvePermission(acls, req);
resolved = self.resolvePermission(acls, req, principalType, principalId);
return callback(null, resolved);
});
return callback.promise;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback"
"url": "https://github.com/supermafete/loopback-right-checkpermission"
},
"browser": {
"express": "./lib/browser-express.js",
Expand Down