Skip to content

Commit 2430b56

Browse files
Timergaearon
authored andcommitted
Ensure address is private (#2297)
* Ensure address is private Resolves #2296 * adjust rule * Update WebpackDevServerUtils.js
1 parent 3260d17 commit 2430b56

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,22 @@ function prepareUrls(protocol, host, port) {
5252
if (isUnspecifiedHost) {
5353
prettyHost = 'localhost';
5454
try {
55+
// This can only return an IPv4 address
5556
lanUrlForConfig = address.ip();
5657
if (lanUrlForConfig) {
57-
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
58+
// Check if the address is a private ip
59+
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
60+
if (
61+
/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
62+
lanUrlForConfig
63+
)
64+
) {
65+
// Address is private, format it for later use
66+
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
67+
} else {
68+
// Address is not private, so we will discard it
69+
lanUrlForConfig = undefined;
70+
}
5871
}
5972
} catch (_e) {
6073
// ignored

0 commit comments

Comments
 (0)