Skip to content
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

The exception string type causes the Enforce function to completely fail #23

Closed
zj611 opened this issue Jan 17, 2022 · 3 comments
Closed
Assignees

Comments

@zj611
Copy link

zj611 commented Jan 17, 2022

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
@casbin-bot
Copy link
Member

@tangyang9464 @closetool @sagilio

@fabian4
Copy link
Member

fabian4 commented Jan 18, 2022

Same with casbin/casbin#950

@hsluoyz
Copy link
Member

hsluoyz commented Jan 19, 2022

See: casbin/casbin#950 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants