Repository navigation
Conversation
shaohuzhang1
commented
Nov 13, 2026
| RoleConstants.EXTENDS_USER.get_workspace_role(), | ||
| ) | ||
| def get(self, request: Request, workspace_id: str, user_group_id: str, current_page: int, page_size: int): | ||
| d = UserGroupListPageSerializer.Query( |
Contributor
Author
There was a problem hiding this comment.
Here is an analysis of the code snippet, focusing on irregularities, potential issues and optimization suggestions.
1. Security & Permission Model Concern (Critical)
The most significant issue is likely a privilege escalation or unintended permission widening.
- Problem: You are adding
RoleConstants.USER.get_workspace_role()andRoleConstants.EXTENDS_USER.get_workspace_role()to the list of allowed roles for accessingUserList. - Risk:
- Typically, listing all users in a group (especially an admin/system-level user group) should not be accessible by regular
USERroles. - If this endpoint exposes sensitive user details (email, phone, department, internal IDs), granting read access to all regular users violates the principle of least privilege and could lead to data leakage or reconnaissance attacks.
- Typically, listing all users in a group (especially an admin/system-level user group) should not be accessible by regular
- Question: Was this intentional? If this endpoint is meant to only return non-sensitive metadata or if there’s another layer of filtering inside
get(), it might be acceptable. Otherwise, this is a serious security flaw.
2. Code Consistency & Readability
- Mixed Role Sources: The list mixes direct role constants (
PermissionConstants,RoleConstants.ADMIN) with method-call based workspace roles (.get_workspace_role()). This is consistent within itself, but ensure thatEXTENDS_ADMINandEXTENDS_WORKSPACE_MANAGEalso follow the same pattern (i.e., whether they need.get_workspace_role()or if they are already role strings). The diff implies they do not call.get_workspace_role(), while the new ones do. Verify this symmetry.
3. Potential Redundancy
- Overlap Check:
RoleConstants.EXTENDS_ADMINvsRoleConstants.ADMINRoleConstants.EXTENDS_WORKSPACE_MANAGEvsRoleConstants.WORKSPACE_MANAGERoleConstants.EXTENDS_USERvsRoleConstants.USER
- If
EXTENDS_*roles are supersets or subsets of the base roles, consider using a single source of truth or a helper utility to determine permissions to avoid maintaining parallel lists that can drift out of sync.
4. Naming Conventions & Type Checking
- Ensure that
RoleConstants.EXTENDS_ADMINetc. return compatible types. IfADMINreturns a string andEXTENDS_ADMINreturns an enum object, the permission decorator may fail silently or raise runtime errors depending on implementation. - Add type annotations to ensure all entries in the permission tuple are consistent (e.g.,
Sequence[str]orIterable[Callable]).
5. Optimization Suggestions
- Use a Role Grouping Utility: If this pattern of "Admin + Workspace Manage + User" repeats across many endpoints, extract it into a constant or helper function:
Then use:
USER_READABLE_ROLES = ( RoleConstants.EXTENDS_ADMIN, RoleConstants.EXTENDS_WORKSPACE_MANAGE.get_workspace_role(), RoleConstants.USER.get_workspace_role(), RoleConstants.EXTENDS_USER.get_workspace_role(), )
@permission_required( PermissionConstants.SYSTEM_USER_GROUP_READ, *USER_READABLE_ROLES, )
Summary of Recommendations
| Area | Issue | Recommendation |
|---|---|---|
| Security | Granting USER role access to list user group members |
✅ Verify intent. If sensitive data is exposed, revert addition of USER roles. Consider if EXTENDS_USER alone was sufficient. |
| Consistency | Mixed usage of .get_workspace_role() |
✅ Confirm all "workspace-scoped" roles consistently use .get_workspace_role(). Ensure EXTENDS_ADMIN doesn't need it if ADMIN didn’t. |
| Maintainability | Hardcoded role lists per endpoint | ✅ Extract common role combinations into reusable constants/functions. |
| Documentation | Lack of clarity on why EXTENDS_* exist |
✅ Add comments explaining the difference between base and extends roles, especially regarding permission inheritance. |
Suggested Revised Code (if USER access is truly intended and safe):
@permission_required(
PermissionConstants.SYSTEM_USER_GROUP_READ,
RoleConstants.ADMIN,
RoleConstants.WORKSPACE_MANAGE.get_workspace_role(),
RoleConstants.EXTENDS_ADMIN,
RoleConstants.EXTENDS_WORKSPACE_MANAGE.get_workspace_role(),
# ONLY INCLUDE BELOW IF REGULAR USERS SHOULD SEE THE LIST
RoleConstants.USER.get_workspace_role(),
RoleConstants.EXTENDS_USER.get_workspace_role(),
)
def get(self, request: Request, workspace_id: str, user_group_id: str, current_page: int, page_size: int):
...RoleConstants.USER.get_workspace_role(),
RoleConstants.EXTENDS_USER.get_workspace_role(),
peslyn
deleted the
pr@v3@fix_number_of_members_who_clicked_on_the_resource_authorization
branch
November 13, 2026 09:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: number of members who clicked on the resource authorization