AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(agent/security): Make CORS more restrictive and configurable
Reinier van der Leerce45c9b267d4
diff --git a/autogpts/autogpt/.env.template b/autogpts/autogpt/.env.templateindex 40590e4098..06539876e0 100644--- a/autogpts/autogpt/.env.template+++ b/autogpts/autogpt/.env.template@@ -232,6 +232,8 @@ OPENAI_API_KEY=your-openai-api-key### Agent Protocol Server Settings################################################################################## AP_SERVER_PORT - Specifies what port the agent protocol server will listen on. (Default: 8000)+## AP_SERVER_DB_URL - Specifies what connection url the agent protocol database will connect to (Default: Internal SQLite)+## AP_SERVER_CORS_ALLOWED_ORIGINS - Comma separated list of allowed origins for CORS. (Default: http://localhost:{AP_SERVER_PORT})# AP_SERVER_PORT=8000-# # AP_SERVER_DB_URL - Specifies what connection url the agent protocol database will connect to (Default: Internal SQLite)# AP_SERVER_DB_URL=sqlite:///data/ap_server.db+# AP_SERVER_CORS_ALLOWED_ORIGINS=diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.pyindex 9c5965ba04..7b778b7927 100644--- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py+++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py@@ -74,11 +74,14 @@ class AgentProtocolServer:version="v0.4",)- # Add CORS middleware- origins = [- "*",- # Add any other origins you want to whitelist+ # Configure CORS middleware+ default_origins = [f"http://localhost:{port}"] # Default only local access+ configured_origins = [+ origin+ for origin in os.getenv("AP_SERVER_CORS_ALLOWED_ORIGINS", "").split(",")+ if origin # Empty list if not configured]+ origins = configured_origins or default_originsapp.add_middleware(CORSMiddleware,