-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Chaining on nested struct / object fields in ABAC policy #438
Comments
After a little digging I found the solution after finding the online editor finds the above code valid with setup like so: Model
Policy
Request
Enforcement Result true I needed to JSON.stringify my subject and object like so: expect(
await enforcer.enforce(
"User",
JSON.stringify(sub),
"Book",
JSON.stringify(obj),
"read"
)
).toBe(true); This was a little unexpected to me, because on the type hints for enforcer.enforce it says (my own emphasis added):
So, just wondering what good is making it the rvals an any[] in TypeScript and adding the phrase can be class instances if it doesn't handle nested structs properly in the js version unless they are strinigified? Seems strinigifying it would possibly be slower especially if it just becomes unstrinigified in JS? I'm mainly just wondering if I'm missing something here, or if there is actually a bug in using nested objects, or if I should just be strinigfying my objects. |
I think I found the bug :D woohoo!!! In your utils in casbin you have the following escape assertions function: function escapeAssertion(s) {
s = s.replace(/r\./g, 'r_');
s = s.replace(/p\./g, 'p_');
return s;
} The problem is owner ends with 'r' and has a dot after it like so in the policy line I propose the following fix this adds a negative look behind that will ensure's that the characters will only be replaced function escapeAssertion(s) {
s = s.replace(/(?<!\w)r\./g, 'r_');
s = s.replace(/(?<!\w)p\./g, 'p_');
return s;
} |
…cording to issue casbin#438 Fixed unwanted replacement of r. in evals according to issue casbin#438 (e.g. r.obj.owner.id wrongly becoming r_obj.owner_id instead of the correct r_obj.owner.id) fix casbin#438
🎉 This issue has been resolved in version 5.24.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi, I'm new to casbin and am using ABAC as outlined here: https://casbin.org/docs/abac
Overall I really like Casbin and I am currently writing a little helper library to help with writing policies easier with type safety.
Anyways, I'm running into an issue with chaining on nested structs and object fields in a policy sub_rule using ABAC.
I know policy rules support nested lookups atleast in Go's casbin, because of this issue: casbin/casbin#677
The following example is what I'm trying to get to work :D. Help would be appreciated :D
Code Sandbox Link
The text was updated successfully, but these errors were encountered: