-
Notifications
You must be signed in to change notification settings - Fork 61k
fix(core): Add ownership check to MCP OAuth client deletion #27446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RicardoE105
merged 2 commits into
master
from
ado-5000-cross-user-oauth-client-deletion-via-missing-ownership-check
Mar 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/cli/src/modules/mcp/__tests__/mcp.oauth-clients.controller.api.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { testDb } from '@n8n/backend-test-utils'; | ||
| import type { User } from '@n8n/db'; | ||
| import { Container } from '@n8n/di'; | ||
|
|
||
| import { createOwner, createMember } from '@test-integration/db/users'; | ||
| import { setupTestServer } from '@test-integration/utils'; | ||
|
|
||
| import { OAuthClientRepository } from '../database/repositories/oauth-client.repository'; | ||
| import { UserConsentRepository } from '../database/repositories/oauth-user-consent.repository'; | ||
|
|
||
| const testServer = setupTestServer({ endpointGroups: ['mcp'], modules: ['mcp'] }); | ||
|
|
||
| let owner: User; | ||
| let member: User; | ||
| let oauthClientRepository: OAuthClientRepository; | ||
| let userConsentRepository: UserConsentRepository; | ||
|
|
||
| beforeAll(async () => { | ||
| owner = await createOwner(); | ||
| member = await createMember(); | ||
| oauthClientRepository = Container.get(OAuthClientRepository); | ||
| userConsentRepository = Container.get(UserConsentRepository); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await testDb.truncate(['OAuthClient', 'UserConsent']); | ||
| }); | ||
|
|
||
| describe('DELETE /rest/mcp/oauth-clients/:clientId', () => { | ||
| test('should allow a user to delete their own OAuth client', async () => { | ||
| const client = await oauthClientRepository.save({ | ||
| id: 'owner-client-id', | ||
| name: 'Owner Client', | ||
| redirectUris: ['https://example.com/callback'], | ||
| grantTypes: ['authorization_code'], | ||
| tokenEndpointAuthMethod: 'none', | ||
| }); | ||
|
|
||
| await userConsentRepository.save({ | ||
| userId: owner.id, | ||
| clientId: client.id, | ||
| grantedAt: Date.now(), | ||
| }); | ||
|
|
||
| const response = await testServer.authAgentFor(owner).delete(`/mcp/oauth-clients/${client.id}`); | ||
|
|
||
| expect(response.statusCode).toBe(200); | ||
| expect(response.body.data).toMatchObject({ | ||
| success: true, | ||
| }); | ||
|
|
||
| const deletedClient = await oauthClientRepository.findOneBy({ id: client.id }); | ||
| expect(deletedClient).toBeNull(); | ||
| }); | ||
|
|
||
| test("should return 404 when a user tries to delete another user's OAuth client", async () => { | ||
| const client = await oauthClientRepository.save({ | ||
| id: 'owner-only-client', | ||
| name: 'Owner Only Client', | ||
| redirectUris: ['https://example.com/callback'], | ||
| grantTypes: ['authorization_code'], | ||
| tokenEndpointAuthMethod: 'none', | ||
| }); | ||
|
|
||
| await userConsentRepository.save({ | ||
| userId: owner.id, | ||
| clientId: client.id, | ||
| grantedAt: Date.now(), | ||
| }); | ||
|
|
||
| const response = await testServer | ||
| .authAgentFor(member) | ||
| .delete(`/mcp/oauth-clients/${client.id}`); | ||
|
|
||
| expect(response.statusCode).toBe(404); | ||
|
|
||
| // Verify the client was NOT deleted | ||
| const existingClient = await oauthClientRepository.findOneBy({ id: client.id }); | ||
| expect(existingClient).not.toBeNull(); | ||
| }); | ||
|
|
||
| test('should return 404 when deleting a non-existent OAuth client', async () => { | ||
| const response = await testServer | ||
| .authAgentFor(owner) | ||
| .delete('/mcp/oauth-clients/non-existent-id'); | ||
|
|
||
| expect(response.statusCode).toBe(404); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: The new delete authorization checks consent instead of client ownership, so a non-owner user with consent to the same
clientIdcan still delete the shared OAuth client.According to linked Linear issue ADO-5000, this does not fully satisfy the required ownership check for cross-user deletion prevention.
Prompt for AI agents