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

feat: keep compatible with unexpected policy, revert PR: https://github.com/casbin/Casbin.NET/pull/337 #350

Closed sagilio0728 closed 2 months ago

sagilio0728 commented 2 months ago

fixed: #335

This change will be compatible with some unforeseen policy in which values count less or longer than model tokens. For example, If your policy definition is:

p = sub, obj, act

When we attempt to add the following policy, the old logic will ignore this action and return false. Furthermore, because the logic for checking unexpected policies is executed after the Adapter is called, the database will contain this anomalous data, and it will never be able to be loaded into memory.

"alice", "data1"
"alice", "data1", "write", "dump"

Starting from this change, the unexpected policies will be trimmed into the following expected format and can be smoothly added to the policy store. Of course, the return value will be true. Here is a simple test:

"alice", "data1", ""
"alice", "data1", "write", 

This is a more gentle approach. Conversely, there is another option where we throw an exception for all unexpected policies. But I believe this could be a change with high risk to the user. If the user prefers a more stringent method, we can provide an option for them to choose at later versions.

QA:

casbin-bot commented 2 months ago

@sagilio please review

github-actions[bot] commented 2 months ago

:tada: This PR is included in version 2.6.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: