[PR #6774] [MERGED] fix(organization): validate role existence in inviteMember endpoint #6875

Closed
opened 2026-03-13 13:14:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6774
Author: @GautamBytes
Created: 12/15/2025
Status: Merged
Merged: 12/15/2025
Merged by: @Bekacru

Base: canaryHead: fix/organization-role-validation


📝 Commits (2)

  • 34c8940 fix(organization): validate role existence in inviteMember endpoint
  • 951e00e cleanup unused variables and assertions

📊 Changes

2 files changed (+110 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+39 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.test.ts (+71 -0)

📄 Description

Description

Fixes #6710 where the inviteMember endpoint allowed inviting users with non-existent roles (e.g., random strings).

Changes

  • Implemented validation logic in crud-invites.ts.
  • The logic now checks:
    1. Static Roles: Checks against default roles (admin, member, owner) and any custom roles defined in options.
    2. Dynamic Roles: If the role is not static and dynamic access control is enabled, it queries the database (batched query for performance).
  • Returns a BAD_REQUEST (400) if the role is invalid.
  • Added test cases in crud-members.test.ts to verify the fix.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Summary by cubic

Prevent inviting members with invalid roles in the inviteMember endpoint. Unknown roles now return 400 with ROLE_NOT_FOUND, with optional dynamic lookup for org-defined roles.

  • Bug Fixes
    • Validate roles against default and custom roles.
    • If dynamic access control is enabled, look up unknown roles in the database (batched).
    • Return 400 with ROLE_NOT_FOUND; tests cover invalid and valid role cases.

Written for commit 951e00edd8. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6774 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 12/15/2025 **Status:** ✅ Merged **Merged:** 12/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/organization-role-validation` --- ### 📝 Commits (2) - [`34c8940`](https://github.com/better-auth/better-auth/commit/34c894038d799293198ab30d3a032e5a93945c7c) fix(organization): validate role existence in inviteMember endpoint - [`951e00e`](https://github.com/better-auth/better-auth/commit/951e00edd88bf671cd441d8ead6531a159eefe9f) cleanup unused variables and assertions ### 📊 Changes **2 files changed** (+110 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+39 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.test.ts` (+71 -0) </details> ### 📄 Description ### Description Fixes #6710 where the `inviteMember` endpoint allowed inviting users with non-existent roles (e.g., random strings). ### Changes - Implemented validation logic in `crud-invites.ts`. - The logic now checks: 1. **Static Roles:** Checks against default roles (`admin`, `member`, `owner`) and any custom roles defined in options. 2. **Dynamic Roles:** If the role is not static and dynamic access control is enabled, it queries the database (batched query for performance). - Returns a `BAD_REQUEST` (400) if the role is invalid. - Added test cases in `crud-members.test.ts` to verify the fix. ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevent inviting members with invalid roles in the inviteMember endpoint. Unknown roles now return 400 with ROLE_NOT_FOUND, with optional dynamic lookup for org-defined roles. - **Bug Fixes** - Validate roles against default and custom roles. - If dynamic access control is enabled, look up unknown roles in the database (batched). - Return 400 with ROLE_NOT_FOUND; tests cover invalid and valid role cases. <sup>Written for commit 951e00edd88bf671cd441d8ead6531a159eefe9f. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:14:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6875