The vulnerability exists because the /ajax-api endpoints of the MLflow Assistant were not protected against Cross-Site Request Forgery (CSRF) attacks due to improper CORS configuration. A malicious webpage could send requests to the locally running MLflow instance and execute commands.
The analysis of the patch 8f9c8a53af90842944101eb8b7d60706822c81bc reveals two key changes that fix the vulnerability:
-
mlflow.server.security_utils.is_api_endpoint: This function is used to determine if a given request path should be subject to API security checks, including CORS validation. Before the patch, this function only checked for paths starting with /api/. The new MLflow Assistant feature introduced endpoints under /ajax-api/, which were not covered. The patch extends the check to include /ajax-api/, ensuring these new endpoints are protected. The vulnerable version of this function failed to identify the new assistant endpoints, leaving them exposed.
-
mlflow.server.fastapi_security.init_fastapi_security: This function sets up the CORS middleware for the FastAPI application. The patch modifies this function to implement a stricter CORS policy. It introduces CORSBlockingMiddleware to block cross-origin requests by default and configures CORSMiddleware to only allow requests from localhost origins for the assistant endpoints. This prevents malicious websites from interacting with the local MLflow server. The previous configuration was too permissive.
Therefore, an exploit would involve a request to an /ajax-api endpoint, which would be processed by the middleware configured by init_fastapi_security, and the decision to apply the middleware would be based on the result of is_api_endpoint. These two functions are central to the vulnerability.