Skip to content

Redact the MAC in the reservations unsubscribe warning - #127

Merged
eman merged 2 commits into
mainfrom
fix/redact-mac-in-reservations-warning
Sep 1, 2026
Merged

Redact the MAC in the reservations unsubscribe warning#127
eman merged 2 commits into
mainfrom
fix/redact-mac-in-reservations-warning

Conversation

@eman

@eman eman commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Problem

fetch_reservations logged device_info.mac_address in the clear when its cleanup unsubscribe raised:

except Exception:
    _logger.warning(
        "Failed to unsubscribe reservations response handler for device %s",
        device.device_info.mac_address,   # unredacted
        exc_info=True,
    )

The identical warning in update_reservations_confirmed, seventy lines below in the same file, already passes the value through redact_mac. This call site was simply missed.

CodeQL has flagged it as py/clear-text-logging-sensitive-data (high severity) since 2026-07-23, and it shipped in 9.3.1.

Fix

Both call sites now redact. The function-local from .mqtt.utils import redact_mac matches the sibling and the three other call sites in the package (tou_schedule.py, device_info_cache.py, mqtt/client.py), all of which import it inside the function rather than at module scope.

I grepped for other unredacted mac_address/device_mac values reaching a logger — this was the only one.

Tests

test_fetch_reservations_redacts_mac_when_unsubscribe_fails drives the cleanup path with a failing unsubscribe and asserts the MAC does not appear in the emitted warning. Verified it fails against the unredacted version and passes with the fix. Full suite: 736 passed.

https://claude.ai/code/session_01XVj9BYvuLj7Th3iFUVoeCn

fetch_reservations logged device_info.mac_address in the clear when its
cleanup unsubscribe raised. The identical warning in
update_reservations_confirmed, seventy lines below, already passed the
value through redact_mac - this call site was simply missed.

CodeQL has flagged it as py/clear-text-logging-sensitive-data (high)
since 2026-07-23; it shipped in 9.3.1.

The local `from .mqtt.utils import redact_mac` matches the sibling and
the three other call sites in the package, which import it inside the
function rather than at module scope.

A test drives the cleanup path with a failing unsubscribe and asserts
the MAC does not appear in the emitted warning; it fails against the
unredacted version.

Claude-Session: https://claude.ai/code/session_01XVj9BYvuLj7Th3iFUVoeCn

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, consistent with existing redaction patterns in the codebase, and includes a targeted regression test.

Pull request overview

This PR addresses a security logging issue in the reservations helpers by ensuring device MAC addresses are redacted in a warning emitted when an unsubscribe cleanup step fails. It aligns fetch_reservations with the already-redacting behavior in update_reservations_confirmed and adds a regression test to prevent reintroducing clear-text MAC logging.

Changes:

  • Redact device.device_info.mac_address in the fetch_reservations unsubscribe-failure warning (matching the existing redaction in update_reservations_confirmed).
  • Add a unit test that forces the unsubscribe failure path and asserts the clear-text MAC does not appear in the warning output.
  • Document the security fix in the Unreleased changelog.
File summaries
File Description
src/nwp500/reservations.py Redacts MAC address in the unsubscribe failure warning in fetch_reservations.
tests/test_reservations.py Adds regression coverage ensuring clear-text MAC is not logged when unsubscribe fails.
CHANGELOG.rst Notes the security-related logging redaction fix under Unreleased.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ervations-warning

# Conflicts:
#	CHANGELOG.rst
@eman
eman merged commit a6d62fe into main Sep 1, 2026
7 checks passed
@eman
eman deleted the fix/redact-mac-in-reservations-warning branch September 1, 2026 13:24
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