Skip to content

fix(internet): exclude reserved port 0 from internet.port()#3948

Open
xianjianlf2 wants to merge 2 commits into
faker-js:nextfrom
xianjianlf2:fix/internet-port-reserved-zero-3937
Open

fix(internet): exclude reserved port 0 from internet.port()#3948
xianjianlf2 wants to merge 2 commits into
faker-js:nextfrom
xianjianlf2:fix/internet-port-reserved-zero-3937

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 11, 2026

Copy link
Copy Markdown

Closes #3937

faker.internet.port() calls this.faker.number.int(65535), whose range is inclusive of 0. Port 0 is listed as Reserved by IANA (RFC 6335 §6) and is never a usable service port, so seeded values fed into a real socket (net.connect({ port: 0 })) trigger OS-assigned ephemeral behavior instead of the seeded value.

This restricts the range to 1..65535:

-    return this.faker.number.int(65535);
+    return this.faker.number.int({ min: 1, max: 65535 });
  • Tightened the existing test assertion (toBeGreaterThanOrEqual(0)1).
  • Regenerated the single affected seeded snapshot (internet > 42 > port); no other snapshots changed.
  • pnpm exec vitest run test/modules/internet.spec.ts → 1125 passed, no type errors.

…#3937)

Port 0 is reserved per RFC 6335 and must not be assigned as a usable
port, so internet.port() now returns a value in [1, 65535].
@xianjianlf2 xianjianlf2 requested a review from a team as a code owner July 11, 2026 10:47
@netlify

netlify Bot commented Jul 11, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b4873d5
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a548ec82117e1000810be00
😎 Deploy Preview https://deploy-preview-3948.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@xDivisionByZerox

Copy link
Copy Markdown
Member

As by comment #3937 (comment) we are currently not sure how to handle this. Since port 0 is not the only reserved port, flat out excluding it without all other reserved ones could lead to more problems than simply returning it for now.

@xDivisionByZerox xDivisionByZerox added the m: internet Something is referring to the internet module label Jul 11, 2026
@xDivisionByZerox xDivisionByZerox added c: bug Something isn't working c: feature Request for new feature p: 1-normal Nothing urgent labels Jul 11, 2026
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.84%. Comparing base (c2cd91d) to head (f967372).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3948   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files         923      923           
  Lines        3216     3216           
  Branches      583      583           
=======================================
  Hits         3179     3179           
  Misses         33       33           
  Partials        4        4           
Files with missing lines Coverage Δ
src/modules/internet/module.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ST-DDT

ST-DDT commented Jul 11, 2026

Copy link
Copy Markdown
Member

@xianjianlf2 Can you comment your thoughts on the linked issues?

@xianjianlf2

Copy link
Copy Markdown
Author

Replied on the linked issue with my thoughts on bug-vs-feature classification and the reserved-port scope: #3937 (comment)

Short version: I've retracted the inaccurate "must not appear on the wire" wording (updated both descriptions) — the authoritative basis is simply that IANA lists port 0 as Reserved. 0 is a special case (never a usable service port), not a slippery slope toward 1023/1024, so I'd keep this PR as the minimal, non-breaking min: 1 fix and treat configurable ranges/flags as a separate feature. Happy to fold it all into a broader feature PR instead if that's the preferred direction.

@ST-DDT ST-DDT added this to the v10.x milestone Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: bug Something isn't working c: feature Request for new feature m: internet Something is referring to the internet module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

faker.internet.port() can return 0, a reserved port per RFC 6335

3 participants