# GHSA-Q2H7-XG5R-FJ2V: aegra dev --debug-host treats an empty host as localhost and binds debugpy to all interfaces without warning

- Database: GitHub
- Severity: low (stated by ghsa, no CVSS score)
- Published: 2026-11-19
- Modified: 2026-11-19

## Affected versions

- aegra-cli (PyPI): from 0.9.4, fixed in 0.12.0

## Description

### Summary

`aegra dev --debug-host` treats an empty string, or any other substring of `localhost`, as `localhost`. With `--debug-host ""` the CLI starts debugpy on all network interfaces and skips the non-loopback warning that is meant to stop exactly that.

### Details

In `libs/aegra-cli/src/aegra_cli/cli.py` (`dev`), a host that is not an IP address is checked with:

```python
except ValueError:
    if debug_host in ("localhost"):
        listen = f"{debug_host}:{debug_port}"
```

`("localhost")` is a string, not a tuple, so this is a substring test. `""`, `"local"`, `"host"` and other fragments pass it. They are forwarded to debugpy as given, `is_loopback` stays `True`, and neither the "Invalid debug host" fallback nor the "Debug Exposure Warning" panel is shown.

For `--debug-host ""` the command becomes `python -m debugpy --listen :5678 ...`. In debugpy 1.8.20 (the version in `uv.lock`), `server/cli.py` `set_address` splits that into `host=""` (the default localhost is only used when there is no `:`), the adapter is started with `--host ""`, and `common/sockets.create_server` only replaces `None`, so it calls `bind(("", 5678))`, which is `0.0.0.0`. An unauthenticated debug server on all interfaces allows remote code execution by anyone who can reach the port.

An empty value is easy to pass by accident, for example `aegra dev --debug-port 5678 --debug-host "$DEBUG_HOST"` with the variable unset.

### PoC

On `main` (9012768), with `subprocess.Popen` mocked as in `libs/aegra-cli/tests/test_cli.py`:

| `--debug-host` | `--listen` passed to debugpy | "Invalid debug host" | exposure warning |
|---|---|---|---|
| `""` | `:5678` | no | no |
| `host` | `host:5678` | no | no |
| `local` | `local:5678` | no | no |
| `not-a-valid-host` (for comparison) | `5678` | yes | no |

I did not start debugpy with an empty host on a network-facing machine; the all-interfaces bind follows from the debugpy source above and from `bind(("", port))` resolving to `0.0.0.0`.

### Fix

```diff
-                if debug_host in ("localhost"):
+                if debug_host == "localhost":
```

With this change, `""`, `local` and `host` get the "Invalid debug host specified" warning and debugpy falls back to `--listen 5678` (loopback). A parametrized regression test (`test_dev_with_partial_localhost_debug_host_warns_and_falls_back_to_loopback`) fails 3/3 on `main` and passes with the fix; the full `aegra-cli` suite passes (199 passed, 5 skipped) and ruff 0.16.1 is clean. The full patch with the test is below.

<details>
<summary>Patch (fix and regression test)</summary>

```diff
diff --git a/libs/aegra-cli/src/aegra_cli/cli.py b/libs/aegra-cli/src/aegra_cli/cli.py
index fab10e3..cb59f1f 100644
--- a/libs/aegra-cli/src/aegra_cli/cli.py
+++ b/libs/aegra-cli/src/aegra_cli/cli.py
@@ -442,7 +442,7 @@ def dev(
                     listen = f"[{debug_host}]:{debug_port}"
                 is_loopback = address.is_loopback
             except ValueError:
-                if debug_host in ("localhost"):
+                if debug_host == "localhost":
                     listen = f"{debug_host}:{debug_port}"
                 else:
                     console.print(
diff --git a/libs/aegra-cli/tests/test_cli.py b/libs/aegra-cli/tests/test_cli.py
index 0dc7b8b..0f4a8a0 100644
--- a/libs/aegra-cli/tests/test_cli.py
+++ b/libs/aegra-cli/tests/test_cli.py
@@ -466,6 +466,30 @@ class TestDevCommand:
                 assert call_args[listen_idx + 1] == "5678"
                 assert "not-a-valid-host:5678" not in " ".join(map(str, call_args))
 
+    @pytest.mark.parametrize("debug_host", ["", "local", "host"])
+    def test_dev_with_partial_localhost_debug_host_warns_and_falls_back_to_loopback(
+        self, cli_runner: CliRunner, tmp_path: Path, debug_host: str
+    ) -> None:
+        """Test that an empty host or a fragment of "localhost" is not treated as localhost."""
+        with cli_runner.isolated_filesystem(temp_dir=tmp_path):
+            Path("aegra.json").write_text('{"graphs": {}}')
+
+            with (
+                patch("importlib.util.find_spec", return_value=object()),
+                patch("aegra_cli.cli.subprocess.Popen") as mock_popen,
+            ):
+                mock_popen.return_value = create_mock_popen(0)
+                result = cli_runner.invoke(
+                    cli,
+                    ["dev", "--no-db-check", "--debug-port", "5678", "--debug-host", debug_host],
+                )
+
+                assert result.exit_code == 0
+                assert "Invalid debug host specified" in result.output
+                call_args = mock_popen.call_args[0][0]
+                listen_idx = call_args.index("--listen")
+                assert call_args[listen_idx + 1] == "5678"
+
     def test_dev_debug_host_non_loopback_warns(self, cli_runner: CliRunner, tmp_path: Path) -> None:
         """Test that using a non-loopback --debug-host prints a warning panel."""
         with cli_runner.isolated_filesystem(temp_dir=tmp_path):
```

</details>

### Impact

`aegra-cli` `dev` command with `--debug-port` and a `--debug-host` that is empty or a fragment of `localhost`. It needs the developer to pass such a value, so it is not remotely triggerable on its own, but when it happens the debug server is exposed without the warning the CLI is designed to show.

## References

- https://github.com/aegra/aegra/security/advisories/GHSA-q2h7-xg5r-fj2v

Page: https://cve.now/GHSA-Q2H7-XG5R-FJ2V

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
