@@ -58,6 +58,7 @@ import { CachePool } from './CachePool'
5858import { ICommonObject , IMessage , INodeOptionsValue } from 'flowise-components'
5959import { createRateLimiter , getRateLimiter , initializeRateLimiter } from './utils/rateLimit'
6060import { addAPIKey , compareKeys , deleteAPIKey , getApiKey , getAPIKeys , updateAPIKey } from './utils/apiKey'
61+ import { sanitizeMiddleware } from './utils/XSS'
6162import axios from 'axios'
6263import { Client } from 'langchainhub'
6364import { parsePrompt } from './utils/hub'
@@ -118,9 +119,15 @@ export class App {
118119 // Allow access from *
119120 this . app . use ( cors ( ) )
120121
122+ // Switch off the default 'X-Powered-By: Express' header
123+ this . app . disable ( 'x-powered-by' )
124+
121125 // Add the expressRequestLogger middleware to log all requests
122126 this . app . use ( expressRequestLogger )
123127
128+ // Add the sanitizeMiddleware to guard against XSS
129+ this . app . use ( sanitizeMiddleware )
130+
124131 if ( process . env . FLOWISE_USERNAME && process . env . FLOWISE_PASSWORD ) {
125132 const username = process . env . FLOWISE_USERNAME
126133 const password = process . env . FLOWISE_PASSWORD
@@ -967,6 +974,12 @@ export class App {
967974 // Download file from assistant
968975 this . app . post ( '/api/v1/openai-assistants-file' , async ( req : Request , res : Response ) => {
969976 const filePath = path . join ( getUserHome ( ) , '.flowise' , 'openai-assistant' , req . body . fileName )
977+ //raise error if file path is not absolute
978+ if ( ! path . isAbsolute ( filePath ) ) return res . status ( 500 ) . send ( `Invalid file path` )
979+ //raise error if file path contains '..'
980+ if ( filePath . includes ( '..' ) ) return res . status ( 500 ) . send ( `Invalid file path` )
981+ //only return from the .flowise openai-assistant folder
982+ if ( ! ( filePath . includes ( '.flowise' ) && filePath . includes ( 'openai-assistant' ) ) ) return res . status ( 500 ) . send ( `Invalid file path` )
970983 res . setHeader ( 'Content-Disposition' , 'attachment; filename=' + path . basename ( filePath ) )
971984 const fileStream = fs . createReadStream ( filePath )
972985 fileStream . pipe ( res )
0 commit comments