diff --git a/package-lock.json b/package-lock.json index c13e7e3..11219e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "ISC", "dependencies": { - "ip": "^2.0.1" + "ipaddr.js": "^2.2.0" }, "devDependencies": { "eslint": "^5.13.0", @@ -1165,10 +1165,14 @@ "node": ">=6" } }, - "node_modules/ip": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", - "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==" + "node_modules/ipaddr.js": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz", + "integrity": "sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==", + "license": "MIT", + "engines": { + "node": ">= 10" + } }, "node_modules/is-arrayish": { "version": "0.2.1", diff --git a/package.json b/package.json index 432c437..12c96b5 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,6 @@ "registry": "https://artifactory.brandwatch.com/artifactory/api/npm/npm" }, "dependencies": { - "ip": "^2.0.1" + "ipaddr.js": "^2.2.0" } } diff --git a/src/index.js b/src/index.js index 7f9a8cc..303b525 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ /** * Configure a ExpressJS middleware to expose useful health/metrics/checks endpoints. */ -const ip = require('ip'); +const ipaddr = require('ipaddr.js'); // Default empty configuration let metrics; @@ -33,7 +33,8 @@ const addMetrics = (m) => { metrics = m; }; const getMiddleware = () => (req, res, next) => { const requestingIP = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; - if (!ip.isPrivate(requestingIP)) { + + if (!['private', 'loopback'].includes(ipaddr.parse(requestingIP).range())) { return next(); }