You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loopback dashboard CORS allows localhost origins, but token-protected /api/* preflight requests never reached CORSMiddleware. A cross-port localhost SPA that sends X-Hermes-Session-Token triggers OPTIONS /api/... first; browsers do not include that token on preflight, so the legacy dashboard token middleware returned 401 with no CORS headers and the real request was never sent.
Root Cause
auth_middleware wraps the earlier-registered CORSMiddleware in loopback mode. It treated tokenless CORS preflights exactly like real protected API calls, even though preflights are only asking whether the configured CORS policy allows the follow-up request.
Fix
Detect true browser CORS preflights (OPTIONS + Origin + Access-Control-Request-Method) in the loopback token gate and pass them through to CORSMiddleware. The actual follow-up request still has to carry X-Hermes-Session-Token or the legacy bearer token.
Same goal, different/refined mechanisms — related_to, not duplicate. A maintainer should pick between the reorder (#59072) and short-circuit approaches; this PR's true-preflight guard is the tightest short-circuit.
Thanks for the focused fix. Current main still registers CORSMiddleware at hermes_cli/web_server.py:299 before the later HTTP middleware decorators, while auth_middleware returns 401 for tokenless protected /api/ requests at hermes_cli/web_server.py:589-595. The reported loopback preflight path therefore remains affected.
Suggested changes
Consider adding a no-Origin regression case: OPTIONS plus Access-Control-Request-Method must still reach the token gate. The proposed _is_cors_preflight guard correctly requires both headers, but the added test currently covers only the allowed true-preflight case.
The change itself is narrowly scoped: it passes only real browser preflights through to the existing CORS policy, while the actual request still reaches the existing token checks.
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
area/authAuthentication, OAuth, credential poolscomp/cliCLI entry point, hermes_cli/, setup wizardcomp/dashboardWeb dashboard / control panel UI (dashboard/, landing)P2Medium — degraded but workaround existssweeper:blast-moderateSweeper blast radius: moderate — a subsystem or single platformsweeper:risk-security-boundarySweeper risk: may affect sandboxing, auth, credentials, or sensitive datatype/bugSomething isn't working
3 participants
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.
Problem
Fixes #59052.
Loopback dashboard CORS allows localhost origins, but token-protected
/api/*preflight requests never reachedCORSMiddleware. A cross-port localhost SPA that sendsX-Hermes-Session-TokentriggersOPTIONS /api/...first; browsers do not include that token on preflight, so the legacy dashboard token middleware returned401with no CORS headers and the real request was never sent.Root Cause
auth_middlewarewraps the earlier-registeredCORSMiddlewarein loopback mode. It treated tokenless CORS preflights exactly like real protected API calls, even though preflights are only asking whether the configured CORS policy allows the follow-up request.Fix
Detect true browser CORS preflights (
OPTIONS+Origin+Access-Control-Request-Method) in the loopback token gate and pass them through toCORSMiddleware. The actual follow-up request still has to carryX-Hermes-Session-Tokenor the legacy bearer token.Tests
$HOME/.hermes/hermes-agent/venv/bin/python -m pytest tests/hermes_cli/test_dashboard_auth_gate.py::test_loopback_cors_preflight_to_protected_api_uses_cors_policy -q$HOME/.hermes/hermes-agent/venv/bin/python -m pytest tests/hermes_cli/test_dashboard_auth_gate.py -qscripts/run_tests.sh tests/hermes_cli/test_dashboard_auth_gate.py$HOME/.hermes/hermes-agent/venv/bin/python -m ruff check hermes_cli/web_server.py tests/hermes_cli/test_dashboard_auth_gate.pyDuplicate check: searched open/all PRs for
#59052, CORS, preflight, and OPTIONS preflight before implementation; no competing PR found.