Skip to content

Commit 87504d7

Browse files
waleedlatif1claude
andcommitted
fix(mcp): compare decrypted plaintext for OAuth client secret change
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 78cbbec commit 87504d7

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • apps/sim/app/api/mcp/servers/[id]

apps/sim/app/api/mcp/servers/[id]/route.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { toError } from '@sim/utils/errors'
66
import { and, eq, isNull } from 'drizzle-orm'
77
import type { NextRequest } from 'next/server'
88
import { updateMcpServerBodySchema } from '@/lib/api/contracts/mcp'
9-
import { encryptSecret } from '@/lib/core/security/encryption'
9+
import { decryptSecret, encryptSecret } from '@/lib/core/security/encryption'
1010
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1111
import {
1212
McpDnsResolutionError,
@@ -140,11 +140,18 @@ export const PATCH = withRouteHandler(
140140
const urlChanged = body.url !== undefined && currentServer?.url !== body.url
141141
const clientIdChanged =
142142
body.oauthClientId !== undefined && currentServer?.oauthClientId !== body.oauthClientId
143-
const clientSecretChanged =
144-
oauthClientSecret !== undefined &&
145-
(oauthClientSecret
146-
? finalUpdateData.oauthClientSecret !== currentServer?.oauthClientSecret
147-
: currentServer?.oauthClientSecret !== null)
143+
let clientSecretChanged = false
144+
if (oauthClientSecret !== undefined) {
145+
if (!oauthClientSecret) {
146+
clientSecretChanged = currentServer?.oauthClientSecret != null
147+
} else if (!currentServer?.oauthClientSecret) {
148+
clientSecretChanged = true
149+
} else {
150+
const currentPlaintext = (await decryptSecret(currentServer.oauthClientSecret))
151+
.decrypted
152+
clientSecretChanged = currentPlaintext !== oauthClientSecret
153+
}
154+
}
148155
const oauthCredsChanged = clientIdChanged || clientSecretChanged
149156

150157
if (urlChanged || oauthCredsChanged) {

0 commit comments

Comments
 (0)