The vulnerability exists in the OAuth 2.0 implementation of Mattermost, specifically in the authorization code and refresh token grant flows. The root cause is the failure to bind the client identity during the token redemption process.
The patch e9ae890a013bb57989fcbdb548d8b7b86b240237 addresses this by adding checks in two key functions within server/channels/app/oauth.go:
-
handleAuthorizationCodeGrant: This function processes the authorization code grant. The patch adds a check to ensure that the clientId in the authorization data matches the clientId of the client making the request. Without this check, a malicious client could redeem an authorization code issued to another client.
-
handleRefreshTokenGrant: This function handles the refresh token grant. The patch introduces a check to verify that the clientId associated with the access token data (derived from the refresh token) matches the ID of the OAuth application making the request. This prevents a client from using a refresh token that was not issued to it.
These two functions are the locations of the vulnerability. An attacker could craft a request to the token endpoint, and if they are an authenticated client, they could redeem codes or refresh tokens from other clients. The runtime profile during exploitation would show calls to app.handleAuthorizationCodeGrant or app.handleRefreshTokenGrant via the main GetOAuthAccessTokenForCodeFlow function.