From 002ff10ac42529f120036fc994fdac29004a2031 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sat, 20 May 2017 16:09:27 -0400 Subject: [PATCH 1/3] Ensure address is private Resolves #2296 --- packages/react-dev-utils/WebpackDevServerUtils.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 4fcd719087b..42ba4655a46 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -52,9 +52,17 @@ function prepareUrls(protocol, host, port) { if (isUnspecifiedHost) { prettyHost = 'localhost'; try { + // This can only return an IPv4 address lanUrlForConfig = address.ip(); if (lanUrlForConfig) { - lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig); + // Check if the address is a private ip + if (/^(10|172|192)[.]/.test(lanUrlForConfig)) { + // Address is private, format it for later use + lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig); + } else { + // Address is not private, so we will discard it + lanUrlForConfig = undefined; + } } } catch (_e) { // ignored From a7d06d50e2384c1675caf4280937a3dc6ffcea0f Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sat, 20 May 2017 16:42:44 -0400 Subject: [PATCH 2/3] adjust rule --- packages/react-dev-utils/WebpackDevServerUtils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 42ba4655a46..876630b5c26 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -56,7 +56,11 @@ function prepareUrls(protocol, host, port) { lanUrlForConfig = address.ip(); if (lanUrlForConfig) { // Check if the address is a private ip - if (/^(10|172|192)[.]/.test(lanUrlForConfig)) { + if ( + /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test( + lanUrlForConfig + ) + ) { // Address is private, format it for later use lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig); } else { From cd64c6117e833f3d1a646ad0b21b9b7bed2e2330 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sat, 20 May 2017 17:29:31 -0400 Subject: [PATCH 3/3] Update WebpackDevServerUtils.js --- packages/react-dev-utils/WebpackDevServerUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-dev-utils/WebpackDevServerUtils.js b/packages/react-dev-utils/WebpackDevServerUtils.js index 876630b5c26..02ce10f3e9b 100644 --- a/packages/react-dev-utils/WebpackDevServerUtils.js +++ b/packages/react-dev-utils/WebpackDevServerUtils.js @@ -56,6 +56,7 @@ function prepareUrls(protocol, host, port) { lanUrlForConfig = address.ip(); if (lanUrlForConfig) { // Check if the address is a private ip + // https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces if ( /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test( lanUrlForConfig