You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We found in testing that an input of unusual string type would cause the Enforce function to fail completely, as shown in the code block below. When calling the enforcer.Enforce function, an error of invalid policy size will be thrown, resulting in a failure to judge the permission. //exception error: false invalid policy size: expected 3, got 1, pvals: [role::35046358490550272]
import (
"fmt"
"github.com/casbin/casbin/v2"
redisAdapter "github.com/casbin/redis-adapter/v2"
"testing"
)
func TestRedisAdapter(t *testing.T) {
adapter := redisAdapter.NewAdapterWithPassword("tcp","localhost:6379","123")
enforcer, err := casbin.NewEnforcer("model.conf", adapter)
if err != nil{
panic(err)
}
enforcer.EnableAutoSave(true)
// Load policy from redis
enforcer.LoadPolicy()
// normal case
_, _ = enforcer.AddNamedPolicy("p", []string{"sub1", "obj1", "on"})
fmt.Println(enforcer.Enforce("sub1", "obj1","on"))
// exception case with newline character
sub2 := `role::35046358490550272
expr 855534449 + 870448142`
//it can be successfully inserted into redis list
_, _ = enforcer.AddNamedPolicy("p", []string{sub2, "obj2", "on"})
fmt.Println(enforcer.Enforce("sub1", "obj1", "on"))
//exception error: false invalid policy size: expected 3, got 1, pvals: [role::35046358490550272]
}
model.conf
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
g2 = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub) && g2(r.obj, p.obj) && r.act == p.act
The text was updated successfully, but these errors were encountered:
We found in testing that an input of unusual string type would cause the Enforce function to fail completely, as shown in the code block below. When calling the
enforcer.Enforce
function, an error of invalid policy size will be thrown, resulting in a failure to judge the permission.//exception error: false invalid policy size: expected 3, got 1, pvals: [role::35046358490550272]
model.conf
The text was updated successfully, but these errors were encountered: