Skip to content

Commit

Permalink
Ensure address is private (#2297)
Browse files Browse the repository at this point in the history
* Ensure address is private
Resolves #2296

* adjust rule

* Update WebpackDevServerUtils.js
  • Loading branch information
Timer authored and gaearon committed May 21, 2017
1 parent 3260d17 commit 2430b56
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,22 @@ 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
// 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
)
) {
// 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
Expand Down

0 comments on commit 2430b56

Please sign in to comment.