Skip to content

Commit

Permalink
fix: remove high security vuln & replace with other ip checking pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Jafferwaffer committed Jul 26, 2024
1 parent 73c0523 commit 24f3596
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
14 changes: 9 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"registry": "https://artifactory.brandwatch.com/artifactory/api/npm/npm"
},
"dependencies": {
"ip": "^2.0.1"
"ipaddr.js": "^2.2.0"
}
}
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 24f3596

Please sign in to comment.