You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bin proxies: *_PROXY_PORT parsed with bare parseInt — invalid values crash opaquely or bind the wrong port #483
All five local proxy scripts in bin/ parse their listen port with a bare parseInt(process.env.<VAR> || '<default>', 10) and pass the result straight to server.listen(...) with no validation:
parseInt is lenient, and server.listen is not a validator:
env value
parseInt(v, 10)
result
abc
NaN
listen throws ERR_SOCKET_BAD_PORT — opaque crash at startup
99999 / -1
99999 / -1
listen throws ERR_SOCKET_BAD_PORT — opaque crash at startup
18744abc
18744
silently binds the default-looking port despite the typo
18744.9
18744
silently truncated
0x4a38
0
binds a random ephemeral port — the proxy is up but nothing can find it at 18744, and the startup log prints the parsed 0-derived value only via the bound callback
The worst case is the silent one: a mistyped or hex-spelled port leaves the proxy listening somewhere unexpected (or on an ephemeral port) while opencode's config points at the documented port — the failure surfaces far away as "proxy unreachable", with nothing in the proxy's own output naming the bad env value. The crash cases are only slightly better: ERR_SOCKET_BAD_PORT never says which env var was wrong or what value it carried.
This is the same failure class as the port-validation issues already fixed/filed for the sibling tools (openchamber schedule weekday parse, opencode restart-driver OC_PORT), but these five scripts are a separate copy that lives only in this repo.
Suggested fix
Parse each port through one strict helper (the scripts already share copy-pasted helpers, e.g. publishEndpoint — see the PR #438 review finding): accept only a decimal integer in 1–65535; on anything else, exit at startup with a message naming the env var and the offending value, e.g. CODEX_PROXY_PORT="0x4a38" is not a valid port (expected an integer 1-65535). Apply it at all seven parse sites in the five files.
Acceptance criteria
Each of the five scripts rejects a non-numeric, fractional, suffixed, hex-spelled, zero, negative, or >65535 port value at startup with an error naming the env var and value, and does not bind any port.
Valid values (including the defaults when the var is unset/empty) bind exactly the requested port, as today.
A check/test exercises at least the abc, 0x…, and 99999 cases for one proxy and the shared helper (if extracted) is used by all seven sites.
Related but distinct: #434 (missing {env:…} fallback in opencode config), #435 (single-sourcing these ports), #437 (port discovery) — none of them validates the value itself.
Activity