Skip to content

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

Description

@chirag127

Problem

faker.internet.port() returns integers in [0, 65535], but port 0 is reserved (RFC 6335 §6, IANA) and must not appear on the wire. Test code that feeds the value into a real socket (net.connect({ port: 0 }), new URL(...)) gets OS-assigned ephemeral behavior instead of the seeded value, producing non-deterministic tests.

Steps

import { faker } from '@faker-js/faker'; // 10.5.0
faker.seed(1);
for (let i = 0; i < 100000; i++) {
  if (faker.internet.port() === 0) { console.log('got 0 at', i); break; }
}

Expected

A port in the valid usable range [1, 65535] (or a documented option to include 0).

Actual

0 is returned. Source: src/modules/internet/module.ts:727return this.faker.number.int(65535); which inclusively includes 0. The existing test at test/modules/internet.spec.ts:733 also asserts toBeGreaterThanOrEqual(0), codifying the defect.

Environment

  • @faker-js/faker 10.5.0 (next branch, commit on 2026-07-03)
  • Node 20+

Thanks for maintaining faker-js/faker!

Metadata

Metadata

Assignees

Labels

c: bugSomething isn't workingc: featureRequest for new featurem: internetSomething is referring to the internet modulep: 1-normalNothing urgent

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions