Coding-agent terminals never connect when the apps host is 32 characters or longer (ttyd --check-origin)

Đang mở
#24 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
49/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, helm, kubernetes
Lĩnh vực
backend, networking

Hướng nghiên cứu

Start with the four ttyd templates at deploy/helm/javo/files/templates/{pi,claude-code,herdr,terminal}.yaml and the gateway origin check at internal/gateway/proxy/proxy.go:650. Check how NetworkPolicy restricts access to app pods, then assess removing --check-origin and adding a gateway test with an apps host of at least 32 characters. Done when terminals connect through the gateway and the regression test covers the long-host case.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

On a NIC cluster on AWS, every coding-agent terminal showed "Press Enter to Reconnect" and never connected. ttyd logged this on each attempt:

refuse to serve WS client from different origin due to the --check-origin option.
User code denied connection

The apps host there was javo-apps.int-hub-dev.openteams.dev, which is 35 characters. ttyd 1.7.7 with --check-origin refuses any websocket whose Origin host is 32 characters or longer, even when Host matches it exactly. The pi, claude-code, herdr and terminal templates all pass that flag (deploy/helm/javo/files/templates/{pi,claude-code,herdr,terminal}.yaml).

Repro

I bypassed the gateway, port-forwarded straight to a pi pod's ttyd on 7681, and sent a websocket handshake with Host: H and Origin: https://H:

Host length Result
4, 22, 28, 29, 30, 31 101 Switching Protocols
32, 33, 35, 38 connection refused, same log line

The gateway is not involved. It keeps Host as is (internal/gateway/proxy/proxy.go:309), and its own same-origin check (foreignOrigin, proxy.go:650) passes for the same request.

Why

check_host_origin in ttyd 1.7.7 (src/protocol.c) parses the Origin header in place with lws_parse_uri, which leaves address pointing inside buf, and then runs sprintf(buf, "%s", address). Source and destination overlap, which is undefined behaviour. A 32-byte limit fits a copy routine that moves 32 bytes at a time and only goes wrong past that. This is inferred from the code and the measured limit. Patching in a separate buffer and re-running the table above would confirm or rule it out. ttyd main swapped sprintf for snprintf (tsl0922/ttyd@e2819f2), which still overlaps, so upgrading ttyd may not fix it. tsl0922/ttyd#1566 is a different --check-origin failure (HTTP/2).

Who hits it

Anyone whose apps host is 32 characters or longer. javo-pack defaults to javo-apps.<domain> (values.yaml:164), so that's every domain of 22 characters or more. The Hetzner deploy at javo-apps.nebari.openteams.app is 30, which is why it works there.

Workaround today: an apps host of 31 characters or fewer. On the AWS cluster apps.int-hub-dev.openteams.dev (30) fixed it, and the pi terminal connected and answered.

What I think we should do

Drop --check-origin from the four templates. The gateway already refuses a websocket from a foreign origin before it reaches the app, and with NetworkPolicy enforced (allow-gateway-only in javo-apps) only the gateway can reach app pods, so ttyd's own check adds nothing we rely on. A test that opens an agent terminal through the gateway with a long apps host would keep this from coming back. Separately, we should report the overlap upstream to ttyd.

Ngôn ngữ chính
Go
Star
5
Fork
0
Merge trung bình
21 giờ 13 phút
Pull request đã merge (30 ngày)
53

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nebari-dev/tapas

Tất cả issue của nebari-dev/tapas

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.