Skip to content

Commit d714026

Browse files
authored
fix(teams): Prevent contributors from downgrading org admins' team roles (#108288)
VULN-734: When a team member had no explicit team role (inheriting from their org role), the permission check defaulted to allowing the change. Use the target member's minimum team role from their org role instead of defaulting to True. <!-- Describe your PR here. -->
1 parent 1dd5d51 commit d714026

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/sentry/core/endpoints/organization_member_team_details.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ def put(
412412
old_role = team_roles.get(omt.role) if omt.role else None
413413
except KeyError:
414414
old_role = None
415-
can_set_old_role = can_set_team_role(request, team, old_role) if old_role else True
415+
if old_role is None:
416+
old_role = roles.get_minimum_team_role(member.role)
417+
can_set_old_role = can_set_team_role(request, team, old_role)
416418

417419
# Verify that the request is allowed to set both the old and new role to prevent role downgrades by low-privilege users
418420
if not (can_set_new_role and can_set_old_role):

‎tests/sentry/core/endpoints/test_organization_member_team_details.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,3 +1126,22 @@ def test_team_contributor_cannot_downgrade_team_admin(self) -> None:
11261126

11271127
assert resp.status_code == 400
11281128
assert resp.data["detail"] == ERR_INSUFFICIENT_ROLE
1129+
1130+
@with_feature("organizations:team-roles")
1131+
def test_member_cannot_downgrade_org_admin_without_explicit_team_role(self) -> None:
1132+
"""VULN-734: A contributor must not be able to downgrade an org admin
1133+
who has no explicit team role (their effective role comes from their
1134+
org role's minimum team role mapping)."""
1135+
# Access cached_property to create the user attribute
1136+
_ = self.member_on_team
1137+
self.login_as(self.member_on_team_user)
1138+
1139+
resp = self.get_response(
1140+
self.org.slug,
1141+
self.admin_on_team.id,
1142+
self.team.slug,
1143+
teamRole="contributor",
1144+
)
1145+
1146+
assert resp.status_code == 400
1147+
assert resp.data["detail"] == ERR_INSUFFICIENT_ROLE

0 commit comments

Comments
 (0)