Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circular link will make getImplicitRolesForUser stackoverflow #150

Closed
GopherJ opened this issue May 5, 2020 · 5 comments
Closed

circular link will make getImplicitRolesForUser stackoverflow #150

GopherJ opened this issue May 5, 2020 · 5 comments

Comments

@GopherJ
Copy link
Member

GopherJ commented May 5, 2020

mode.conf

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && regexMatch(r.act, p.act)
p, book_admin , /book/1, GET
p, pen_admin , /pen/1, GET

g, *, book_admin 
g, *, pen_admin

patten matching func:

keyMatch

error: e.getImplicitRolesForUser("alice") will cause stackoverflow

What's happening

Step1: Since we have pattern matching function and alice match *, then when we createRole alice will add * in her role list. While calling e.getImplicitRolesForUser("alice").

The first loop, we will get alice's direct role list:

["*"]

Step2: Then we call e.getImplicitRolesForUser("*"), and in its first iteration we get the following role list:

["book_admin", "pen_admin"]

Step3: Then we call e.getImplicitRolesForUser("book_admin") and e.getImplicitRolesForUser("pen_admin"), it founds book_admin matches * then it returns also * and the next call will return to our step1.

@GopherJ
Copy link
Member Author

GopherJ commented May 5, 2020

I suggest switching to casbin golang's implementation

@nodece
Copy link
Member

nodece commented May 8, 2020

@GopherJ The have same implementation in golang. So I try to do a fix in casbin/casbin#452.

@GopherJ
Copy link
Member Author

GopherJ commented May 8, 2020

@nodece I think we should fix first:

const role = await this.getImplicitRolesForUser(n, ...domain);
, it cannot handle this type of link * -> book_admin -> *. In casbin-rs it crashed and I fixed it in: casbin/casbin-rs#131

casbin/casbin-rs@1aa11d6#diff-94f22c9d3dc2cf7a1c731fa147d2dbb2R247-R260

circular link in pattern we can solve it later because the importance is not to crash

@nodece
Copy link
Member

nodece commented May 9, 2020

@GopherJ I submitted a patch in #155 , Could you review it?

@nodece
Copy link
Member

nodece commented May 9, 2020

fixed in #155

@nodece nodece closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants