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

Context set in policy does not register for IdentityBasedPolicy and ResourceBasedPolicy #43

Closed
yaser-ali-s opened this issue Apr 9, 2021 · 2 comments
Labels
bug Something isn't working released

Comments

@yaser-ali-s
Copy link

Really sorry to be annoying but I'm working heavily with your project and really appreciate all the effort you've put into it.

It seems the context set during instantiation of IdentityBasedPolicy and ResourceBasedPolicy is not respected, as seen:

// IdentityBasedPolicy.ts
  can(
    this: IdentityBasedPolicy<T>,
    { action, resource, context }: EvaluateIdentityBasedInterface<T>
  ): boolean {
    return this.allowStatements.some((s) =>
      s.matches({
        action,
        resource,
        context, // <-- Not using this.context
        conditionResolver: this.conditionResolver
      })
    );
  }

  cannot(
    this: IdentityBasedPolicy<T>,
    { action, resource, context }: EvaluateIdentityBasedInterface<T>
  ): boolean {
    return this.denyStatements.some((s) =>
      s.matches({
        action,
        resource,
        context, // <-- Not using this.context
        conditionResolver: this.conditionResolver
      })
    );
  }
}

// ResourceBasedPolicy.ts
  can(
    this: ResourceBasedPolicy<T>,
    {
      principal,
      action,
      resource,
      principalType,
      context
    }: EvaluateResourceBasedInterface<T>
  ): boolean {
    return this.allowStatements.some((s) =>
      s.matches({
        principal,
        action,
        resource,
        principalType,
        context, // <-- Not using this.context
        conditionResolver: this.conditionResolver
      })
    );
  }

  cannot(
    this: ResourceBasedPolicy<T>,
    {
      principal,
      action,
      resource,
      principalType,
      context
    }: EvaluateResourceBasedInterface<T>
  ): boolean {
    return this.denyStatements.some((s) =>
      s.matches({
        principal,
        action,
        resource,
        principalType,
        context, // <-- Not using this.context
        conditionResolver: this.conditionResolver
      })
    );
  }
}

It is, however, respected in the ActionBasedPolicy:

// ActionBasedPolicy.ts
  can(
    this: ActionBasedPolicy<T>,
    { action, context }: EvaluateActionBasedInterface<T>
  ): boolean {
    return this.allowStatements.some((s) =>
      s.matches({
        action,
        context: context || this.context,
        conditionResolver: this.conditionResolver
      })
    );
  }

  cannot(
    this: ActionBasedPolicy<T>,
    { action, context }: EvaluateActionBasedInterface<T>
  ): boolean {
    return this.denyStatements.some((s) =>
      s.matches({
        action,
        context: context || this.context,
        conditionResolver: this.conditionResolver
      })
    );
  }
@roggervalf
Copy link
Owner

Hi @yaser-ali-s, thanks for submitting this bug, let me take a look on this.

roggervalf pushed a commit that referenced this issue Apr 11, 2021
## [4.8.2](v4.8.1...v4.8.2) (2021-04-11)

### Bug Fixes

* **evaluate:** using context in instantiation in IdentityBasedPolicy and ResourceBasedPolicy ([c0f3561](c0f3561)), closes [#43](#43)
@roggervalf
Copy link
Owner

🎉 This issue has been resolved in version 4.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@roggervalf roggervalf added released bug Something isn't working labels Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants