hasPermission fails when called with multiple permissions if those permissions are granted by different roles #1351

Open
opened 2026-03-13 08:34:21 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @harveylee on GitHub (Jun 13, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

See https://stackblitz.com/edit/stackblitz-starters-wsvsumaj?file=index.js (node ./index.js to start)

  1. Use Organization plugin with two custom roles, each with a single custom permission (say, role AUser has a: use-a and role BUser has b: use-b)
  2. Assign both roles to one user
  3. Call hasPermission with each permission separately - both succeed
  4. Call hasPermission on both permissions together - fails

Current vs. Expected behavior

Expected: if user has the roles that grant permission A and permission B, then hasPermission on the union of those permissions (A and B) should also succeed
Actual: hasPermission returns success === false

What version of Better Auth are you using?

1.2.9

Provide environment information

- OS: Windows 11 Build 26100
- WSL2: Linux 6.6.87.1-microsoft-standard-WSL2 
- Debian trixie

Which area(s) are affected? (Select all that apply)

Backend, Client, Package

Auth config (if applicable)

See Stackblitz repro

Additional context

I think the reason is because the permissions for the roles are checked independently, and no single role has all of the requested permissions.

The way I expected this to work is that the permissions for all the roles are gathered first, and then those permissions are checked against the requested permissions.

Originally created by @harveylee on GitHub (Jun 13, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce See https://stackblitz.com/edit/stackblitz-starters-wsvsumaj?file=index.js (`node ./index.js` to start) 1. Use Organization plugin with two custom roles, each with a single custom permission (say, role AUser has `a: use-a` and role BUser has `b: use-b`) 2. Assign both roles to one user 3. Call `hasPermission` with each permission separately - both succeed 4. Call `hasPermission` on both permissions together - fails ### Current vs. Expected behavior Expected: if user has the roles that grant permission A and permission B, then `hasPermission` on the union of those permissions (A and B) should also succeed Actual: `hasPermission` returns `success === false` ### What version of Better Auth are you using? 1.2.9 ### Provide environment information ```bash - OS: Windows 11 Build 26100 - WSL2: Linux 6.6.87.1-microsoft-standard-WSL2 - Debian trixie ``` ### Which area(s) are affected? (Select all that apply) Backend, Client, Package ### Auth config (if applicable) ```typescript See Stackblitz repro ``` ### Additional context I think the reason is because the permissions for the roles are checked independently, and no single role has all of the requested permissions. The way I expected this to work is that the permissions for all the roles are gathered first, and then those permissions are checked against the requested permissions.
GiteaMirror added the bug label 2026-03-13 08:34:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 12, 2025):

Hi, @harveylee. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary

  • You reported that the hasPermission function in Better Auth v1.2.9 returns false when checking multiple permissions granted across different roles.
  • The problem occurs because the function checks permissions per role instead of aggregating them across all roles.
  • You provided a Stackblitz reproduction to demonstrate the issue.
  • There have been no further comments or updates on this issue.

Next Steps

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Sep 12, 2025): Hi, @harveylee. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary** - You reported that the `hasPermission` function in Better Auth v1.2.9 returns false when checking multiple permissions granted across different roles. - The problem occurs because the function checks permissions per role instead of aggregating them across all roles. - You provided a Stackblitz reproduction to demonstrate the issue. - There have been no further comments or updates on this issue. **Next Steps** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@harveylee commented on GitHub (Sep 13, 2025):

Still occurs in 1.3.9. I updated the Stackblitz repro (still at https://stackblitz.com/edit/stackblitz-starters-wsvsumaj?file=index.js)

@harveylee commented on GitHub (Sep 13, 2025): Still occurs in 1.3.9. I updated the Stackblitz repro (still at https://stackblitz.com/edit/stackblitz-starters-wsvsumaj?file=index.js)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 13, 2025):

Hi, @harveylee. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary

  • You reported that the hasPermission function returns false when checking multiple permissions granted across different roles.
  • The problem arises because hasPermission checks permissions per role instead of aggregating them.
  • You confirmed the issue still occurs in version 1.3.9 and provided an updated reproduction link.
  • The maintainers have yet to address the permission aggregation logic in hasPermission.

Next Steps

  • Please confirm if this issue is still relevant with the latest version of better-auth by commenting on this issue.
  • If no response is received, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 13, 2025): Hi, @harveylee. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary** - You reported that the `hasPermission` function returns false when checking multiple permissions granted across different roles. - The problem arises because `hasPermission` checks permissions per role instead of aggregating them. - You confirmed the issue still occurs in version 1.3.9 and provided an updated reproduction link. - The maintainers have yet to address the permission aggregation logic in `hasPermission`. **Next Steps** - Please confirm if this issue is still relevant with the latest version of better-auth by commenting on this issue. - If no response is received, I will automatically close this issue in 7 days. Thank you for your understanding and contribution!
Author
Owner

@harveylee commented on GitHub (Dec 15, 2025):

Hello. This is still an issue in better-auth 1.4.7. I have updated the Stackblitz reproduciton again
https://stackblitz.com/edit/stackblitz-starters-wsvsumaj

@harveylee commented on GitHub (Dec 15, 2025): Hello. This is still an issue in better-auth 1.4.7. I have updated the Stackblitz reproduciton again https://stackblitz.com/edit/stackblitz-starters-wsvsumaj
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1351