π OpenHands: AI-Driven Development
fix(security): redact credentials from MCP config logging (#13720)
simonrosenbergb8f2932b0233
diff --git a/openhands/app_server/app_conversation/live_status_app_conversation_service.py b/openhands/app_server/app_conversation/live_status_app_conversation_service.pyindex 861e1152e4..3c2facf3be 100644--- a/openhands/app_server/app_conversation/live_status_app_conversation_service.py+++ b/openhands/app_server/app_conversation/live_status_app_conversation_service.py@@ -92,6 +92,7 @@ from openhands.sdk.llm import LLMfrom openhands.sdk.plugin import PluginSourcefrom openhands.sdk.secret import LookupSecret, SecretValue, StaticSecretfrom openhands.sdk.utils.paging import page_iterator+from openhands.sdk.utils.redact import sanitize_dictfrom openhands.sdk.workspace.remote.async_remote_workspace import AsyncRemoteWorkspacefrom openhands.server.types import AppModefrom openhands.storage.data_models.conversation_metadata import ConversationTrigger@@ -1108,7 +1109,7 @@ class LiveStatusAppConversationService(AppConversationServiceBase):# Wrap in the mcpServers structure required by the SDKmcp_config = {'mcpServers': mcp_servers} if mcp_servers else {}- _logger.info(f'Final MCP configuration: {mcp_config}')+ _logger.info(f'Final MCP configuration: {sanitize_dict(mcp_config)}')return llm, mcp_configdiff --git a/openhands/mcp/utils.py b/openhands/mcp/utils.pyindex cf6a8fca1d..df0e420a40 100644--- a/openhands/mcp/utils.py+++ b/openhands/mcp/utils.py@@ -24,6 +24,7 @@ from openhands.mcp.client import MCPClientfrom openhands.mcp.error_collector import mcp_error_collectorfrom openhands.runtime.base import Runtimefrom openhands.runtime.impl.cli.cli_runtime import CLIRuntime+from openhands.sdk.utils.redact import sanitize_dictdef convert_mcp_clients_to_tools(mcp_clients: list[MCPClient] | None) -> list[dict]:@@ -177,7 +178,9 @@ async def fetch_mcp_tools_from_config(mcp_clients = []mcp_tools = []try:- logger.debug(f'Creating MCP clients with config: {mcp_config}')+ logger.debug(+ f'Creating MCP clients with config: {sanitize_dict(mcp_config.model_dump())}'+ )# Create clients - this will fetch tools but not maintain active connectionsmcp_clients = await create_mcp_clients(diff --git a/openhands/server/session/session.py b/openhands/server/session/session.pyindex c8cb92bd74..aaeed22a23 100644--- a/openhands/server/session/session.py+++ b/openhands/server/session/session.py@@ -37,6 +37,7 @@ from openhands.events.serialization import event_from_dict, event_to_dictfrom openhands.events.stream import EventStreamSubscriberfrom openhands.llm.llm_registry import LLMRegistryfrom openhands.runtime.runtime_status import RuntimeStatus+from openhands.sdk.utils.redact import sanitize_dictfrom openhands.server.constants import ROOM_KEYfrom openhands.server.services.conversation_stats import ConversationStatsfrom openhands.server.session.agent_session import AgentSession@@ -184,7 +185,7 @@ class WebSession:# NOTE: this need to happen AFTER the config is updated with the search_api_keyself.logger.debug(- f'MCP configuration before setup - self.config.mcp_config: {self.config.mcp}'+ f'MCP configuration before setup - self.config.mcp_config: {sanitize_dict(self.config.mcp.model_dump())}')# Check if settings has custom mcp_config@@ -192,7 +193,9 @@ class WebSession:if mcp_config is not None:# Use the provided MCP SHTTP servers instead of default setupself.config.mcp = self.config.mcp.merge(mcp_config)- self.logger.debug(f'Merged custom MCP Config: {mcp_config}')+ self.logger.debug(+ f'Merged custom MCP Config: {sanitize_dict(mcp_config.model_dump())}'+ )# Add OpenHands' MCP server by default(@@ -209,7 +212,7 @@ class WebSession:self.config.mcp.stdio_servers.extend(openhands_mcp_stdio_servers)self.logger.debug(- f'MCP configuration after setup - self.config.mcp: {self.config.mcp}'+ f'MCP configuration after setup - self.config.mcp: {sanitize_dict(self.config.mcp.model_dump())}')# TODO: override other LLM config & agent config groups (#2075)