Skip to content

Enforce admin-only characteristic access - #538

Merged
ikalchev merged 10 commits into
ikalchev:devfrom
RaHehl:enforce-admin-only
Nov 10, 2026
Merged

ikalchev merged 10 commits into
ikalchev:devfrom
RaHehl:enforce-admin-only

Conversation

@RaHehl

@RaHehl RaHehl commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Builds on the catalog from #539, which marks Motion Enabled and Streaming Enabled with "AdminOnlyAccess": ["write"]. Nothing checked that property so far.

This PR enforces AdminOnlyAccess for writes. The HAP handler now passes the controller of the session to the write path. A write that contains a value, also null, to a characteristic whose AdminOnlyAccess contains "write" is refused with -70401 unless the controller is a paired admin. A call without a known controller is refused as well. The check runs before the pw and tw checks from #535 and #536, so a controller without the privilege learns nothing else about the characteristic. Writes without a value, i.e. event subscriptions, stay allowed. Admin rights are checked per request, so a controller that is demoted or removed is refused on its next write.

Reads, the accessory database and events are not restricted. No catalog characteristic restricts reads. Characteristics without the property behave as before, so existing accessories are not affected. The new client_uuid argument of set_characteristics is optional and keyword-only, so it can't be mixed up with client_addr.

AI use: written with the help of an AI coding assistant (Opus 5.5). I reviewed and tested the changes myself (pytest, ruff, ty).

Add the eight services and 27 characteristics of Apple's HomeKit Secure
Video Open Source Compatibility Guide (Developer Preview 1.0) to the
loader resources. Two of them, Contributing Sensors and Motion Enabled,
also become optional characteristics of the Motion Sensor service.

Timed write is advertised where the guide requires it. Writes to Motion
Enabled and Streaming Enabled are marked admin only with an
"AdminOnlyAccess": ["write"] catalog property. It is not part of the HAP
representation and not enforced yet.

Camera Recording Management keeps the characteristics classic recording
relies on.
Third Party Camera Active is state the camera reports, so controllers
read and subscribe to it but do not write it. Night Vision and Camera
Operating Mode Indicator are written with timed writes. The Camera
Global Operating Mode service of HKSV 17.99 uses all three. This
matches the definitions in HAP-NodeJS.
The catalog can mark a characteristic with "AdminOnlyAccess" (Motion
Enabled and Streaming Enabled list "write"), but nothing checked it.

Pass the controller of the session from the HAP handler to the driver
and refuse a write, or a read when the list contains "read", with
-70401 unless the controller is a paired admin. A request without a
known controller is refused too. This follows adminOnlyAccess in
HAP-NodeJS. Characteristics without the property are not affected.
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.73%. Comparing base (c83b472) to head (f1a182e).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #538      +/-   ##
==========================================
+ Coverage   91.71%   91.73%   +0.01%     
==========================================
  Files          27       27              
  Lines        4335     4342       +7     
  Branches      553      554       +1     
==========================================
+ Hits         3976     3983       +7     
  Misses        251      251              
  Partials      108      108              
Files with missing lines Coverage Δ
pyhap/accessory_driver.py 93.68% <100.00%> (+0.04%) ⬆️
pyhap/characteristic.py 97.89% <100.00%> (+0.01%) ⬆️
pyhap/hap_handler.py 86.23% <ø> (ø)
pyhap/state.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Conflicts:
#	pyhap/resources/characteristics.json
@RaHehl
RaHehl marked this pull request as ready for review November 10, 2026 13:13
ikalchev#535 adds client_addr as the second argument of get_characteristics,
so a positional client_uuid could end up as the address once both are
in. Also note why privileges are checked before availability.
The catalog tests came with the old catalog commits and are not about
admin-only access.
@ikalchev

Copy link
Copy Markdown
Owner

@RaHehl Can you resolve the merge conflicts here as well and in the other PRs?

# Conflicts:
#	pyhap/accessory_driver.py
#	pyhap/hap_handler.py
#	tests/test_loader.py
@RaHehl

RaHehl commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@ikalchev done

@ikalchev

Copy link
Copy Markdown
Owner

@RaHehl Conflicted again :/

# Conflicts:
#	pyhap/accessory_driver.py
#	pyhap/hap_handler.py
Also say in the catalog generator that the driver enforces admin-only
writes.
@RaHehl

RaHehl commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@ikalchev resolved again after #537 went in. I also narrowed it to writes: AdminOnlyAccess now only restricts writes, reads stay open, see the updated description.

@ikalchev
ikalchev merged commit cb774a6 into ikalchev:dev Nov 10, 2026
7 checks passed
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.

2 participants