fix: reject unknown websocket routes #10

Merged
exler merged 1 commit from fix/websocket-route-path into main 2026-11-26 13:45:24 +01:00
Collaborator

Summary

  • Reject unmatched WebSocket paths before acceptance, so Daphne returns HTTP 403 instead of an uncaught routing exception.
  • Keep the existing authenticated /ws/household/ route unchanged; scanner paths are not aliased.

Root cause

Channels URLRouter raises ValueError for unmatched paths. A final rejecting consumer turns those probes into normal handshake failures, leaving no exception for Sentry to capture.

Verification

  • env -u PYTHONPATH DJANGO_SECRET_KEY=x uv run python manage.py test — 58 tests passed after compiling the translation catalogs with gettext. The test run emitted one non-failing warning that the local staticfiles/ directory was absent.
  • Ruff check, Ruff format check, and git diff --check passed.
  • Actual local Daphne handshake for /websocket returned HTTP 403; there were zero unhandled-route error log lines and zero Sentry events captured by a local before_send callback with a dummy DSN. The callback dropped events locally; nothing was sent to external Sentry.

Risk

Only unknown WebSocket paths change. No database or deployment changes are included.

## Summary - Reject unmatched WebSocket paths before acceptance, so Daphne returns HTTP 403 instead of an uncaught routing exception. - Keep the existing authenticated `/ws/household/` route unchanged; scanner paths are not aliased. ## Root cause Channels `URLRouter` raises `ValueError` for unmatched paths. A final rejecting consumer turns those probes into normal handshake failures, leaving no exception for Sentry to capture. ## Verification - `env -u PYTHONPATH DJANGO_SECRET_KEY=x uv run python manage.py test` — 58 tests passed after compiling the translation catalogs with gettext. The test run emitted one non-failing warning that the local `staticfiles/` directory was absent. - Ruff check, Ruff format check, and `git diff --check` passed. - Actual local Daphne handshake for `/websocket` returned HTTP 403; there were zero unhandled-route error log lines and zero Sentry events captured by a local `before_send` callback with a dummy DSN. The callback dropped events locally; nothing was sent to external Sentry. ## Risk Only unknown WebSocket paths change. No database or deployment changes are included.
fix: reject unknown websocket routes
All checks were successful
CI / test (pull_request) Successful in 2m46s
CI / push (pull_request) Has been skipped
CI / test (push) Successful in 2m44s
CI / push (push) Successful in 29s
2d31b1d2ba
exler merged commit 2d31b1d2ba into main 2026-11-26 13:45:24 +01:00
exler deleted branch fix/websocket-route-path 2026-11-26 13:45:24 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
exler/hearth!10
No description provided.