From f6628cf56d8315d2aad3997e35ae0396ebc437f8 Mon Sep 17 00:00:00 2001 From: Zhong-fan <17373302683@163.com> Date: Fri, 4 Dec 2026 13:41:05 +0800 Subject: [PATCH] fix(ssh): send no Origin header on the /colab/ssh upgrade Since 2026-12-02 the runtime rejects an upgrade that carries an Origin header with HTTP 403, so colab ssh failed on every fresh runtime while colab exec still worked. websocket-client sends Origin by default; pass suppress_origin=True and assert in the wire-contract test that the header never reaches the server. --- docs/06_ssh_access.md | 1 + src/colab_cli/commands/ssh.py | 5 ++++- tests/test_ssh_wire_contract.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/06_ssh_access.md b/docs/06_ssh_access.md index b659c5ab..96ad168e 100644 --- a/docs/06_ssh_access.md +++ b/docs/06_ssh_access.md @@ -1,5 +1,6 @@ --- log: +2026-12-04: `colab ssh` no longer sends an `Origin` header on the `/colab/ssh` upgrade (`suppress_origin=True`); the runtime rejects an upgrade that carries one with HTTP 403. 2026-11-27: Fixed `colab ssh` under Git for Windows' MSYS `ssh` (`/usr/bin/ssh` in Git Bash): ProxyCommand path arguments now use forward slashes on Windows (bash stripped the backslashes, failing with `D:Projects...python.exe: not found`), and `UserKnownHostsFile` is `/dev/null` when `ssh.exe` is an MSYS/Cygwin build (it wrote the host key to a `./nul` file). Native Windows OpenSSH keeps `nul`. Verified live from Git Bash and PowerShell (OpenSSH_for_Windows 9.5), and `integration/repro_windows_ssh/test.py` passed. 2026-11-23: Updated `integration/repro_windows_ssh/test.py` to check cached OAuth2 credentials via the OS `keyring` (`KEYRING_SERVICE_NAME` / `KEYRING_USERNAME`) instead of the removed `TOKEN_CONFIG_PATH`, and added portable import and prerequisite-skip regression tests in `tests/test_windows_ssh.py`. 2026-11-09: `--identity/-i` now accepts either a `.pub` public key or a private key path: `_resolve_pubkey` reads the `.pub` file directly when present before falling back to `_pubkey_from_identity` (`ssh-keygen -y -f`), and `_ssh_base_args` strips `.pub` for `ssh -i` when the sibling private key exists on disk. diff --git a/src/colab_cli/commands/ssh.py b/src/colab_cli/commands/ssh.py index cbf6a42b..4b49a9da 100644 --- a/src/colab_cli/commands/ssh.py +++ b/src/colab_cli/commands/ssh.py @@ -376,7 +376,10 @@ def _connect_websocket(url: str, pubkey: str) -> websocket.WebSocket: agent = COLAB_CLIENT_AGENT_HEADER header = [f"{_PUBKEY_HEADER}: {pubkey}", f"{agent['key']}: {agent['value']}"] try: - ws.connect(url, header=header) + # The runtime rejects an upgrade that carries an Origin header with 403, + # treating it as a cross-origin browser request. A CLI is not a browser, + # so the header must not be sent at all. + ws.connect(url, header=header, suppress_origin=True) return ws except websocket.WebSocketBadStatusException as e: status = getattr(e, "status_code", None) diff --git a/tests/test_ssh_wire_contract.py b/tests/test_ssh_wire_contract.py index 2c2db6d3..3ffa88fc 100644 --- a/tests/test_ssh_wire_contract.py +++ b/tests/test_ssh_wire_contract.py @@ -268,6 +268,10 @@ def _assert_wire_contract( ), f"wrong upgrade target: {req.target!r}" agent = req.headers_lower.get("x-colab-client-agent") assert agent == ("X-Colab-Client-Agent", "colab-cli"), f"agent header: {agent!r}" + assert "origin" not in req.headers_lower, ( + "the upgrade must not carry an Origin header: the runtime rejects it " + f"with 403. Headers sent: {sorted(req.headers)!r}" + ) # --- the real-wire contract, success path ------------------------------------