Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/util/settings.py (Python)

Code before:
    websocket_server_port: int = Field(
        default=8001,
        description="The port for the websocket server to run on",
    )

    execution_manager_port: int = Field(
        default=8002,
        description="The port for execution manager daemon to run on",
    )

    execution_scheduler_port: int = Field(
        default=8003,
        description="The port for execution scheduler daemon to run on",
    )

    agent_server_port: int = Field(
        default=8004,
        description="The port for agent server daemon to run on",
    )

    agent_api_port: int = Field(
        default=8006,
        description="The port for agent server API to run on",
    )

    backend_cors_allow_origins: List[str] = []

    @field_validator("backend_cors_allow_origins")
    @classmethod
    def validate_cors_allow_origins(cls, v):
        out = []
        if isinstance(v, list):
            for url in v:
                url = url.strip()
                if url.startswith(("http://", "https://")):
                    out.append(url)
                else:
                    raise ValueError(f"Invalid URL: {url}")
        else:
            raise ValueError("backend_cors_allow_origins must be a valid url")

        # If using local callback add both localhost and 127.0.0.1
        # NOTE: Localhost does not use ssl
        has_localhost = any(["localhost" in url for url in out])
        has_127_0_0_1 = any(["127.0.0.1" in url for url in out])
        if has_127_0_0_1 and not has_localhost:
            out.append("http://localhost:3000")
        if has_localhost and not has_127_0_0_1:
            out.append("http://127.0.0.1:3000")

        return out

Review comment (suggestion):
```suggestion
    backend_cors_allow_origins: List[str] = Field(default_factory=list)
```
otherwise it becomes a shared object between all instances

Code after:
    websocket_server_host: str = Field(
        default="0.0.0.0",
        description="The host for the websocket server to run on",
    )

    websocket_server_port: int = Field(
        default=8001,
        description="The port for the websocket server to run on",
    )

    execution_manager_port: int = Field(
        default=8002,
        description="The port for execution manager daemon to run on",
    )

    execution_scheduler_port: int = Field(
        default=8003,
        description="The port for execution scheduler daemon to run on",
    )

    agent_server_port: int = Field(
        default=8004,
        description="The port for agent server daemon to run on",
    )

    agent_api_host: str = Field(
        default="0.0.0.0",
        description="The host for agent server API to run on",
    )

    agent_api_port: int = Field(
        default=8006,
        description="The port for agent server API to run on",
    )

    backend_cors_allow_origins: List[str] = Field(default_factory=list)

    @field_validator("backend_cors_allow_origins")
    @classmethod
    def validate_cors_allow_origins(cls, v: List[str]) -> List[str]:
        out = []
        port = None
        has_localhost = False
        has_127_0_0_1 = False
        for url in v:
            url = url.strip()
            if url.startswith(("http://", "https://")):
                if "localhost" in url:
                    port = url.split(":")[2]
                    has_localhost = True
                if "127.0.0.1" in url: