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

OPL: Incorrect Evaluation of Permissions in Ory Keto #1522

Open
5 tasks done
LukaGiorgadze opened this issue Apr 17, 2024 · 0 comments
Open
5 tasks done

OPL: Incorrect Evaluation of Permissions in Ory Keto #1522

LukaGiorgadze opened this issue Apr 17, 2024 · 0 comments
Labels
bug Something is not working.

Comments

@LukaGiorgadze
Copy link

Preflight checklist

Ory Network Project

No response

Describe the bug

When evaluating user permissions in Ory Keto, a discrepancy occurs based on the order of user group checks. When a user is only in the "owners" group, the expected behavior is to return True for the itemView perm. However, when the line this.related.owners.includes(ctx.subject) is moved up in the code block, while keeping the rest of the logic identical, the function incorrectly returns False. This issue arises despite the fact that the code remains technically the same.

This discrepancy manifests when incorporating a check for blocked users, denoted by !this.related.blockedUsers.includes(ctx.subject) && (). The unexpected behavior undermines the intended functionality of permission evaluation and could potentially lead to incorrect access control decisions.

class User implements Namespace {}

class LegalEntityUserGroup implements Namespace {
  related: {
    // predefined roles
    owners: User[];
    administrators: User[];
    creators: User[];
    viewers: User[];
    members: User[];
  };
}

class BlockedUserGroup implements Namespace {
  related: {
    blockedUsers: User[];
  };
}

class LegalEntity implements Namespace {
  related: {
    // pre-deifned roles
    owners: SubjectSet<LegalEntityUserGroup, "owners">[];
    administrators: SubjectSet<LegalEntityUserGroup, "administrators">[];
    creators: SubjectSet<LegalEntityUserGroup, "creators">[];
    viewers: SubjectSet<LegalEntityUserGroup, "viewers">[];
    members: SubjectSet<LegalEntityUserGroup, "members">[];
    blockedUsers: SubjectSet<BlockedUserGroup, "blockedUsers">[];
  };

  permits = {
    own: (ctx: Context): boolean =>
        !this.related.blockedUsers.includes(ctx.subject) &&
        this.related.owners.includes(ctx.subject),

    itemView: (ctx: Context): boolean =>
      !this.related.blockedUsers.includes(ctx.subject) &&
      (this.related.administrators.includes(ctx.subject) ||
      this.related.creators.includes(ctx.subject) ||
      this.related.viewers.includes(ctx.subject) ||
      this.related.owners.includes(ctx.subject) || // ⚠️ move this line up and it it won't work.
      this.related.members.includes(ctx.subject)),

  };
}

Reproducing the bug

  1. Add User in LegalEntityUserGroup as owner use object legalentity_123;
  2. Relate LegalEntityUserGroup to LegalEntity
  3. Send request:
./check
?namespace=LegalEntity
&relation=itemView
&object=legalentity_123
&subject_set.namespace=User
&subject_set.object=user_123
&subject_set.relation=

Relevant log output

No response

Relevant configuration

No response

Version

v0.11.1-alpha.0

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker Compose

Additional Context

No response

@LukaGiorgadze LukaGiorgadze added the bug Something is not working. label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

No branches or pull requests

1 participant