casbin / node-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
https://casbin.org
Apache License 2.0
2.61k stars 218 forks source link

regexMatch fails till v.5.34.0 #492

Closed otchilin closed 2 days ago

otchilin commented 4 days ago

Hello,

With the new 5.34.0 release which replaced the expression-eval lib by @casbin/expression-eval 5.2.0,
my regexMatch(r.act, p.act) doesn't work anymore.

It produces this kind of exception : isAccessGranted: Exception occurred, error= SyntaxError: Invalid regular expression: /*/: Nothing to repeat

If we debug it, we can notice that the key2 parameter of regexMatch function doesn't contain the good value during call and thus produce this error.

Hope it will help... Regards

hsluoyz commented 4 days ago

@otchilin why? we just forked the original expression-eval lib and @casbin/expression-eval 5.2.0 should have the same codebase with the original lib. Why are their behaviors different? You can check the commits

tx2002 commented 2 days ago

@otchilin Could you please provide more information? Specifically, it would be helpful if you could share your test code or indicate the exact step in your debugging process where you utilized @casbin/expression-eval. Thank you!

otchilin commented 2 days ago

In fact, there is a difference in the new expression-eval libs for the CallExpression implementation. In the previous version the regexMatchFunc was called without waiting for evaluateArrayAsync promise and thus it never raised an error on my '*' wildcard usage.

I was using some policies like this one: await this._enforcer.addPolicy('superadmin', '*', '*'); with a matcher declaration like this m = (r.sub == p.sub) && (r.obj == p.obj || p.obj == '*' ) && (p.act == '*' || regexMatch(r.act, p.act))

It was working, but it was a side effect of previous expression-eval version :/ I'll rework my policies to be compliant with matcher. In conclusion this was not a bug but rather a fix that raised an issue on my side ;)

Thanks for your quick reply. Regards.

hsluoyz commented 2 days ago

Closed as resolved