-
-
Notifications
You must be signed in to change notification settings - Fork 467
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
[bug]Adding a policy that contains double quotes will cause an exception in the eval function #440
Comments
|
model.conf:
policy:
request:
|
@Wan95u plz provide full Java code (better in a test case format) |
@hsluoyz main code
Request
policy
|
@Wan95u Could you please provide more details on how you added the policy, such as which adapter you're using and the type of database? I performed some tests, and the results were correct even without calling public class MyTest {
@Test
public void jCasbin() {
Request.Sub sub = new Request().new Sub();
sub.setName("n3");
sub.setAge(1);
Request.Obj obj = new Request().new Obj();
obj.setField(Arrays.asList("f1", "f2"));
Request request = new Request();
request.setSub(sub);
request.setObj(obj);
request.setAct("read");
Policy policy = new Policy();
policy.setSub("");
policy.setObj("let test=seq.set('n3','n4');include(test,r.sub.name)");
policy.setAct("read");
Enforcer enforcer = new Enforcer("examples/test.conf");
// addPolicy
boolean flag = enforcer.addPolicy(policy.rule());
System.out.println("add policy:" + flag);
// verify
AviatorEvaluatorInstance aviatorEval = enforcer.getAviatorEval();
aviatorEval.setOption(Options.TRACE_EVAL, true);
EnforceResult enforceResult = enforcer.enforceEx(request.getSub(), request.getObj(), request.getAct());
System.out.println(enforceResult);
}
} |
@tx2002
I used casbin-spring-boot-starter:1.7.0, which is jscasbin:1.55.0.database type is mysql yaml:
|
🎉 This issue has been resolved in version 1.77.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Follow-up of #447. This seems to be rather an issue with the adapter than the core enforcement functionality.
EDIT: See below snippet which is used to load in the policy in the JDBC adapter:
|
@TYsewyn The version of the JDBC adapter I am using is 2.7.0, and it does not contain the code mentioned above. `
` I believe that the adapter.addPolicy(sec, ptype, rule) method is functionally reasonable, while the model.addPolicy(sec, ptype, rule) method has issues with the logic for handling policy strings. Currently, I simply remove the leading and trailing double quotes (since Aviator script strings support both double and single quotes, I am using single quotes to avoid the issue of nested double quotes). |
jcasbin version
1.5.5
What happened
When adding a new policy, if the rule contains double quotes, the Assertion.policy will also contain double quotes, causing the eval function to fail. Restarting the program and calling Helper.loadPolicyLine() will split the double quotes. I would like to ask about the original intention behind the design of both.
The text was updated successfully, but these errors were encountered: