DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

🚀 Feature: Agent API security improvements

Open pabik opened this issue 2 months ago • 13 comments

🔖 Feature description

This feature proposes the implementation of critical security and quality-of-life enhancements for the public-facing Agent API. As agents are designed to be embedded and shared, it's essential to provide users with robust tools to control access and prevent abuse.

I propose adding two key features to the agent configuration settings:

  1. CORS Origin Whitelisting: An option for users to specify a whitelist of allowed domains. This will ensure that the agent's API can only be called from trusted websites.
  2. API Limits: A mechanism to set limits on token usage (or maybe number of requests). This is crucial for protecting against denial-of-service (DoS) attacks and managing the costs associated with LLM calls.

🎤 Why is this feature needed ?

Currently, once an agent is made public, its API endpoint is open to the world. This poses significant risks for some users.

✌️ How do you aim to achieve this?

The implementation can be broken down into two parts, targeting the backend API and the frontend Agent Advanced section.

  1. CORS Origin Whitelisting:

Frontend:

  • In the Agent Advanced section, add a new text input field labeled "Allowed Origins". This field should accept a comma-separated list of URLs.

Backend:

  • Store the list of allowed origins in the database, associated with the specific agent.
  • In the API middleware that handles agent requests, check the incoming request's Origin header if enabled.
  1. API Limits

Frontend:

  • In the Agent Advanced section, add new text input field labeled "Usage limits"

Backend:

  • In the API middleware that handles agent requests, check usage before processing if enabled.

🔄️ Additional Information

No response

👀 Have you spent some time to check if this feature request has been raised before?

  • [x] I checked and didn't find similar issue

Are you willing to submit PR?

None

pabik avatar Sep 26 '25 17:09 pabik

Hey @pabik , I want to implement this. I will handle the backend part first but I am not sure about the frontend part. I will try that too after backend. Can you assign me this?

ardafincan avatar Sep 26 '25 19:09 ardafincan

Thank you, @ardafincan Assigned to you. In terms of frontend changes, try to hide the settings inside the advanced section please. If anything make a mock desing we will ask our UI designer to adjust it a bit later on.

dartpain avatar Sep 30 '25 08:09 dartpain

Can you please assign to me

ravi-hash avatar Oct 05 '25 14:10 ravi-hash

Hey, I have already implemented the api limiting part, the only remaining is whitelisting

ardafincan avatar Oct 05 '25 14:10 ardafincan

I had some confusion about the whitelisting part, but I guess I got it right now :D. I have such a squeezed schedule but I will try to implement it in 3-4 days max.

ardafincan avatar Oct 08 '25 08:10 ardafincan

Amazing, appreciate it a lot, thank you! Are you going to add changes to the existing PR or create a new one? I dont mind reviewing / merging current one then doing another review for second PR.

dartpain avatar Oct 08 '25 10:10 dartpain

It would be great if you review current one, so in need of any changes in that one I can work on that too along whitelist one.

ardafincan avatar Oct 08 '25 12:10 ardafincan

Hey @dartpain @pabik what do we want if request doesn't include Origin Header? I think that we should directly restrict its access if user has enabled origin whitelisting. Also do we always include the DocsGPT origin "https://app.docsgpt.cloud" in whitelist without user specifiying it or is it completely decision of user?

I am wondering your ideas about these.

ardafincan avatar Oct 08 '25 14:10 ardafincan

In terms of Origin Header check is think we need to include where fronted is deployed so yeah, "https://app.docsgpt.cloud/" would be great, if you can add "https://ent.docsgpt.cloud/" too - would be great, thank you!

dartpain avatar Oct 08 '25 17:10 dartpain

Hey @dartpain so I have made the changes you requested for the usage limiting PR and I have finished implementing the Origin whitelisting feature in a separate branch on the first one. So would you prefer merging the first one and me opening the second PR, or is it better if I combine two features in that existing PR and you review that?

ardafincan avatar Oct 12 '25 14:10 ardafincan

I merged the Pr if you can make second one now - would be great, thank you!

dartpain avatar Oct 13 '25 18:10 dartpain

Hey, I have opened the second one. Thank you, actually for maintaining such a great project!

ardafincan avatar Oct 13 '25 20:10 ardafincan

Thank you @ardafincan, appreciate your contributions!

dartpain avatar Oct 14 '25 14:10 dartpain