casbin / Casbin.NET

An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
https://casbin.org
Apache License 2.0
1.13k stars 110 forks source link

Casbin .NET doesn't support commas in policy #310

Closed robin-83 closed 1 year ago

robin-83 commented 1 year ago

I have tried to escape or wrap commas like described here: https://casbin.org/docs/policy-storage But this does not work for Casbin.NET, instead I get an exception: System.ArgumentException: "Invalid policy size: expected 3, got 4." If I got that right then Casbin.NET calls a simple string.Split which is not aware of wrapped instances of the string parts or escaped characters. I would suggest using a csv package like Csv Helper to ensure that the parts are read correctly. My test case:

var enforcer = new Enforcer("model.conf", "policy.csv");
var isAllowed = enforcer.Enforce("alice@example.com", "Basic,Test", "Get");

With this model

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

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

[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act

and policy: p, alice@example.com, "Basic,Test", Get If I remove the comma and the quotes, everything works as expected.

casbin-bot commented 1 year ago

@sagilio @sociometry @AsakusaRinne

sagilio commented 1 year ago

You are right, we need a more stable parser. Here is a similer issue about this https://github.com/casbin/Casbin.NET/issues/264.

hsluoyz commented 1 year ago

@robin-83 fixed by: https://github.com/casbin/Casbin.NET/pull/317