The vulnerability described is a missing authorization check in Mattermost that allows guest users to discover public channels they are not members of via the /api/v4/teams/{team_id}/channels/ids endpoint. The provided commit e8c7e7d0252bbf1e098aae4a5ea05d945afd7e70 directly addresses this issue.
The analysis of the commit's diff reveals a change in server/channels/api4/channel.go, specifically within the getPublicChannelsByIdsForTeam function. This function is the handler for the vulnerable API endpoint. The patch introduces a new block of code that checks if the current user's session belongs to a guest. If it does, it iterates through the channels being requested and verifies that the guest user has the PermissionReadChannel permission for each one. If the permission is missing for any channel, it returns a permission error.
The absence of this check in vulnerable versions is the root cause of the security issue. Therefore, the getPublicChannelsByIdsForTeam function is identified as the vulnerable function. During exploitation, a stack trace or profiler would show this function being executed when a malicious request is made by a guest user to the vulnerable endpoint.