Skip to content

Commit f174afd

Browse files
author
christopherholland-workday
committed
Stop text-to-speach endpoint from accepting arbitrary creds
1 parent 4d857f8 commit f174afd

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/components/cookies.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Netscape HTTP Cookie File
2+
# https://curl.se/docs/http-cookies.html
3+
# This file was generated by libcurl! Edit at your own risk.
4+
5+
#HttpOnly_localhost FALSE / FALSE 0 connect.sid s%3Acwjbi1guxLcnar0s1aVCP5bMBvSsyX4f.VHFJfS8WHyPbC2xM8Src7AU9MAB2kF15w%2F%2FY7G2wwIc
6+
#HttpOnly_localhost FALSE / FALSE 0 refreshToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAwZDQxNjQ2LTk1YmYtNDM4ZS1iZGE2LWU3ZjlkY2QyZjcxZSIsInVzZXJuYW1lIjoiQ2hyaXMgQWRtaW4iLCJtZXRhIjoiMDdjNzAwNGU2NzQ5OTYyN2YyNzVmY2FkNzBlMDZmMTg6MTlmODhjNTQzNjNmZWRjODljYjQ1MmVkZTYzN2E5ODliMDRlY2JiNDFkYzFjZTY2ZGM3YzMzNjk0MzAxYmM5MzQ2YzEzZjdiYjk5ZGI1YmFkYmY0NGM1ZTI2M2NhYzAzMTY0NjAxYWQ0YTk4NWM0OGM2YWVmMTAxOTZmN2JkOGYxYmEzMzg2NzkzODg4NDI4YjBiNDEwOGMxZTY2OTliNiIsImlhdCI6MTc3MjY1MTAzNCwibmJmIjoxNzcyNjUxMDM0LCJleHAiOjE3NzUyNDMwMzQsImF1ZCI6IkZsb3dpc2UiLCJpc3MiOiJGbG93aXNlIn0.8CVAjXXGxskieocmhfVt6mvD0hgiToketbQI2q6_vAs
7+
#HttpOnly_localhost FALSE / FALSE 0 token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjAwZDQxNjQ2LTk1YmYtNDM4ZS1iZGE2LWU3ZjlkY2QyZjcxZSIsInVzZXJuYW1lIjoiQ2hyaXMgQWRtaW4iLCJtZXRhIjoiZmRjYjM4MWIxMTVjMzI1Zjc1MTBlYzE5YzdjYjM4Y2U6OTI0ZDg2YjRjMjllNTdjNDVmODYxOTNmNmVmNDQxMDEyNDkzYjhiMDkzNTZjYjY1YTJiY2RjNWZiMGJjMDMzOGJhZmNiZTUxN2I4MGNiZDg4ZjRmZGU3MWYxNjY2N2ExMjViOWJlMDE4NDIyYmMxYTAwMTVhYjNmZjQ4YjEwZWNlOGI2OGJjZmVhZjdlMjlmZGQ4OTRjYjAzMmYyMDEyMiIsImlhdCI6MTc3MjY1MTAzNCwibmJmIjoxNzcyNjUxMDM0LCJleHAiOjE3NzI2NzI2MzQsImF1ZCI6IkZsb3dpc2UiLCJpc3MiOiJGbG93aXNlIn0.rxhXXvWeTf8S3ggIpApR6NnHOK-ZyW_fJE3qAYxGb3c

packages/server/src/controllers/text-to-speech/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { convertTextToSpeechStream } from 'flowise-components'
33
import { StatusCodes } from 'http-status-codes'
44
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
55
import chatflowsService from '../../services/chatflows'
6+
import credentialsService from '../../services/credentials'
67
import textToSpeechService from '../../services/text-to-speech'
78
import { databaseEntities } from '../../utils'
89
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
@@ -56,6 +57,17 @@ const generateTextToSpeech = async (req: Request, res: Response) => {
5657
voice = providerConfig.voice
5758
model = providerConfig.model
5859
} else {
60+
// Body-supplied credentials require the caller to be authenticated
61+
const workspaceId = req.user?.activeWorkspaceId
62+
if (!workspaceId) {
63+
return res.status(StatusCodes.UNAUTHORIZED).json({ message: 'Authentication required' })
64+
}
65+
if (!bodyCredentialId) {
66+
return res.status(StatusCodes.BAD_REQUEST).json({ message: 'credentialId not provided' })
67+
}
68+
// Verify the credential belongs to the authenticated user's workspace —
69+
// throws NOT_FOUND if the credential doesn't exist or belongs to another workspace
70+
await credentialsService.getCredentialById(bodyCredentialId, workspaceId)
5971
// Use TTS config from request body
6072
provider = bodyProvider
6173
credentialId = bodyCredentialId
@@ -80,8 +92,6 @@ const generateTextToSpeech = async (req: Request, res: Response) => {
8092
res.setHeader('Content-Type', 'text/event-stream')
8193
res.setHeader('Cache-Control', 'no-cache')
8294
res.setHeader('Connection', 'keep-alive')
83-
res.setHeader('Access-Control-Allow-Origin', '*')
84-
res.setHeader('Access-Control-Allow-Headers', 'Cache-Control')
8595

8696
const appServer = getRunningExpressApp()
8797
const options = {

0 commit comments

Comments
 (0)