GeezerVison is showing github.com — antigravity-ls-proxy: ANTIGRAVITY_LS_ADDRESS port parsed with bare parseInt — malformed addresses silently discarded, managed daemon spawned instead · Issue #494 · developing-today/code
antigravity-ls-proxy: ANTIGRAVITY_LS_ADDRESS port parsed with bare parseInt — malformed addresses silently discarded, managed daemon spawned instead #494DescriptionProblem
bin/antigravity-ls-proxy.mjs validates its own listen port strictly via the shared parseProxyPort helper (#483), but the port it connects to — taken from the operator-supplied ANTIGRAVITY_LS_ADDRESS env var — is parsed with a bare parseInt and no validation at all.
bin/antigravity-ls-proxy.mjs:199-202 (LanguageServerManager.detectRunningInstances):
if (process.env.ANTIGRAVITY_LS_ADDRESS && process.env.ANTIGRAVITY_CSRF_TOKEN) {
const parts = process.env.ANTIGRAVITY_LS_ADDRESS.split(':');
const port = parseInt(parts[parts.length - 1], 10);
return [{ port, token: process.env.ANTIGRAVITY_CSRF_TOKEN }];
}
This branch returns immediately, bypassing even the weak check in the add() helper below it (p > 0, lines 207-214 — which itself has no <= 65535 upper bound, so candidate ports discovered from ps/ss/lsof/log lines are also unbounded above).
Evidence (verified this run on main 72a52d4)
Replaying the exact lines 200-202 logic in Node:
ANTIGRAVITY_LS_ADDRESS |
resulting candidate port |
127.0.0.1:abc |
NaN |
127.0.0.1: |
NaN |
127.0.0.1:99999 |
99999 |
127.0.0.1:0 |
0 |
127.0.0.1:-5 |
-5 |
127.0.0.1:18745abc |
18745 (trailing junk silently dropped) |
127.0.0.1:18745.9 |
18745 (fraction silently dropped) |
And the add() helper accepts 99999 / 65536 as candidate ports.
Why it matters
ensureActive() (line 271+) heartbeats each candidate via checkHeartbeat(port, token), which fetches http://127.0.0.1:${port}/.... With NaN, 0, -5 or 99999 that fetch simply fails and is swallowed (catch { return false }), so a typo'd explicit address is silently discarded and the proxy falls through to startManagedDaemon() — spawning a second, managed language server instead of telling the operator their configured address is malformed. That masks configuration errors and can attach the session to the wrong (fresh) server.
18745abc / 18745.9 silently connect to port 18745, the same wrong-port class bin proxies: *_PROXY_PORT parsed with bare parseInt — invalid values crash opaquely or bind the wrong port #483 fixed for the *_PROXY_PORT listen ports.
- The bin proxies: *_PROXY_PORT parsed with bare parseInt — invalid values crash opaquely or bind the wrong port #483 guard test (
bin/proxy-port.test.mjs, "all seven parse sites…") only regexes parseInt(process.env.[A-Z_]*PROXY_PORT, so this site — an *_ADDRESS, not a *_PROXY_PORT — slips past the guard that was meant to prevent regressions of this class.
Suggested fix / acceptance criteria
- The
ANTIGRAVITY_LS_ADDRESS port is validated strictly (digits only, integer 1-65535), reusing parseProxyPortValue from bin/proxy-port.mjs where practical; a malformed address fails fast with an error naming ANTIGRAVITY_LS_ADDRESS and the offending value, instead of silently falling back to a managed daemon.
- The
add() candidate helper rejects ports > 65535 as well as <= 0 / NaN.
- Regression tests cover at least:
abc, empty port, 0, 99999, 18745abc, 18745.9, and a valid host:18745; and the bin proxies: *_PROXY_PORT parsed with bare parseInt — invalid values crash opaquely or bind the wrong port #483 guard test (or a new one) catches a bare parseInt on the ANTIGRAVITY_LS_ADDRESS path.
-
node --test bin/proxy-port.test.mjs (plus any new test file) passes.
Dedup: #483 covered only the *_PROXY_PORT listen ports (closed); #435 is about single-sourcing the proxies' port configuration in opencode config, not about validating this address; no open or closed issue covers ANTIGRAVITY_LS_ADDRESS parsing. MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|