loopback icon indicating copy to clipboard operation
loopback copied to clipboard

ACL does not apply to related models

Open superkhau opened this issue 11 years ago • 26 comments

Access is denied for related models even when the user is authenticated and has permissions on the primary model.

See https://github.com/strongloop/loopback-example-access-control/issues/41 and https://groups.google.com/forum/#!searchin/loopbackjs/access$20denied$20related$20model/loopbackjs/iCgMsTzuJ14/Efmdl33JcTQJ

superkhau avatar Dec 31 '14 01:12 superkhau

I came across this issue to so I dug into the LoopBack code itself to find that by default all related model methods have a DENY ALL ACL set. You need to explicitly open them up.

http://docs.strongloop.com/display/public/LB/Restricting+access+to+related+models

The ACLs do not inherit from the target model's endpoint.

GET /user/{id}/books // default ACL is DENY all 
GET /books // default ACL is ALLOW $authenticated

This definitely tripped me up for a while and is not explained in the documentation and example app.

blainsmith avatar Feb 20 '15 15:02 blainsmith

@superkhau, going through old issues... this can be closed right?

richardpringle avatar Jan 13 '16 19:01 richardpringle

@richardpringle Sure.

This definitely tripped me up for a while and is not explained in the documentation and example app.

@crandmck ^ for docs, @loay ^ for example app

@blainsmith Closing this issue. Please open a new one if you are still having problems.

superkhau avatar Jan 13 '16 19:01 superkhau

Thanks for following up. Closing this sounds good.

blainsmith avatar Jan 13 '16 20:01 blainsmith

I added a note to https://docs.strongloop.com/display/LB/Accessing+related+models. I'll go ahead and close.

crandmck avatar Jan 13 '16 21:01 crandmck

Ehhm, Am I missing something or is "By default, all related model methods have a DENY ALL ACL set" explicitly wrong?

True, that for the example with the build-in user model, all relations are default DENY ALL, but that is only true for that model explicitly and (a few other build-in) any relations created from custom models are ALLOW ALL, unless a DENY ACL is set. Right?

proreact-mj avatar Mar 01 '16 18:03 proreact-mj

@proreact-mj, a little confused with what you're asking. The best thing to do to understand is to just create a model and some ACLs and to just test it out. As far as relations go, the ACL should only affect the model that "has" the ACLs (the ACL array is populated in that model's JSON file).

If ModelA hasMany ModelB and both models are "public" (set in the model-config.json), any ACLs attached to ModelA will affect that model only. ModelB can still be accessed through the api.

richardpringle avatar Mar 01 '16 18:03 richardpringle

Fair enough. I have ~200 relations in my app, and none of them have ALLOW ACL and they all work fine.

My point is, that the general statement is in fact only true if the parent model has an explicit DENY ALL (i.e. not a default)

The reason for the questions, was just in case there where some security setting that I haven't yet found that set implicit DENY on all relations. I was very confused (and a bit worried) when reading that all relations had default deny and needed explicit allow

proreact-mj avatar Mar 01 '16 19:03 proreact-mj

@proreact-mj

By default, all related model methods have a DENY ALL ACL set

Where did you see that line, in the docs? Can you point me to a link please?

richardpringle avatar Mar 01 '16 19:03 richardpringle

First line in a yellow warning box :) https://docs.strongloop.com/display/public/LB/Accessing+related+models

proreact-mj avatar Mar 01 '16 19:03 proreact-mj

@proreact-mj, you're right, that is a little misleading. The statement is really only relevant to the built-in User Model.

@crandmck, can you take a look at this when you get a chance? I think it should be something like "By default, all related model methods will inherit DENY ALL ACL settings."

You can word it anyway you would like, but as @proreact-mj pointed out, the way it is currently worded only holds true for models that already have the "DENY ALL" ACL set (on the parent model).

Make sense? That gets convoluted quite quickly...

richardpringle avatar Mar 01 '16 19:03 richardpringle

I would suggest to not use the word "inherit" at all. The ACL governing, is the ACL on the base model called and the ACL of the related model does not come into play at all. Inheritance would suggest that the ACL somehow propergates down to the related model, while the case is that ALL enpoints of the called model (which just happens to include some relation-defined endpoints) has been explicitly set to deny.

proreact-mj avatar Mar 01 '16 19:03 proreact-mj

True, good call. @crandmck ^

richardpringle avatar Mar 01 '16 20:03 richardpringle

@richardpringle @proreact-mj If not "By default, all related model methods will inherit DENY ALL ACL settings." then please suggest the wording you'd like to see, and I'll make the change. Thanks.

crandmck avatar Mar 01 '16 20:03 crandmck

Suggestion (the yellow warning) to also cover the security risk in the issue: Base statement (possible security risk)

When accessing a related model, the active ACL is still the one for the model your are calling. So even if your model has DENY ALL, if ther model relating to it has no ACL, then all the relation endpoints will also be open

Example of security risk

eg GET /OpenModel/{id}/ACLSecuredModel will allow full access to secured model through the OpenModel's relations

Reversed base statement (risk of functionality missing / convoluted permission fails)

Contrariwise if your model has a DENY ALL eg. the build-in user model which is has it pr default, but the related models have no ACL, they will still not be accessible through the user model

Original example (which only covers functionality risk)

So, for example, even if the books model's default ACL is ALLOW $authenticated for GET /books, the route GET /user/{id}/books default will still be DENY ALL.

@crandmck You will also want to check (remove or rewrite) the warning box a bit further down the page. I'm not affiliated with Strongloop, not a documentation writer and English is my second language, so please check, correct and rewrite as you see fit :)

proreact-mj avatar Mar 02 '16 14:03 proreact-mj

Might be worth pointing out (underlining) that the current wording can lead to security problems. If a developer assumes that related models have a default DENY all, thus failing to close down access to a secured model through a less secure model, potentially exposing the entire database through nested includes.

proreact-mj avatar Mar 07 '16 10:03 proreact-mj

Sorry it took me so long to fix this. I changed the wording of the warning in https://docs.strongloop.com/display/LB/Accessing+related+models based on your suggestion @proreact-mj. Does this cover it?

crandmck avatar Mar 29 '16 21:03 crandmck

First part looks good. But the is another warning box further down the page that is still contradictory.

Might be a good place to put the information about explicit opening (the Reversed base statement and original example). Also clearly stating in the example eg. "For example, the build-in User model always have a default deny all, so to access related models you need to ...."

proreact-mj avatar Mar 30 '16 07:03 proreact-mj

I'm looking for a way to secure a related model. But I think I found a loopholes.

GET /pushIDs // ACL is deny for all, but everyone can create new records
GET /users/{id}/pushIDs // ACL is $owner can CRUD

In Explorer, it looks fine. I cannot access other's pushIDs from the above APIs, even I know the id of pushIDs records. However, I can get the pushIDs with this:

GET /users/{id}?filter={"include": "pushIDs"}

Is that a leak?

johncpang avatar Aug 12 '17 03:08 johncpang

As pr discussions in this thread and the subsequent documentation in Accessing related models this is by design.

Specifically: When accessing a related model, the active ACL is still the one for the model you are calling. So even if your model has DENY ALL permissions set, if the model relating to it has no ACL, then all the relation endpoints will be open. This can be a security risk because, for example, GET /OpenModel/{id}/ACLSecuredModel will allow full access to ACLSecuredModel through the OpenModel relations.

proreact-mj avatar Aug 14 '17 08:08 proreact-mj