The security vulnerability is a result of an insecure default CORS (Cross-Origin Resource Sharing) configuration in the Glances REST API server. The analysis of the provided patch commit 4465169b71d93991f1e49740fe02428291099832 confirms this. The vulnerable code is located in the __init__ method of the GlancesRestfulApi class in the file glances/outputs/glances_restful_api.py.
Previously, the CORSMiddleware was configured with allow_origins defaulting to ["*"] (all origins) and allow_credentials defaulting to True. While browsers typically block credentialed requests to a wildcard origin, the Starlette framework (used by FastAPI) has a feature that reflects the requesting Origin header in the Access-Control-Allow-Origin response header. This bypasses the browser's protection and allows any malicious website to make requests to the Glances API on behalf of an authenticated user, leading to the exfiltration of sensitive data.
The patch addresses this by changing the default value of cors_credentials to False and adding a specific check to prevent the combination of allow_origins=["*"] and allow_credentials=True. The GlancesRestfulApi.__init__ function is the entry point where this misconfiguration is applied, making it the vulnerable function. During runtime, this function is responsible for setting up the web server's middleware, and its flawed logic is what introduces the security risk.