Skip to content

fix(node:net): validate listen ports synchronously - #44555

Open
steipete wants to merge 1 commit into
oven-sh:mainfrom
steipete:claude/w131-listen-port-validation-upstream
Open

steipete wants to merge 1 commit into
oven-sh:mainfrom
steipete:claude/w131-listen-port-validation-upstream

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

http.Server.listen(65536) and https.Server.listen(65536) now throw RangeError with ERR_SOCKET_BAD_PORT synchronously, like Node 24. Real bind failures such as EADDRINUSE remain asynchronous error events.

HTTP currently lets Bun.serve() validate the port inside the bind-error catch. The fix validates before binding, preserves the original string until validation, and converts the complete numeric string instead of accepting a parseInt() prefix. Numeric ports take precedence over an accompanying path. The net portion preserves whitespace strings for validation and uses Node's pipe-name routing.

Adapts the net string-routing and U+3000 validation changes from #34083, which remains open; thanks @robobun. This also covers HTTP/HTTPS timing and the full port overload matrix.

Proof:

  • Node v24.19.0 passes a dependency-free matrix of 264 invalid-port cases and three asynchronous bind controls. The exact upstream candidate passes the same matrix.
  • All 75 added regressions pass on an exact Linux build of this branch. Exact unpatched upstream base aa8307619d8dccbda113a5a4aa1885e0cef7eaba fails 36 of them and passes 39.
  • The fix resolves OpenClaw's gateway listen consumer: Node 5/5, c999 4/5, patched fork 5/5, with isolated HOME/state/TMPDIR and umask 022.
  • Surrounding net/HTTP/TLS suites pass 484 tests with one existing skip on the exact upstream candidate.
  • Scoped P2 branch review is clean.

The fork counterpart is openclaw#101; Linux x64 and macOS arm64 native CI passed before its guarded squash merge.

AOT-main rebase validation

Rebased onto upstream main 8d5672c5529049f1a9a3453d07e6cd6a1564abc7. Linux x64 main fails 36 added port-validation cases. The rebased release passes the full HTTP file: 389 passed, one skipped, zero failed. The fix is mirrored into the AOT HTTP implementation and shared validator. A compiled AOT probe passes invalid-port and port-zero checks; the alternate-source hash test and formatting also pass.

The release build uses bun run build:release --lto=off. Its executable revision matches a6b6ade2c424991536423ddcb8c6513226c8b72b. Independent P0–P2 review passes. Earlier platform results above are historical; this rebase's fresh validation is scoped to the results here.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: oven-sh/bun
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8d5672c
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5a62148c-f029-4f82-9227-5c5d8da46708
Commits

Reviewing files that changed from the base of the PR and between c40812a and a6b6ade.

Files selected for processing: 5
  • src/js/ahead-of-time/node/_http_server.ts
  • src/js/node/_http_server.ts
  • src/js/node/net.ts
  • src/jsc/bindings/NodeValidatorBodies.h
  • test/js/node/http/node-http.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

Server.listen() now routes string arguments based on pipe-name detection and validates numeric and string ports before binding. Null ports default to port 0 when no socket path is supplied. Tests cover invalid and ephemeral ports, plus asynchronous address conflicts.

Changes

Server listen port handling

Layer / File(s) Summary
Listen argument routing
src/js/node/net.ts
isPipeName(port) now selects the pipe-path branch. Strings that convert to nonnegative numbers use the port-handling path.
Port validation and binding
src/js/node/_http_server.ts, src/js/ahead-of-time/node/_http_server.ts, src/jsc/bindings/NodeValidatorBodies.h, test/js/node/http/node-http.test.ts
Server.listen() defaults null ports to 0 when no socket path is supplied. It validates numeric and string ports, converts them to signed 32-bit numbers, and clears socketPath. Port-string trimming now includes U+3000 IDEOGRAPHIC SPACE. Tests cover synchronous port errors, ephemeral ports, and asynchronous EADDRINUSE events.

Suggested reviewers: jarred-sumner

Priority: Normal

Merge Risk: Minimal · up to a6b6a

Invalid ports are intended to fail synchronously while bind failures remain asynchronous. No merge-blocking issue was identified.

Security architecture risk: Low · up to c4081

Port validation becomes stricter without weakening the numeric range controls. The main security-relevant change is endpoint selection when port and path inputs overlap. No introduced authorization bypass was established, but downstream deployment exposure and cancellation-after-failure behavior remain incompletely assessed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The security-relevant exposure is listener placement for applications using these APIs. HTTP selects TCP when a valid port accompanies a path, while net accepts additional positional strings as pipe names. Deployment impact depends on caller configuration and endpoint access controls, which were not supplied.

Trust Boundaries and Controls

  • observed — Numeric port inputs are validated before native binding. Strings classified as pipe names use the existing Unix-socket binding path, which already accepted nonnumeric paths before this PR. The routing expansion does not itself establish additional binding authority or a numeric validation bypass.

Resilience and Maintainability Implications

  • observed — Successful net binding assigns handle ownership before scheduling listening, and close releases the handle. The added regressions check invalid-input error timing and asynchronous address conflicts, but do not exercise AbortSignal cleanup followed by retry. Test execution was not independently performed in this review.

Hardening Proposals

  • proposed — Applications relying on filesystem-restricted IPC should explicitly reject simultaneous port and path configuration, rather than treating a supplied path as proof that the listener remains IPC-only.
Pre-merge checks: Passed 4
Check name Status Explanation
Description check Passed The description clearly explains the change and provides extensive verification results. It does not use the template headings, but it covers both required sections completely.
Title check Passed The title is concise, specific, and accurately summarizes the synchronous listen-port validation change.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Validate HTTP and HTTPS ports before binding, preserving asynchronous bind failures. Adapt the net string-routing and Unicode whitespace fixes from oven-sh#34083.

This branch has not been deployed

No deployments
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