Skip to content

Warn when the peripheral API binds to a non-loopback address - #420

Open
sappafrancesco wants to merge 1 commit into
OHF-Voice:mainfrom
sappafrancesco:peripheral-api-bind-warning
Open

sappafrancesco wants to merge 1 commit into
OHF-Voice:mainfrom
sappafrancesco:peripheral-api-bind-warning

Conversation

@sappafrancesco

Copy link
Copy Markdown

Fixes #400.

The peripheral WebSocket API defaults to 0.0.0.0 and has no
authentication. That combination isn't flagged anywhere at runtime,
and docs/peripheral_api.md's "No authentication is required." reads
as a convenience note rather than a warning.

Per the issue discussion, keeping 0.0.0.0 as the default isn't
obviously wrong (some setups genuinely want to control LVA from
another device or container), so this doesn't change it. What it does:

  • Logs a warning at startup whenever --peripheral-host resolves to
    anything other than 127.0.0.1/::1/localhost, naming the
    concrete things an unauthenticated LAN client could do (mute/unmute
    the mic, start_listening to open a voice pipeline and stream
    captured audio to whatever conversation agent is configured, change
    the volume, register arbitrary entities) and pointing at
    --peripheral-host 127.0.0.1.
  • Expands the docs line to spell out what "no authentication" plus the
    0.0.0.0 default actually means, and how to opt out of it.

Type of change

  • Bugfix (non-breaking change which fixes an issue)

Testing

Added:

  • test_start_warns_on_non_loopback_host
  • test_start_does_not_warn_on_loopback_host (parametrized over
    127.0.0.1, ::1, localhost)
black --check / isort --check / flake8 / mypy / pylint -> clean
pytest tests/unit/test_peripheral_api.py -> 88 passed
pytest tests/ -> same 49 pre-existing failures in test_satellite.py as
  on main with this diff stashed out (an audio/OS-level test
  environment issue unrelated to and untouched by this change)

Fixes OHF-Voice#400.

The peripheral WebSocket API defaults to 0.0.0.0 and has no
authentication (documented and by design, per the linked issue's
discussion, the network-accessible case is intentional for people who
want to control LVA from another device or container). But nothing
told the operator that this combination means anyone on the LAN can
mute/unmute the mic, start a voice pipeline (streaming captured audio
to whatever conversation agent is configured), change the volume, or
register arbitrary entities into Home Assistant.

This doesn't change the default (that's a bigger, more opinionated
call than a warning, and the issue thread hasn't converged on it).
Instead:

- Logs a clear warning at startup whenever the peripheral API binds to
  anything other than 127.0.0.1/::1/localhost, naming the concrete
  commands an unauthenticated LAN client could send and pointing at
  `--peripheral-host 127.0.0.1`.
- Updates docs/peripheral_api.md's "No authentication is required"
  line, which read as a convenience note, with an explicit explanation
  of what that means combined with the 0.0.0.0 default.

Added test_start_warns_on_non_loopback_host and
test_start_does_not_warn_on_loopback_host (parametrized over
127.0.0.1/::1/localhost).

Checked:
```
black --check / isort --check / flake8 / mypy / pylint -> clean
pytest tests/unit/test_peripheral_api.py -> 88 passed
pytest tests/ -> same 49 pre-existing failures in test_satellite.py as
  on main with this diff stashed out (unrelated audio/OS-level test
  environment issue, not touched by this change)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Peripheral API binds 0.0.0.0 with no authentication by default

2 participants