Skip to content

Commit e326bc8

Browse files
authored
Bugfix/Refactor createFileAttachment to streamline chatId validation (#4740)
Removed redundant chatId validation and path traversal checks, improving code clarity and maintainability. The chatId is now validated after the chatflowid check, ensuring proper error handling for invalid inputs.
1 parent e7553a1 commit e326bc8

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

packages/server/src/utils/createAttachment.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@ export const createFileAttachment = async (req: Request) => {
3030
if (!chatflowid || !isValidUUID(chatflowid)) {
3131
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Invalid chatflowId format - must be a valid UUID')
3232
}
33-
34-
const chatId = req.params.chatId
35-
if (!chatId || !isValidUUID(chatId)) {
36-
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Invalid chatId format - must be a valid UUID')
37-
}
38-
39-
// Check for path traversal attempts
40-
if (isPathTraversal(chatflowid) || isPathTraversal(chatId)) {
33+
if (isPathTraversal(chatflowid)) {
4134
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Invalid path characters detected')
4235
}
4336

37+
const chatId = req.params.chatId
38+
4439
// Validate chatflow exists and check API key
4540
const chatflow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({
4641
id: chatflowid

0 commit comments

Comments
 (0)