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

Open
#24 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
49/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go, helm, kubernetes

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Go
Stars
5
Forks
0
Avg merge
21h 13m
Merged PRs (30d)
53

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nebari-dev/tapas

All issues in nebari-dev/tapas

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.