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
ConversableAgent
class 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_info
parameter 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
ConversableAgent
class 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_info
dictionary in HTTP requests to agent chat endpointsCall Chain:
/v1/chat/completions
with maliciousext_info
in request bodychat_completions()
function inpackages/dbgpt-app/src/dbgpt_app/openapi/api_v1/api_v1.py:501
multi_agents.app_agent_chat()
inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py:409
agent_chat_v2()
function inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py:163
user_chat_2_app()
function inpackages/dbgpt-serve/src/dbgpt_serve/agent/agents/app_agent_manage.py:66
user_proxy.initiate_chat()
inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:686
with**ext_info
passed ascontext
AgentMessage(context=context)
created with user-controlled data inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:700
ConversableAgent.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:1084
withcontext=reply_message.get_dict_context()
build_system_prompt()
inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:1048
merges context intoprompt_param
Template(self.bind_prompt.template).render(prompt_param)
inpackages/dbgpt-core/src/dbgpt/agent/core/base_agent.py:1068
Proof of Concept
Impact
cc: @fangyinc @Aries-ckt