Repository navigation
fix(rest): gate editor WebSockets with bearer, cookie and Origin (R-52, S-32) - #29
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/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