oauth check (#35553)
Some checks are pending
API / build (push) Waiting to run
Server CI / Compute Go Version (push) Waiting to run
Server CI / Check mocks (push) Blocked by required conditions
Server CI / Check go mod tidy (push) Blocked by required conditions
Server CI / check-style (push) Blocked by required conditions
Server CI / Check serialization methods for hot structs (push) Blocked by required conditions
Server CI / Vet API (push) Blocked by required conditions
Server CI / Check migration files (push) Blocked by required conditions
Server CI / Generate email templates (push) Blocked by required conditions
Server CI / Check store layers (push) Blocked by required conditions
Server CI / Check mmctl docs (push) Blocked by required conditions
Server CI / Postgres with binary parameters (push) Blocked by required conditions
Server CI / Postgres (push) Blocked by required conditions
Server CI / Postgres (FIPS) (push) Blocked by required conditions
Server CI / Generate Test Coverage (push) Blocked by required conditions
Server CI / Run mmctl tests (push) Blocked by required conditions
Server CI / Run mmctl tests (FIPS) (push) Blocked by required conditions
Server CI / Build mattermost server app (push) Blocked by required conditions
Web App CI / check-lint (push) Waiting to run
Web App CI / check-i18n (push) Blocked by required conditions
Web App CI / check-external-links (push) Blocked by required conditions
Web App CI / check-types (push) Blocked by required conditions
Web App CI / test (platform) (push) Blocked by required conditions
Web App CI / test (mattermost-redux) (push) Blocked by required conditions
Web App CI / test (channels shard 1/4) (push) Blocked by required conditions
Web App CI / test (channels shard 2/4) (push) Blocked by required conditions
Web App CI / test (channels shard 3/4) (push) Blocked by required conditions
Web App CI / test (channels shard 4/4) (push) Blocked by required conditions
Web App CI / upload-coverage (push) Blocked by required conditions
Web App CI / build (push) Blocked by required conditions

This commit is contained in:
Ben Cooke 2026-03-18 13:31:48 -04:00 committed by GitHub
parent 1dea4b1378
commit e9ae890a01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 70 additions and 0 deletions

View file

@ -341,6 +341,10 @@ func (a *App) handleAuthorizationCodeGrant(rctx request.CTX, oauthApp *model.OAu
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.expired_code.app_error", nil, "", http.StatusForbidden)
}
if authData.ClientId != clientId {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.client_id_mismatch.app_error", nil, "", http.StatusBadRequest)
}
if authData.RedirectUri != redirectURI {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.redirect_uri.app_error", nil, "", http.StatusBadRequest)
}
@ -395,6 +399,10 @@ func (a *App) handleRefreshTokenGrant(rctx request.CTX, oauthApp *model.OAuthApp
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.refresh_token.app_error", nil, "", http.StatusNotFound).Wrap(nErr)
}
if accessData.ClientId != oauthApp.Id {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.client_id_mismatch.app_error", nil, "", http.StatusBadRequest)
}
user, nErr := a.Srv().Store().User().Get(context.Background(), accessData.UserId)
if nErr != nil {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound).Wrap(nErr)

View file

@ -1400,6 +1400,64 @@ func TestGetOAuthAccessTokenForCodeFlow(t *testing.T) {
require.Contains(t, appErr.Id, "resource_mismatch")
})
})
t.Run("DifferentClient_CannotRedeemCode", func(t *testing.T) {
appA := createConfidentialOAuthApp("TestClientA")
appB := createConfidentialOAuthApp("TestClientB")
code := getAuthorizationCode(appA, "")
_, appErr := th.App.GetOAuthAccessTokenForCodeFlow(
th.Context,
appB.Id,
model.AccessTokenGrantType,
appA.CallbackUrls[0],
code,
appB.ClientSecret,
"",
"",
"",
)
require.NotNil(t, appErr)
require.Contains(t, appErr.Id, "client_id_mismatch")
require.Equal(t, http.StatusBadRequest, appErr.StatusCode)
})
t.Run("DifferentClient_CannotUseRefreshToken", func(t *testing.T) {
appA := createConfidentialOAuthApp("TestClientA")
appB := createConfidentialOAuthApp("TestClientB")
code := getAuthorizationCode(appA, "")
// Get a valid refresh token for appA
tokenResp, appErr := th.App.GetOAuthAccessTokenForCodeFlow(
th.Context,
appA.Id,
model.AccessTokenGrantType,
appA.CallbackUrls[0],
code,
appA.ClientSecret,
"",
"",
"",
)
require.Nil(t, appErr)
require.NotEmpty(t, tokenResp.RefreshToken)
// Try to use appA's refresh token with appB's credentials
_, appErr = th.App.GetOAuthAccessTokenForCodeFlow(
th.Context,
appB.Id,
model.RefreshTokenGrantType,
appB.CallbackUrls[0],
"",
appB.ClientSecret,
tokenResp.RefreshToken,
"",
"",
)
require.NotNil(t, appErr)
require.Contains(t, appErr.Id, "client_id_mismatch")
require.Equal(t, http.StatusBadRequest, appErr.StatusCode)
})
}
func TestParseOAuthStateTokenExtra(t *testing.T) {
t.Run("valid token with normal values", func(t *testing.T) {

View file

@ -2596,6 +2596,10 @@
"id": "api.oauth.get_access_token.bad_request.app_error",
"translation": "invalid_request: Bad request."
},
{
"id": "api.oauth.get_access_token.client_id_mismatch.app_error",
"translation": "invalid_grant: Token grant was not issued to this client."
},
{
"id": "api.oauth.get_access_token.credentials.app_error",
"translation": "invalid_client: Invalid client credentials."