The vulnerability lies in the /common_teams API endpoint, which did not properly validate channel membership at the time of data retrieval. This allowed a deactivated user to exploit a race condition and access team names they were no longer authorized to see. The analysis of the patch reveals two key functions involved in this vulnerability.
The first is api4.getGroupMessageMembersCommonTeams in server/channels/api4/channel.go, which serves as the entry point for the API request. This function was calling the application logic without ensuring the user's current status was checked.
The second, and more critical, function is app.App.GetGroupMessageMembersCommonTeams in server/channels/app/channel.go. This function contained the flawed logic that fetched common teams for a channel's members without verifying if the user making the request was still an active member. The vulnerability was a classic Time-of-check Time-of-use (TOCTOU) problem, where the check for user validity and the actual data retrieval were not atomic.
The patch addresses this by introducing a new function, GetGroupMessageMembersCommonTeamsAsUser, which explicitly passes the requesting user's ID. The core logic was moved to a new private function, getGroupMessageMembersCommonTeams, which now includes a crucial check to ensure the requesting user is an active member of the channel before proceeding to fetch and return the list of common teams. If the user is not an active member, it returns an empty list, effectively closing the information leak.