Skip to content

factory: cli: a non-integer or out-of-range PORT env var reaches net.listen and crashes b4 start - #1065

Closed
b4dotrun[bot] wants to merge 1 commit into
mainfrom
factory/wo-9409eea3d48a98ab
Closed

b4dotrun[bot] wants to merge 1 commit into
mainfrom
factory/wo-9409eea3d48a98ab

Conversation

@b4dotrun

@b4dotrun b4dotrun Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Refs #1063

Produced by the B4.run software factory from issue #1063 and approved by a person
(recorded actor: operator) on 2026-10-21T21:55:50.801Z. This is a draft. The factory never merges.

Pin and drift

Branched at 270ff78. main was at 9d02a3a when delivered, 1 commits ahead of the pin.
No file this change touches changed on main in between.

Approved task

Fix resolveServePort to validate the PORT environment variable as a purely decimal integer within the valid TCP port range.

Background

Currently resolveServePort converts the trimmed PORT env var with Number() and accepts any finite number. That allows non-integer, negative, out-of-range and non-decimal spellings (fractional like "3.5", signed like "-1", hex like "0x50", exponential like "1e3") to be returned and passed to net.listen, which then throws a RangeError or binds an unexpected port. The function's doc comment already states non-numeric or empty values should fall back to the default (8000) — the implementation must be brought in line with that behaviour and with the CLI flag parsing.

Change required

Only the file packages/cli/src/lib/dev/serve-runtime.ts should be changed. The function resolveServePort must honour an explicitPort argument when present. When explicitPort is undefined, the envPort string must be treated as set only when it is a decimal integer spelling consisting of digits only (no sign, no exponent, no hex, no fraction) and its numeric value is between 0 and 65535 inclusive. Any other envPort value (including fractional, negative, >65535, hex, exponential, or non-numeric) must be treated as unset and the function should return DEFAULT_SERVE_PORT.

Do not change DEFAULT_SERVE_PORT, the CLI flag parsing, or any exported types.

Acceptance criteria

A1: explicitPort wins (including 0): resolveServePort(0, "65535") returns 0
A2: decimal-digit envPort in range is honoured: resolveServePort(undefined, "65535") returns 65535
A3: fractional envPort falls back to default: resolveServePort(undefined, "3.5") returns 8000
A4: non-decimal envPort (hex) falls back to default: resolveServePort(undefined, "0x50") returns 8000

Digests and receipts

task 6a92487944e4bd8749a5b4e3aa6338c4cd798e5271a9a027124e07e196063dfa · bundle 558e485fc83297ac94a0ebbf0cbe57b9b2e7b4ebe124ea6b5e0d9268a0cccb47 · candidate 84fc77597ea429984fed44458dccd4a8ff9777c6d2a5cadbddce40b9e1e40d35
oracle receipt rc-837901b3-f95c-4ff2-8ec8-c10d61c992fd · verification receipt rc-68dd644b-0d6e-47f6-89a2-affef5f5d7d3 · re-verification at approval rc-2b97d809-b4c7-40c4-af81-bb093507011b
policy 57db502ebe1f60cb8359a1481337172c1171ef49d0d42a4263838f0ee16f1d26 · environment eb32c1df43bbdc4cb05adaeee0d9c9d4201764d11390a90642fc2c853f1c0508

packages/cli/src/lib/dev/serve-runtime.ts: 4a6211cd3f9c06c9a891e371ddf97c7b5ef1700a → 0d01d57853672ee09933c37f5de434289c33294e

…et.listen` and crashes `b4 start`

Refs #1063

Work order wo-9409eea3d48a98ab, bundle 558e485fc83297ac94a0ebbf0cbe57b9b2e7b4ebe124ea6b5e0d9268a0cccb47.
@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
b4-run Ignored Ignored Preview Oct 21, 2026 9:56pm UTC
navlog-web Ignored Ignored Preview Oct 21, 2026 9:56pm UTC

Request Review

@blove

blove commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Adopted as #1066: the delivered commit cherry-picked onto adopt/wo-9409eea3d48a98ab, with a changeset and the independent check promoted to packages/cli/test/serve-port.test.ts. Closing this draft; the factory never merges its own.

@blove blove closed this Oct 21, 2026
blove added a commit that referenced this pull request Oct 21, 2026
…` and crashes `b4 start` (#1063) (#1066)

* factory: cli: a non-integer or out-of-range `PORT` env var reaches `net.listen` and crashes `b4 start`

Refs #1063

Work order wo-9409eea3d48a98ab, bundle 558e485fc83297ac94a0ebbf0cbe57b9b2e7b4ebe124ea6b5e0d9268a0cccb47.

* cli: a non-integer or out-of-range `PORT` env var reaches `net.listen` and crashes `b4 start` (#1063)

Adopted from the factory's draft PR #1065 (work order wo-9409eea3d48a98ab): the delivered commit, cherry-picked, plus a changeset (.changeset/factory-wo-9409eea3d48a98ab.md) and the factory's independent check as packages/cli/test/serve-port.test.ts.

Closes #1063

---------

Co-authored-by: b4dotrun[bot] <344497757+b4dotrun[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant