fix(webui): allow SSH quick pairing behind HTTPS proxies

This commit is contained in:
Xubin Ren committed 2026-11-18 20:15:13 +08:00
1 parent d1e1d7bc5e
commit 307b3bce82
4 files changed
+92 -15

No files matched your search

+24 -8
View File
@@ -17,7 +17,7 @@ import subprocess
import sys
import tempfile
from pathlib import Path
from typing import Any
from typing import Any, TypedDict
from nanobot.webui.remote_pairing import PairReceipt, PairRequest, private_write, public_key, seal
from nanobot.webui.remote_ssh import RemoteError
@@ -70,22 +70,38 @@ def bridge_source(port: int, until: int) -> str:
return _BRIDGE.replace("PORT", str(port)).replace("UNTIL", str(until))
def metadata(config: Path) -> dict[str, Any]:
"""Read only the WebUI credential out of the operator-selected config."""
class PairingTarget(TypedDict):
port: int
secret: str
hostname: str
config_path: str
token_issue_path: str
def metadata(config: Path) -> PairingTarget:
"""Read the fixed loopback target and its credential from the selected config."""
try:
raw = json.loads(config.read_text())
ws = raw.get("channels", {}).get("websocket", {})
secret = ws.get("tokenIssueSecret") or ws.get("token_issue_secret") or ws.get("token")
if not ws.get("enabled") or not isinstance(secret, str) or not secret.strip() or "${" in secret:
raise RemoteError("webui_auth_required")
if ws.get("publicWsUrl") or ws.get("public_ws_url") or ws.get("trustedProxyAuth") or ws.get("trusted_proxy_auth"):
# publicWsUrl advertises the browser route. The SSH bridge does not
# use that URL, but does require a plain HTTP listener on loopback.
certfile = ws.get("sslCertfile") or ws.get("ssl_certfile") or ""
if (isinstance(certfile, str) and certfile.strip()) or ws.get("trustedProxyAuth") or ws.get("trusted_proxy_auth"):
raise RemoteError("incompatible_gateway")
port = ws.get("port", 8765)
if type(port) is not int or not 1 <= port <= 65535:
issue_path = ws.get("tokenIssuePath") or ws.get("token_issue_path") or ""
if type(port) is not int or not 1 <= port <= 65535 or not isinstance(issue_path, str):
raise ValueError
return {"port": port, "secret": secret, "hostname": socket.gethostname(),
"config_path": str(config.resolve()),
"token_issue_path": ws.get("tokenIssuePath") or ws.get("token_issue_path") or ""}
return {
"port": port,
"secret": secret,
"hostname": socket.gethostname(),
"config_path": str(config.resolve()),
"token_issue_path": issue_path,
}
except PermissionError:
raise RemoteError("config_permission") from None
except (OSError, ValueError, TypeError, AttributeError):