Skip to content

Commit 75f431f

Browse files
0xi4odavehamptonusa
authored andcommitted
Fix: Disclosures (FlowiseAI#5562)
* fix: remove hostname from log filename * fix: remove metrics endpoint from whitelist and require authentication * update: example prometheus configuration * fix: require authentication for bullmq dashboard * remove: get-upload-path route * update: move export chat messages logic to backend * update: auth method for bullmq dashboard * fix: hard-coded api key in example prometheus config * fix: unused imports * fix: duplicated try-catch blocks * fix: add rate-limiting to bullmq dashboard * fix: add rate-limiting to bullmq dashboard * update: use existing json parse method
1 parent 54ed3d6 commit 75f431f

File tree

16 files changed

+315
-144
lines changed

16 files changed

+315
-144
lines changed

metrics/prometheus/prometheus.config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ scrape_configs:
66
- targets: ["localhost:8080","localhost:3000"]
77

88
metrics_path: /api/v1/metrics/
9-
scheme: http
9+
scheme: http
10+
11+
authorization:
12+
type: Bearer
13+
credentials_file: '/etc/prometheus/api_key.txt'

packages/server/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ JWT_REFRESH_TOKEN_EXPIRY_IN_MINUTES=43200
169169
# REDIS_KEEP_ALIVE=
170170
# ENABLE_BULLMQ_DASHBOARD=
171171

172-
173172
############################################################################################################
174173
############################################## SECURITY ####################################################
175174
############################################################################################################

packages/server/src/controllers/export-import/index.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,45 @@ const importData = async (req: Request, res: Response, next: NextFunction) => {
4949
}
5050
}
5151

52+
const exportChatflowMessages = async (req: Request, res: Response, next: NextFunction) => {
53+
try {
54+
const workspaceId = req.user?.activeWorkspaceId
55+
if (!workspaceId) {
56+
throw new InternalFlowiseError(
57+
StatusCodes.NOT_FOUND,
58+
`Error: exportImportController.exportChatflowMessages - workspace ${workspaceId} not found!`
59+
)
60+
}
61+
62+
const { chatflowId, chatType, feedbackType, startDate, endDate } = req.body
63+
if (!chatflowId) {
64+
throw new InternalFlowiseError(
65+
StatusCodes.BAD_REQUEST,
66+
'Error: exportImportController.exportChatflowMessages - chatflowId is required!'
67+
)
68+
}
69+
70+
const apiResponse = await exportImportService.exportChatflowMessages(
71+
chatflowId,
72+
chatType,
73+
feedbackType,
74+
startDate,
75+
endDate,
76+
workspaceId
77+
)
78+
79+
// Set headers for file download
80+
res.setHeader('Content-Type', 'application/json')
81+
res.setHeader('Content-Disposition', `attachment; filename="${chatflowId}-Message.json"`)
82+
83+
return res.json(apiResponse)
84+
} catch (error) {
85+
next(error)
86+
}
87+
}
88+
5289
export default {
5390
exportData,
54-
importData
91+
importData,
92+
exportChatflowMessages
5593
}

packages/server/src/controllers/get-upload-path/index.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/server/src/enterprise/middleware/passport/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,34 @@ export const verifyToken = (req: Request, res: Response, next: NextFunction) =>
429429
})(req, res, next)
430430
}
431431

432+
export const verifyTokenForBullMQDashboard = (req: Request, res: Response, next: NextFunction) => {
433+
passport.authenticate('jwt', { session: true }, (err: any, user: LoggedInUser, info: object) => {
434+
if (err) {
435+
return next(err)
436+
}
437+
438+
// @ts-ignore
439+
if (info && info.name === 'TokenExpiredError') {
440+
if (req.cookies && req.cookies.refreshToken) {
441+
return res.redirect('/signin?retry=true')
442+
}
443+
return res.redirect('/signin')
444+
}
445+
446+
if (!user) {
447+
return res.redirect('/signin')
448+
}
449+
450+
const identityManager = getRunningExpressApp().identityManager
451+
if (identityManager.isEnterprise() && !identityManager.isLicenseValid()) {
452+
return res.redirect('/license-expired')
453+
}
454+
455+
req.user = user
456+
next()
457+
})(req, res, next)
458+
}
459+
432460
const storeSSOUserPayload = (ssoToken: string, returnUser: any) => {
433461
const app = getRunningExpressApp()
434462
app.cachePool.addSSOTokenCache(ssoToken, returnUser)

packages/server/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Telemetry } from './utils/telemetry'
1818
import flowiseApiV1Router from './routes'
1919
import errorHandlerMiddleware from './middlewares/errors'
2020
import { WHITELIST_URLS } from './utils/constants'
21-
import { initializeJwtCookieMiddleware, verifyToken } from './enterprise/middleware/passport'
21+
import { initializeJwtCookieMiddleware, verifyToken, verifyTokenForBullMQDashboard } from './enterprise/middleware/passport'
2222
import { IdentityManager } from './IdentityManager'
2323
import { SSEStreamer } from './utils/SSEStreamer'
2424
import { validateAPIKey } from './utils/validateKey'
@@ -331,7 +331,17 @@ export class App {
331331
})
332332

333333
if (process.env.MODE === MODE.QUEUE && process.env.ENABLE_BULLMQ_DASHBOARD === 'true' && !this.identityManager.isCloud()) {
334-
this.app.use('/admin/queues', this.queueManager.getBullBoardRouter())
334+
// Initialize admin queues rate limiter
335+
const id = 'bullmq_admin_dashboard'
336+
await this.rateLimiterManager.addRateLimiter(
337+
id,
338+
60,
339+
100,
340+
process.env.ADMIN_RATE_LIMIT_MESSAGE || 'Too many requests to admin dashboard, please try again later.'
341+
)
342+
343+
const rateLimiter = this.rateLimiterManager.getRateLimiterById(id)
344+
this.app.use('/admin/queues', rateLimiter, verifyTokenForBullMQDashboard, this.queueManager.getBullBoardRouter())
335345
}
336346

337347
// ----------------------------------------

packages/server/src/routes/export-import/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const router = express.Router()
55

66
router.post('/export', checkPermission('workspace:export'), exportImportController.exportData)
77

8+
router.post('/chatflow-messages', checkPermission('workspace:export'), exportImportController.exportChatflowMessages)
9+
810
router.post('/import', checkPermission('workspace:import'), exportImportController.importData)
911

1012
export default router

packages/server/src/routes/get-upload-path/index.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/server/src/routes/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import fetchLinksRouter from './fetch-links'
1919
import filesRouter from './files'
2020
import flowConfigRouter from './flow-config'
2121
import getUploadFileRouter from './get-upload-file'
22-
import getUploadPathRouter from './get-upload-path'
2322
import internalChatmessagesRouter from './internal-chat-messages'
2423
import internalPredictionRouter from './internal-predictions'
2524
import leadsRouter from './leads'
@@ -93,7 +92,6 @@ router.use('/flow-config', flowConfigRouter)
9392
router.use('/internal-chatmessage', internalChatmessagesRouter)
9493
router.use('/internal-prediction', internalPredictionRouter)
9594
router.use('/get-upload-file', getUploadFileRouter)
96-
router.use('/get-upload-path', getUploadPathRouter)
9795
router.use('/leads', leadsRouter)
9896
router.use('/load-prompt', loadPromptRouter)
9997
router.use('/marketplaces', marketplacesRouter)

0 commit comments

Comments
 (0)