Skip to content

Commit f248b47

Browse files
committed
Change server.listen default address
1 parent 547ceb6 commit f248b47

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docs/server.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ Example:
8080
`listen(port, [host], [callback])`
8181

8282
Begin accepting connections on the specified port and host. If the host is
83-
omitted, the server will accept connections directed to any IPv4 address
84-
(INADDR\_ANY).
83+
omitted, the server will accept connections directed to the IPv4 address
84+
`127.0.0.1`. To listen on any other address, supply said address as the `host`
85+
parameter. For example, to listen on all available IPv6 addresses supply
86+
`::` as the `host` (note, this _may_ also result in listening on all
87+
available IPv4 addresses, depending on operating system behavior).
88+
89+
We highly recommend being as explicit as possible with the `host` parameter.
90+
Listening on all available addresses (through `::` or `0.0.0.0`) can lead
91+
to potential security issues.
8592

8693
This function is asynchronous. The last parameter callback will be called when
8794
the server has been bound.

lib/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,13 @@ Server.prototype.after = function () {
701701
})
702702
}
703703

704-
// All these just reexpose the requisite net.Server APIs
704+
// All these just re-expose the requisite net.Server APIs
705705
Server.prototype.listen = function (port, host, callback) {
706706
if (typeof (port) !== 'number' && typeof (port) !== 'string') { throw new TypeError('port (number or path) required') }
707707

708708
if (typeof (host) === 'function') {
709709
callback = host
710-
host = '0.0.0.0'
710+
host = '127.0.0.1'
711711
}
712712
if (typeof (port) === 'string' && /^[0-9]+$/.test(port)) {
713713
// Disambiguate between string ports and file paths

0 commit comments

Comments
 (0)