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

未关闭
#24 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
49/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
go, helm, kubernetes

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Go
星标
5
派生
0
平均合并
21 小时 13 分钟
30 天内合并 PR
53

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nebari-dev/tapas 的其他 Issue

查看 nebari-dev/tapas 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。