(serverParams: any)
| 416 | * (see docker/.env.example, docker/worker/.env.example, packages/server/.env.example). |
| 417 | */ |
| 418 | export const validateMCPServerConfig = (serverParams: any): void => { |
| 419 | // Validate the entire server configuration |
| 420 | if (!serverParams || typeof serverParams !== 'object') { |
| 421 | throw new Error('Invalid server configuration') |
| 422 | } |
| 423 | |
| 424 | if (serverParams.cwd != null) { |
| 425 | throw new Error('cwd parameter is not allowed in MCP server configuration') |
| 426 | } |
| 427 | |
| 428 | // Command allowlist - operator-controlled via CUSTOM_MCP_ALLOWED_COMMANDS (empty = none allowed) |
| 429 | const allowedCommands = (process.env.CUSTOM_MCP_ALLOWED_COMMANDS ?? '') |
| 430 | .split(',') |
| 431 | .map((s) => s.trim()) |
| 432 | .filter(Boolean) |
| 433 | |
| 434 | if (serverParams.command && !allowedCommands.includes(serverParams.command)) { |
| 435 | throw new Error(`Command '${serverParams.command}' is not allowed. Permitted: ${allowedCommands.join(', ') || '(none)'}`) |
| 436 | } |
| 437 | |
| 438 | // Validate arguments if present |
| 439 | if (serverParams.args && Array.isArray(serverParams.args)) { |
| 440 | validateArgsForLocalFileAccess(serverParams.args) |
| 441 | validateCommandInjection(serverParams.args) |
| 442 | |
| 443 | // Validate command-specific dangerous flags |
| 444 | if (serverParams.command) { |
| 445 | validateCommandFlags(serverParams.command, serverParams.args) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Validate environment variables |
| 450 | if (serverParams.env) { |
| 451 | validateEnvironmentVariables(serverParams.env) |
| 452 | } |
| 453 | } |
no test coverage detected