Skip to content

Commit 9b72b5c

Browse files
committed
fix(mcp): validate json headers, add domain check, fix empty api key header
1 parent e41fbcc commit 9b72b5c

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/mcp/mcp.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,14 @@ export function MCP({ initialServerId }: MCPProps) {
681681
return {
682682
name,
683683
url: config.url,
684-
headers: (config.headers as Record<string, string>) || {},
684+
headers:
685+
typeof config.headers === 'object' && config.headers !== null
686+
? Object.fromEntries(
687+
Object.entries(config.headers).filter(
688+
(entry): entry is [string, string] => typeof entry[1] === 'string'
689+
)
690+
)
691+
: {},
685692
}
686693
}
687694

@@ -690,7 +697,14 @@ export function MCP({ initialServerId }: MCPProps) {
690697
return {
691698
name: '',
692699
url: parsed.url,
693-
headers: (parsed.headers as Record<string, string>) || {},
700+
headers:
701+
typeof parsed.headers === 'object' && parsed.headers !== null
702+
? Object.fromEntries(
703+
Object.entries(parsed.headers).filter(
704+
(entry): entry is [string, string] => typeof entry[1] === 'string'
705+
)
706+
)
707+
: {},
694708
}
695709
}
696710

@@ -718,6 +732,11 @@ export function MCP({ initialServerId }: MCPProps) {
718732
return
719733
}
720734

735+
if (!isDomainAllowed(config.url, allowedMcpDomains)) {
736+
setJsonError('Domain not permitted by server policy')
737+
return
738+
}
739+
721740
setIsAddingServer(true)
722741
try {
723742
const serverConfig = {
@@ -758,7 +777,15 @@ export function MCP({ initialServerId }: MCPProps) {
758777
} finally {
759778
setIsAddingServer(false)
760779
}
761-
}, [jsonInput, parseJsonConfig, testConnection, createServerMutation, workspaceId, resetForm])
780+
}, [
781+
jsonInput,
782+
parseJsonConfig,
783+
testConnection,
784+
createServerMutation,
785+
workspaceId,
786+
resetForm,
787+
allowedMcpDomains,
788+
])
762789

763790
/**
764791
* Opens the delete confirmation dialog for an MCP server.
@@ -1620,6 +1647,10 @@ export function MCP({ initialServerId }: MCPProps) {
16201647
)
16211648
return
16221649
}
1650+
if (!isDomainAllowed(config.url, allowedMcpDomains)) {
1651+
setJsonError('Domain not permitted by server policy')
1652+
return
1653+
}
16231654
testConnection({
16241655
name: config.name,
16251656
transport: 'streamable-http',

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/workflow-mcp-servers/workflow-mcp-servers.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ function ServerDetailView({ workspaceId, serverId, onBack }: ServerDetailViewPro
480480
try {
481481
const headers: Record<string, string> = server.isPublic
482482
? {}
483-
: { 'X-API-Key': '' }
483+
: { 'X-API-Key': '{{SIM_API_KEY}}' }
484484
await addToWorkspaceMutation.mutateAsync({
485485
workspaceId,
486486
config: {
@@ -515,7 +515,7 @@ function ServerDetailView({ workspaceId, serverId, onBack }: ServerDetailViewPro
515515
</Button>
516516
{!server.isPublic && (
517517
<p className='text-[11px] text-[var(--text-muted)]'>
518-
After adding, set your API key in Settings &gt; MCP Tools, or{' '}
518+
Set the SIM_API_KEY environment variable, or{' '}
519519
<button
520520
type='button'
521521
onClick={() => setShowCreateApiKeyModal(true)}

0 commit comments

Comments
 (0)