The vulnerability is a privilege escalation caused by an off-by-one error in the database.Repository.ChangeCollaborationAccessMode function in internal/database/repo_collaboration.go. The original code checked if the requested access mode was greater than AccessModeOwner (mode > 4), which is always false for mode = 4. This allowed a collaborator with Admin access (mode=3) to escalate their privileges to Owner (mode=4).
The vulnerability was exposed through the web handler setting.ChangeCollaborationAccessMode in internal/route/repo/setting.go. This function takes the mode as a raw integer from the mode query parameter and passes it to the vulnerable ChangeCollaborationAccessMode function in the database layer. An attacker could send a POST request to /settings/collaboration/access_mode with mode=4 to trigger the privilege escalation.
The patch fixes this by:
- Modifying
database.Repository.ChangeCollaborationAccessMode to accept the actor's access mode.
- Adding validation to ensure the new mode is not higher than 'Admin' and not higher than the actor's own access level.
- Updating the call sites in
internal/route/repo/setting.go and internal/route/api/v1/repo_collaborators.go to pass the actor's access mode, thus enforcing the new security check.