Closed toi500 closed 1 week ago
@HenryHengZJ, our friend @saatchi-david gave me a good idea tonight when we were talking on Discord.
We could extend the proxy to support multiple chatflows for the same deployment. I think that the easiest way to do this is by adding a CHATFLOWS JSON configuration:
Backend (.env):
CHATFLOWS={
"default": "ce158a4f-989f-467b-9a9f4-d0f3f7def6b7, *",
"support": "f5d84d3a-2c72-4853-8574-37a4a87dd5c4, www.support-site.com",
"sales": "89b7e421-9f3a-4669-8a6f-9b7d3e31739c, www.sales-site.com"
}
Frontend:
<script type="module">
import Chatbot from './web.js'
// Support chatflow
Chatbot.init({
chatflowid: 'support/proxy', // Uses support flow
apiHost: 'http://localhost:3000'
})
</script>
(Cross-posting from Discord) That's exactly the functionality I was hoping for. Awesome. Would be awesome to see something like that more baked into flowise, potentially as an addition to the "Allowed Domains" interface. Or maybe more appropriate to replace that tab with a "security" tab where users could specify allowed domains and toggle the proxy functionality.
On a related note, Henry mentioned exploring adding more control/security for the config overrides. Just thinking out loud, but I could imagine the security tab including a toggle to disable the config overrides as well.
Taking that a step further... it would be awesome if we could specify defaults for each of the config options from within flowise, preventing the need to handle so much with the embed. Then from flowise, have the overrides disabled by default, and have the option to enable specific ones as needed.
This would consolidate configuration to the flowise interface, simplifying setup by reducing the need to update code, and by default create a more secure setup. Then if users need to control something via override, they can enable only what they need, e.g. maybe only the session ID, and not have the risk of things like prompt and model being overridden by the user.
-- off topic --
@saatchi-david, I don't want to go off-topic too much here, but I agree 100%. The overrideConfig limitation is definitely something they are already cooking, and I think it is a brilliant idea. It will reduce the risk of hijacking a lot. It would be much less attractive to mess around with other people's flows. And I really hope they bring back together Flowise and the Embed Chatbot in the future for Flowise Cloud for an effective proxy implementation you just described. Not a easy task though.
--
In relation to this PR and my last comment, I think it makes sense to have just one deployment to manage multiple embedded chatbots from different flows.
@saatchi-david @HenryHengZJ I've added the multi-flow feature. I managed to do it entirely through.env
configuration, so all variables are in one place. All of this is built on top of the current implementation, and no changes are needed in the FlowiseAI repository.
This approach is much better. Testing it now.
thank you! let me know when its ready to review
@HenryHengZJ I have removed the legacy /proxy
sufix (from the original single-flow implementation) and now it is ready to review.
@HenryHengZJ I have made the requested changes. Please review.
Enhanced Chatflow Management and Security in Embed Server
This PR introduces significant improvements to chatflow management, security, and developer experience, making it easier to configure and deploy secure embedded chatbots.
Easy Flow Management with Environment Variables:
CHATFLOWS
environment variable with a more flexible and scalableCHATFLOW_X
format. Each chatflow is now configured with its own environment variable, making it easier to add, remove, or modify individual chatflows without affecting others. Example:CHATFLOW_X
variable has the correct format and includes a valid chatflow ID and allowed domains.*
) in chatflow configurations to enforce explicit domain whitelisting and enhance security. Attempts to use wildcards will result in an error message, and the affected chatflow will be disabled.Enhanced
web.js
Access Control:web.js
embed script. The script will only be served to requests originating from allowed domains defined in theCHATFLOW_X
configurations. This prevents unauthorized use of the embed script.Improved Documentation:
README.md
file with the following information:CHATFLOW_X
environment variable format and configuration options.index.html
: Refreshed theindex.html
file with the latest embed script examples, demonstrating the new configuration options and best practices.Embed Script Display Utility:
Strengthened Server Security:
validateApiKey
middleware, ensuring that requests originate from legitimate browsers and further mitigating potential security risks.CHATFLOW_X
environment variables.