Repository navigation
fix: support proxied dashboard chat sessions #21104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hejun041
wants to merge
2
commits into
NousResearch:main
Choose a base branch
from
hejun041:fix/dashboard-ws-systemd-compat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -595,7 +595,7 @@ async def get_status(): | |
| from hermes_state import SessionDB | ||
| db = SessionDB() | ||
| try: | ||
| sessions = db.list_sessions_rich(limit=50) | ||
| sessions = db.list_sessions_rich(limit=50, order_by_last_active=True) | ||
| now = time.time() | ||
| active_sessions = sum( | ||
| 1 for s in sessions | ||
|
|
@@ -764,7 +764,7 @@ async def get_sessions(limit: int = 20, offset: int = 0): | |
| from hermes_state import SessionDB | ||
| db = SessionDB() | ||
| try: | ||
| sessions = db.list_sessions_rich(limit=limit, offset=offset) | ||
| sessions = db.list_sessions_rich(limit=limit, offset=offset, order_by_last_active=True) | ||
| total = db.session_count() | ||
| now = time.time() | ||
| for s in sessions: | ||
|
|
@@ -2902,13 +2902,24 @@ def _is_public_bind() -> bool: | |
|
|
||
|
|
||
| def _ws_client_is_allowed(ws: "WebSocket") -> bool: | ||
| """Check if the WebSocket client IP is acceptable. | ||
|
|
||
| Allows loopback always; allows any IP when bound to all-interfaces | ||
| (--insecure mode, guarded by session token auth). | ||
| """Check if the WebSocket client is acceptable. | ||
|
|
||
| Allows loopback clients always; allows any IP when bound to all-interfaces | ||
| (--insecure mode, guarded by session token auth). For the documented | ||
| loopback-behind-reverse-proxy deployment, Uvicorn may replace ws.client | ||
| with the X-Forwarded-For address. In that case we still allow the request | ||
| when the upstream Host header targets the dashboard's bound host (Nginx | ||
| sets Host to 127.0.0.1:9119), preserving the DNS-rebinding guard for WS | ||
| routes. | ||
| """ | ||
| if _is_public_bind(): | ||
| return True | ||
|
|
||
| bound_host = getattr(app.state, "bound_host", "") | ||
| host_header = ws.headers.get("host", "") | ||
| if bound_host and _is_accepted_host(host_header, bound_host): | ||
| return True | ||
|
|
||
| client_host = ws.client.host if ws.client else "" | ||
| if not client_host: | ||
| return True | ||
|
|
@@ -4050,6 +4061,13 @@ def start_server( | |
| app.state.bound_host = host | ||
| app.state.bound_port = port | ||
|
|
||
| # Uvicorn's WebSocket scope uses the socket peer address for ws.client. | ||
| # When the loopback-only dashboard is intentionally exposed through a | ||
| # same-host reverse proxy, the socket peer is already 127.0.0.1, but | ||
| # enabling proxy headers keeps HTTP URL/client metadata consistent with | ||
| # the deployment docs while only trusting local proxies. | ||
| forwarded_allow_ips = "127.0.0.1,::1" | ||
|
|
||
| if open_browser: | ||
| import webbrowser | ||
|
|
||
|
|
@@ -4060,4 +4078,11 @@ def _open(): | |
| threading.Thread(target=_open, daemon=True).start() | ||
|
|
||
| print(f" Hermes Web UI → http://{host}:{port}") | ||
| uvicorn.run(app, host=host, port=port, log_level="warning") | ||
| uvicorn.run( | ||
| app, | ||
| host=host, | ||
| port=port, | ||
| log_level="warning", | ||
| proxy_headers=True, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not enable proxy headers unconditionally for loopback binds. The current design keeps the loopback peer as the security boundary and enables forwarded-header handling only for authenticated public binds; preserve that distinction when salvaging the proxy case. |
||
| forwarded_allow_ips=forwarded_allow_ips, | ||
| ) | ||
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes only the peer-IP check. A normal public reverse proxy still presents a browser
Originfor its public hostname, while the separate Host/Origin guard compares that Origin to the loopbackbound_host; this PR does not modify that path, so the reportedorigin_mismatchremains. Please route the configured trusted public URL through the Host/Origin policy rather than bypassing this peer check.