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.
  
    
  
    
Version: 0.7.2
CVSS: 3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Score: 8.8 (High)
Description
An RCE vulnerability exists in the
ConversableAgentclass through Server-Side Template Injection (SSTI) in Jinja2 template rendering. The vulnerability allows authenticated attackers to execute arbitrary Python code on the server by injecting malicious template expressions into AgentMessage context parameters.The vulnerability stems from the complete lack of input validation in the agent message processing pipeline. User-controlled data from HTTP requests flows directly through the
ext_infoparameter intoAgentMessage.context, which is subsequently merged into Jinja2 template parameters without sanitization. When agents use custom bind_prompt templates with jinja2 format, the malicious template expressions are rendered with full Python execution capabilities.The
ConversableAgentclass is the foundation for all agents and is exposed through multiple HTTP API endpoints, making this vulnerability remotely exploitable in all DB-GPT installations that use agent chat functionality.Source - Sink Analysis
Source: User-controlled
ext_infodictionary in HTTP requests to agent chat endpointsCall Chain:
/v1/chat/completionswith maliciousext_infoin request bodychat_completions()function inpackages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py:501multi_agents.app_agent_chat()inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py:409agent_chat_v2()function inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py:163user_chat_2_app()function inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/app_agent_manage.py:66user_proxy.initiate_chat()inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:686with**ext_infopassed ascontextAgentMessage(context=context)created with user-controlled data inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:700ConversableAgent.receive()→generate_reply()inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:319_load_thinking_messages()inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:1084withcontext=reply_message.get_dict_context()build_system_prompt()inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:1048merges context intoprompt_paramTemplate(self.bind_prompt.template).render(prompt_param)inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:1068Proof of Concept
Impact
cc: @fangyinc @Aries-ckt