Skip to content

Commit

Permalink
Remove insecure ip package
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Jul 12, 2024
1 parent c0ebaa1 commit 7d0aa33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 0 additions & 7 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "2.0.0",
"dependencies": {
"chokidar": "^3.6.0",
"ip": "^2.0.1",
"tiny-json-http": "^7.5.1",
"uuid": "^10.0.0"
}
Expand Down
19 changes: 17 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { v4: uuidv4 } = require('uuid');

const chokidar = require('chokidar');
const tiny = require('tiny-json-http');
const ip = require('ip');
const os = require('os');

// These directory names are also referenced in other scripts!
const DIR_APPREDICT_RESULTS = concatenator([ __dirname, 'res'], false);
Expand Down Expand Up @@ -846,6 +846,21 @@ function write_stderr(std_file_prefix, stderr_file, stop_file, messages) {
});
}

/**
* Return the first non-internal IPv4 address, or the loopback address if none.
*/
function ip_address() {
const interfaces = os.networkInterfaces();
for (const networks of Object.values(interfaces)) {
for (const network of networks) {
if (network.family === 'IPv4' && !network.internal) {
return network.address;
}
}
}
return '127.0.0.1';
}

/******************************************************************************/

if (typeof process.env.REST_API_URL_DATA !== 'undefined' && process.env.REST_API_URL_DATA != '') {
Expand Down Expand Up @@ -946,7 +961,7 @@ const server = http.createServer((request, response) => {
return_obj = {
'success': {
'id': simulation_id,
'ip': ip.address()
'ip': ip_address()
}
};

Expand Down

0 comments on commit 7d0aa33

Please sign in to comment.