The vulnerability exists in both the WriteFileTool and ReadFileTool components of Flowise. The root cause is the lack of input validation on the file_path parameter provided by the user. In the vulnerable versions, these tools used the standard NodeFileStore from the langchain library, which does not perform any path sanitization or boundary checks. This allowed an authenticated attacker to craft a file_path that points to arbitrary locations on the server's filesystem, leading to arbitrary file write/read.
The exploitation of the WriteFileTool could lead to remote code execution by overwriting sensitive files like ~/.ssh/authorized_keys or application files like package.json.
The provided patch addresses this vulnerability by introducing a new SecureFileStore class. This class is now used by both WriteFileTool and ReadFileTool. The SecureFileStore enforces security policies by:
- Restricting file operations to a defined workspace directory.
- Validating file paths to prevent path traversal and the use of absolute paths.
- Checking for allowed file extensions and file sizes.
The vulnerable functions, WriteFileTool._call and ReadFileTool._call, would appear in a runtime profile or stack trace during exploitation, as they are the entry points that receive the malicious file path and trigger the insecure file operation.