I have developed a chatbot widget that can be integrated into any website by hosting it and embedding it in an iframe. I have also built a REST API using Flask and deployed it on Google Cloud Run. The front-end widget communicates with the API by sending requests that contain the user query, the session ID, and the website domain where the iframe is embedded. The API responds with the chatbot output.
However, I am facing a security issue. The API URL is visible in the client-side code, and the API allows unauthenticated invocations. How can I secure the API so that only my widget can access it? How can I prevent unauthorized calls to the API without asking visitors to login or provide any credentials?
Hello,
I don't think this is related to cloud run functionnality.
Each web site should have his own api key build in the iframe src. Than handle the api key in your code.
Take a look on how google map allow iframe for dev with a api key.
Have fun.
See my response to a related question