mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #1012] vinext dev/start CLI arg parser silently accepts missing values for --port / --hostname (NaN, undefined, swallows next flag) #223
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#223
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @eashish93 on GitHub (May 2, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/1012
vinext devandvinext startaccept--port/--hostname(and their short aliases-p/-H) without validating that the next argv slot actually contains a value. The parser blindly consumesargs[++i], so:vinext dev --port(no value) →port = NaN→ server tries tolisten(NaN)and either crashes or binds an OS-assigned random port silently.vinext dev --hostname(no value) →hostname = undefined.vinext dev --port --hostname 0.0.0.0(typo: missing port value) →--hostnameis consumed as the port value, parses toNaN, AND the hostname flag is lost. User loses BOTH settings with no warning.Reproduce
The bug lives in the CLI parser at
dist/cli.js:71-73. Same pattern in source (src/cli.ts):Standalone repro of the parser logic (no need to install vinext):
End-to-end repro:
Why it's a bug
Three concrete failure modes:
NaN— Node'sserver.listen(NaN)falls back to a random ephemeral port. The user typed--portexpecting a deterministic port; they get one assigned by the OS. The dev URL printed is correct but the user's bookmarks / proxy configs / wrangler bindings break.hostname = undefined— Vite'sserver.hostfalls back to its default (localhost), which means the dev server is unreachable from anything but the loopback interface. Common bug shape inside containers / WSL — user explicitly passes--hostname 0.0.0.0to fix it, mistypes (case 3 above), and gets the broken default back without a warning.vinext dev --port --hostname 0.0.0.0parses as{ port: NaN }(no hostname). Everything downstream of port-resolution fails, but the error message says "could not bind port NaN" rather than "you forgot the port value."Proposed fix
Validate that
args[i + 1]exists and isn't another flag before consuming it. Suggested shape:Same shape for any other future flag taking a value.
Environment
The bug is in the parser itself — environment-independent.