node-casbin icon indicating copy to clipboard operation
node-casbin copied to clipboard

Are there keywords in expression parsing?

Open vaseala opened this issue 3 years ago • 2 comments

full example code

https://github.com/issuebox/casbin-jsep

policy.csv

p, alice, read
p, bob, write

normal instance

model1.conf

[request_definition]
r = sub_data, act

[policy_definition]
p = sub, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub_data.attrs.username == p.sub && r.act == p.act
const e1 = await newEnforcer(
  join(__dirname, "./model1.conf"),
  join(__dirname, "./policy.csv")
);

const result = await e1.enforce(
  {
    attrs: {
      id: "alice",
    },
  },
  "read"
);

// result === true

theresult is true,which is as expected!

exception instance

model2.conf only replaces attrs in the last line of model1.conf with attr, everything else remains the same

model2.conf

[request_definition]
r = sub_data, act

[policy_definition]
p = sub, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub_data.attr.username == p.sub && r.act == p.act

const e2 = await newEnforcer(
  join(__dirname, "./model2.conf"),
  join(__dirname, "./policy.csv")
);

const result = await e2.enforce(
  {
    attr: {
      id: "alice",
    },
  },
  "read"
);
// result === false

Running the program, the result obtained is false, which is not as expected

question

In the above two examples, only one letter is different, which leads to different results. After testing, there is also a user will cause the same problem, ask: user and attr are keywords? If yes, what other keywords?

vaseala avatar Sep 14 '22 06:09 vaseala

@nodece @Zxilly @Shivansh-yadav13

casbin-bot avatar Sep 14 '22 06:09 casbin-bot

@vaseala plz change all texts to English

hsluoyz avatar Sep 14 '22 07:09 hsluoyz

@vaseala there is no conflict like keywords, but found a bug which is causing this whenever a word ends with r or p like you said attr and user. Thanx for raising the issue

Shivansh-yadav13 avatar Oct 02 '22 06:10 Shivansh-yadav13

:tada: This issue has been resolved in version 5.19.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Oct 04 '22 14:10 github-actions[bot]