You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The permission check for GET /api/products/1/categories then must perform two steps:
Verify that the caller is allowed to access the parent model instance (Product id 1).
Verify that the caller is allowed to execute the operation on the target model (READ Categories).
What is not clear: how to deal with writes, does POST /api/products/1/categories require write permissions for both Product and Category, or is it sufficient to havea READ permission for Product and WRITE permission for Category?
accessTarget seems like exactly what we need. We can just call checkAccess() on the target instead of the "from" model.
Verify that the caller is allowed to access the parent model instance (Product id 1).
Why do we need this? I guess this could be accomplished by calling checkAccess on both the accessTarget and the original parent model.
So to illustrate the check:
/api/products/1 => READ (Product.findById()) Product as $ROLE
/api/products/1/categories =>
READ (Product.findById()) Product as $ROLE
and
READ (Category.find()) Category as $ROLE
What is not clear: how to deal with writes, does POST /api/products/1/categories require write permissions for both Product and Category, or is it sufficient to havea READ permission for Product and WRITE permission for Category?
Hmm... This makes me think that we should treat these methods as sugar and just apply the ACLs as if they were accessed without a relation. If we do this the accessType and accessTarget would be used to form a new AccessContext and a single check would be performed:
/api/products/1/categories => READ (Category.find()) Category as $ROLE
During an offline discussion @raymondfeng brought up an interesting alternative. To pass the remote context around the call stack as part of the options param.
The implementation of this has several parts.
1. injecting the remoteContext into the options argument
2. check access in all DAO methods by using observers
// add this to each DAO methodif(options&&options.remoteContext){// new method based on Model.checkAccess()Model.checkAccessForContext({method: 'create',// or the methodmodelId: modelId,remoteContext: options.remoteContext,},continueWithDaoMehtod);}
3. ensure options.remoteContext is passed in every DAO call (especially the relation sugar methods)
I'm leaning towards the simpler solution: adding an accessTarget to the remoting metadata and treating __get__categories exactly like Categories.find().
There is one thing I dislike about options.remoteContext: it's introducing coupling between strong-remoting context object, loopback's checkAccessForContext and loopback-datasource-juggler.
At the moment, juggler is a standalone library that can be used on its own and I'd like to preserve that, as it is a good design decision IMO.
Having said that, I can imagine we can rework this initial proposal to make it more generic and fit better into the standalone juggler. For example, instead of options.remoteContext, we can pass options.principal and expect Models to override Model._authorizeOperation({ operation, instanceId, principal }). Operation = method name, e.g. "create" or "updateOrCreate". instanceId = the id of the affected model instance, undefined for "create".
Now it all depends on how much time we are willing to invest into this. Providing the current user in the options object will allow us to implement acl-based filtering in queries, i.e. the find method can return only the items the user can read. (At the moment, it returns 401 unless the user can read everything.) On the other hand, this solution will need more time to implement compared to the accessTarget alternative.
Actually, the solution based on options.remoteContext has a major issue: the authentication will be performed by DAO methods, meaning that any strong-remoting hooks will be executed before the user is authorized to perform the operation - see #1191.
In the light of that, I am leaning towards accessTarget too.
@raymondfeng Using disableInclude does not work, because some dynamics roles need to use the include feature.
Would it be possible to add something similar to ACL, but specific to the "include". Whenever nested include is used it would check each models "inclusion" tag and run. This way each model will decides access by role.
What is the status on this issue??? This should definitely be implemented in next versions... You should no way be able to access a model B without read access just because you have access to model A which is related to model B...
This can be easily reproduced at example repo. If you convert all ACLs to a single deny all you should not be able to access anything. However accessing the user/:id with filter={"include":"projects"} then voila... user projects, although ACL denies...
@caleuanhopkins This indeed complies with security, but it simply disables the feature. The best option would be to have the feature but propagate proper permissions to included models...
With the release of LoopBack 4.0 GA (see the announcement), this module has entered Active LTS mode and no longer accepts new features (see our LTS policy).
Activity
[-]Extend ACL with First Relation Support[/-][+]70 Extend ACL with First Relation Support[/+][-]70 Extend ACL with First Relation Support[/-][+]A Extend ACL with First Relation Support[/+][-]A Extend ACL with First Relation Support[/-][+]70 Extend ACL with First Relation Support[/+]bajtos commentedon May 6, 2015
An idea to consider:
The remoting metadata already has
accessTypeoption allowing the method to specify READ/WRITE instead of EXECUTE.Perhaps we can add
accessTargetoption that will allow the method to specify the model to use for checking the access control?For example,
Product.prototype.__get__categoriescan haveaccessTarget: 'Category'.The permission check for
GET /api/products/1/categoriesthen must perform two steps:Product id 1).READ Categories).What is not clear: how to deal with writes, does
POST /api/products/1/categoriesrequire write permissions for both Product and Category, or is it sufficient to havea READ permission for Product and WRITE permission for Category?ritch commentedon May 6, 2015
accessTargetseems like exactly what we need. We can just callcheckAccess()on the target instead of the "from" model.Why do we need this? I guess this could be accomplished by calling
checkAccesson both theaccessTargetand the original parent model.So to illustrate the check:
Hmm... This makes me think that we should treat these methods as sugar and just apply the ACLs as if they were accessed without a relation. If we do this the
accessTypeandaccessTargetwould be used to form a newAccessContextand a single check would be performed:ritch commentedon May 6, 2015
During an offline discussion @raymondfeng brought up an interesting alternative. To pass the remote context around the call stack as part of the options param.
The implementation of this has several parts.
1. injecting the
remoteContextinto theoptionsargument2. check access in all
DAOmethods by using observers3. ensure
options.remoteContextis passed in everyDAOcall (especially the relation sugar methods)ritch commentedon May 6, 2015
I'm leaning towards the simpler solution: adding an
accessTargetto the remoting metadata and treating__get__categoriesexactly likeCategories.find().[-]70 Extend ACL with First Relation Support[/-][+]70 Extend ACL with Relation Support[/+][-]70 Extend ACL with Relation Support[/-][+]Extend ACL with Relation Support[/+]bajtos commentedon May 7, 2015
There is one thing I dislike about
options.remoteContext: it's introducing coupling between strong-remoting context object, loopback'scheckAccessForContextand loopback-datasource-juggler.At the moment, juggler is a standalone library that can be used on its own and I'd like to preserve that, as it is a good design decision IMO.
Having said that, I can imagine we can rework this initial proposal to make it more generic and fit better into the standalone juggler. For example, instead of
options.remoteContext, we can passoptions.principaland expect Models to overrideModel._authorizeOperation({ operation, instanceId, principal }). Operation = method name, e.g. "create" or "updateOrCreate". instanceId = the id of the affected model instance, undefined for "create".Now it all depends on how much time we are willing to invest into this. Providing the current user in the
optionsobject will allow us to implement acl-based filtering in queries, i.e. thefindmethod can return only the items the user can read. (At the moment, it returns 401 unless the user can read everything.) On the other hand, this solution will need more time to implement compared to theaccessTargetalternative.I am personally fine with both ways.
bajtos commentedon May 7, 2015
Actually, the solution based on
options.remoteContexthas a major issue: the authentication will be performed by DAO methods, meaning that any strong-remoting hooks will be executed before the user is authorized to perform the operation - see #1191.In the light of that, I am leaning towards
accessTargettoo.22 remaining items
raymondfeng commentedon Jul 22, 2016
@mohit1993 You can set
disableIncludeper relation. Would that help?mohitgoyal707 commentedon Jul 22, 2016
On Fri 22 Jul, 2016, 9:11 PM Raymond Feng, notifications@github.com wrote:
But i wanted to use inclusion with access token.
Regards
Mohit Goyal
madianas commentedon Sep 9, 2016
@raymondfeng Using
disableIncludedoes not work, because some dynamics roles need to use the include feature.Would it be possible to add something similar to ACL, but specific to the "include". Whenever nested include is used it would check each models "inclusion" tag and run. This way each model will decides access by role.
mitsos1os commentedon Apr 10, 2017
What is the status on this issue??? This should definitely be implemented in next versions... You should no way be able to access a model B without read access just because you have access to model A which is related to model B...
This can be easily reproduced at example repo. If you convert all ACLs to a single deny all you should not be able to access anything. However accessing the user/:id with
filter={"include":"projects"}then voila... user projects, although ACL denies...eisaqasemi commentedon Apr 24, 2017
here is a workaround which works with one level deep include but not with nested include.
caleuanhopkins commentedon Apr 28, 2017
@mitsos1os I've just found out this can stop the
includesbug:mitsos1os commentedon Apr 28, 2017
@caleuanhopkins This indeed complies with security, but it simply disables the feature. The best option would be to have the feature but propagate proper permissions to included models...
bajtos commentedon Oct 11, 2018
With the release of LoopBack 4.0 GA (see the announcement), this module has entered Active LTS mode and no longer accepts new features (see our LTS policy).