Skip to content

fix(rest): gate editor WebSockets with bearer, cookie and Origin (R-52, S-32) - #29

Merged
TurkerMertkan merged 1 commit into
developfrom
s32-ws-auth
Nov 20, 2026
Merged

TurkerMertkan merged 1 commit into
developfrom
s32-ws-auth

Conversation

@TurkerMertkan

Copy link
Copy Markdown
Collaborator

/live, /api/rows and /live/sedonaState go through a pre-upgrade gate (bearer or sandstar_session cookie + Origin check). /api/ws SCRAM-only pre-auth hole closed. Behavior unchanged while auth is off.

Tests: auth_layer.rs 14. Gates: 2886 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC

…2, S-32)

Browsers cannot send an Authorization header on a WebSocket upgrade, so
/live, /api/rows and /live/sedonaState sat outside the auth layer while
carrying the same component writes as /api/sox/*.

- New check_upgrade_auth / require_upgrade_auth (rest/mod.rs), run
  before the upgrade. Accepts `Authorization: Bearer <token|session>`
  or the `sandstar_session` cookie (every same-name cookie is tried).
  With auth on, a browser Origin that is not the same host and not in
  --ws-allowed-origins gets 403; no or bad credential gets 401.
- POST /api/auth sets `sandstar_session` (HttpOnly, SameSite=Strict,
  Path=/) on SCRAM success. The JSON response is unchanged. No Secure
  flag: the device serves plain HTTP (R-14).
- /api/ws: a SCRAM-only setup no longer marks every connection as
  authenticated (was `(None, _) => true`). Origin check added; bearer
  comparisons are constant time. `?token=` still works for the legacy
  bearer only and logs a deprecation warning.
- New CLI/env --ws-allowed-origins / SANDSTAR_WS_ALLOWED_ORIGINS
  (default empty = same host only).

Routes: /live, /live/sedonaState, /api/rows now inside the upgrade auth
gate; /api/ws keeps its in-socket auth plus the new pre-auth; /api/auth
stays public; /roxwarp stays outside (R-54).

Behavior: unchanged while auth is not configured (field default). With
auth on, the Vue editor cannot connect until it logs in (S-32b).

Tests: tests/auth_layer.rs now 14 tests (401/403/101 matrix, cookie
attributes, SCRAM-only /api/ws); 5 of the new tests fail on the old
code. Gates: fmt, clippy, hal OK; test 27 suites, 2886 passed, 0 failed.

docs: OVERVIEW §3 route/auth table and HARDCODED_LIMITS (session
cookie, allowed origins) updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
@TurkerMertkan
TurkerMertkan merged commit 7fc1a9b into develop Nov 20, 2026
2 checks passed
@TurkerMertkan
TurkerMertkan deleted the s32-ws-auth branch November 20, 2026 20:51
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