Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2 low vulnerabilities, centralize env vars validation #173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
const assert = require('assert');
assert.ok(process.env.JAMBONES_MYSQL_HOST &&
process.env.JAMBONES_MYSQL_USER &&
process.env.JAMBONES_MYSQL_PASSWORD &&
process.env.JAMBONES_MYSQL_DATABASE, 'missing JAMBONES_MYSQL_XXX env vars');
if (process.env.JAMBONES_REDIS_SENTINELS) {
assert.ok(process.env.JAMBONES_REDIS_SENTINEL_MASTER_NAME,
'missing JAMBONES_REDIS_SENTINEL_MASTER_NAME env var, JAMBONES_REDIS_SENTINEL_PASSWORD env var is optional');
} else {
assert.ok(process.env.JAMBONES_REDIS_HOST, 'missing JAMBONES_REDIS_HOST env var');
}
assert.ok(process.env.DRACHTIO_PORT || process.env.DRACHTIO_HOST, 'missing DRACHTIO_PORT env vars');
assert.ok(process.env.DRACHTIO_SECRET, 'missing DRACHTIO_SECRET env var');
assert.ok(process.env.JAMBONES_TIME_SERIES_HOST, 'missing JAMBONES_TIME_SERIES_HOST env var');
assert.ok(process.env.JAMBONES_NETWORK_CIDR || process.env.K8S, 'missing JAMBONES_NETWORK_CIDR env var');
require('./lib/config').validateEnvVars();

const Srf = require('drachtio-srf');
const srf = new Srf('sbc-inbound');
Expand Down
41 changes: 41 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const assert = require('assert');

const requiredEnvVars = [
'JAMBONES_MYSQL_HOST',
'JAMBONES_MYSQL_USER',
'JAMBONES_MYSQL_PASSWORD',
'JAMBONES_MYSQL_DATABASE',
'DRACHTIO_SECRET',
'JAMBONES_TIME_SERIES_HOST'
];

if (process.env.JAMBONES_REDIS_SENTINELS) {
requiredEnvVars.push('JAMBONES_REDIS_SENTINEL_MASTER_NAME');
} else {
requiredEnvVars.push('JAMBONES_REDIS_HOST');
}

if (process.env.DRACHTIO_HOST || process.env.DRACHTIO_PORT) {
requiredEnvVars.push(process.env.DRACHTIO_HOST ? 'DRACHTIO_HOST' : 'DRACHTIO_PORT');
}

if (process.env.DRACHTIO_HOST && !process.env.K8S) {
assert.ok(process.env.JAMBONES_NETWORK_CIDR,
'Missing JAMBONES_NETWORK_CIDR env var (required when DRACHTIO_HOST is set and not in K8S)');
} else if (process.env.K8S && process.env.K8S_FEATURE_SERVER_SERVICE_NAME) {
requiredEnvVars.push('K8S');
requiredEnvVars.push('K8S_FEATURE_SERVER_SERVICE_NAME');
} else {
assert.ok(process.env.K8S && !process.env.K8S_FEATURE_SERVER_SERVICE_NAME,
'when running in Kubernetes, an env var K8S_FEATURE_SERVER_SERVICE_NAME is required');
}

const validateEnvVars = () => {
requiredEnvVars.forEach((envVar) => {
assert.ok(process.env[envVar], `Missing ${envVar} env var`);
});
};

module.exports = {
validateEnvVars
};

Check failure on line 41 in lib/config.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found
30 changes: 16 additions & 14 deletions package-lock.json

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

Loading