Skip to content

fix: robustness against malformed SIP headers, deep JSON and broken files - #244

Merged
lollox80 merged 11 commits into
mainfrom
fix/input-robustness
Dec 3, 2026
Merged

lollox80 merged 11 commits into
mainfrom
fix/input-robustness

Conversation

@lollox80

@lollox80 lollox80 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

What and why

Small robustness fixes for malformed or unusual input, each with a test that fails without it. None changes behaviour with the messages and files real plants produce today; they stop a bad input from crashing a handler, dropping a client or logging errors in a loop.

  • SIP: _host_of no longer raises IndexError on an empty Via (it made _dialog_hosts fail on every packet from a host other than the proxy, each with an ERROR log and a 2 s pause); it returns the bare address of an IPv6 reference (sip:[fe80::1]:5060); _parse reads the compact header names of RFC 3261 7.3.3 (v, f, t, i, m, l...).
  • /audio_ws: valid JSON that is not an object, JSON nested too deep and an action that is not a string are ignored like invalid JSON, instead of dropping the client.
  • JSON nested too deep ("[" * 100000, where json.loads raises RecursionError, not ValueError): a RestError in the REST client, actuators_bad_json in the options flow, an empty ring log.
  • HomeKit: a setup-code file that is not a JSON object gets a new code, like any other broken file.
  • Rubrica import: a rubrica.db on a Windows UNC path opens (file:////server/share/...), in the importer and in tools/parse_rubrica.py.

Tested on

Tests only: python -m pytest tests -m "not live and not media and not browser and not docker" (2531 passed, 32 skipped) and ruff check . clean, on Windows.

Docs

Docs: not needed (no user-facing change for valid input).

Changelog

Changelog: Bug fixes - A malformed message from the network or a broken file no longer drops the card's audio connection or stops the SIP reader
Changelog: Bug fixes - The phonebook import opens a rubrica.db on a network share (UNC path)
Changelog: Other changes - Robustness fixes for malformed SIP headers, JSON nested too deep and broken HomeKit setup-code files, with tests

🤖 Generated with Claude Code

lollox80 and others added 11 commits December 3, 2026 00:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
json.loads raises RecursionError, not a ValueError, on a text such as
"[" * 100000: it left _handle_text, the socket loop caught it and
dropped the client. It is now ignored like any other invalid JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
json.loads raises RecursionError, not ValueError, on input such as
"[" * 100000. _parse_actuators let it escape, so the options step failed
with a generic error instead of showing actuators_bad_json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"sip:[fe80::1]:5060" gave "[fe80::1]:5060", which never matches the
sender address a socket reports. Today the local UDP socket is IPv4 only,
so nothing changes for current plants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Windows UNC path became file://server/share/..., where SQLite reads the
server as the URI authority and refuses it. An empty authority in front
(file:////server/share/...) keeps the whole path. Same fix in the importer
and in tools/parse_rubrica.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
{"action": [...]} made `action in ADMIN_WS_ACTIONS` (a set) raise TypeError
outside the action's try: the socket loop caught it and dropped the client,
the same failure as JSON that is not an object (fixed above).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
json.load raises RecursionError, not ValueError, on "[[[[...": the docstring
promises that a broken file stops nothing. Same case as the REST client and the options flow above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…code

"[]", "5" or a bare string made json.load(f)["pincode"] raise TypeError, and
deep nesting RecursionError: neither was caught, so the code file did not
fall back to a new code like any other broken file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RFC 3261 7.3.3: a UA must accept the short form of a header name. A message with v:/i:/m: was parsed with no Via, Call-ID or Contact, so the reply carried an empty Via and _dialog_hosts missed the Via host. _split_stream already accepted l: for Content-Length. Vimar plants have only been seen sending the long form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lollox80
lollox80 added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit 6fdbe87 Dec 3, 2026
7 checks passed
@lollox80
lollox80 deleted the fix/input-robustness branch December 3, 2026 00:05
@lollox80 lollox80 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant