mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
@@ -58,6 +58,7 @@ import { CachePool } from './CachePool'
|
||||
import { ICommonObject, IMessage, INodeOptionsValue } from 'flowise-components'
|
||||
import { createRateLimiter, getRateLimiter, initializeRateLimiter } from './utils/rateLimit'
|
||||
import { addAPIKey, compareKeys, deleteAPIKey, getApiKey, getAPIKeys, updateAPIKey } from './utils/apiKey'
|
||||
import { sanitizeMiddleware } from './utils/XSS'
|
||||
import axios from 'axios'
|
||||
import { Client } from 'langchainhub'
|
||||
import { parsePrompt } from './utils/hub'
|
||||
@@ -118,9 +119,15 @@ export class App {
|
||||
// Allow access from *
|
||||
this.app.use(cors())
|
||||
|
||||
// Switch off the default 'X-Powered-By: Express' header
|
||||
this.app.disable('x-powered-by')
|
||||
|
||||
// Add the expressRequestLogger middleware to log all requests
|
||||
this.app.use(expressRequestLogger)
|
||||
|
||||
// Add the sanitizeMiddleware to guard against XSS
|
||||
this.app.use(sanitizeMiddleware)
|
||||
|
||||
if (process.env.FLOWISE_USERNAME && process.env.FLOWISE_PASSWORD) {
|
||||
const username = process.env.FLOWISE_USERNAME
|
||||
const password = process.env.FLOWISE_PASSWORD
|
||||
@@ -967,6 +974,12 @@ export class App {
|
||||
// Download file from assistant
|
||||
this.app.post('/api/v1/openai-assistants-file', async (req: Request, res: Response) => {
|
||||
const filePath = path.join(getUserHome(), '.flowise', 'openai-assistant', req.body.fileName)
|
||||
//raise error if file path is not absolute
|
||||
if (!path.isAbsolute(filePath)) return res.status(500).send(`Invalid file path`)
|
||||
//raise error if file path contains '..'
|
||||
if (filePath.includes('..')) return res.status(500).send(`Invalid file path`)
|
||||
//only return from the .flowise openai-assistant folder
|
||||
if (!(filePath.includes('.flowise') && filePath.includes('openai-assistant'))) return res.status(500).send(`Invalid file path`)
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=' + path.basename(filePath))
|
||||
const fileStream = fs.createReadStream(filePath)
|
||||
fileStream.pipe(res)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Request, Response, NextFunction } from 'express'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
|
||||
export function sanitizeMiddleware(req: Request, res: Response, next: NextFunction): void {
|
||||
// decoding is necessary as the url is encoded by the browser
|
||||
const decodedURI = decodeURI(req.url)
|
||||
req.url = sanitizeHtml(decodedURI)
|
||||
for (let p in req.query) {
|
||||
req.query[p] = sanitizeHtml(req.query[p] as string)
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
Reference in New Issue
Block a user