docker, processLoad fixed potential security issue
This commit is contained in:
parent
2e929387c3
commit
07daa05fb0
@ -109,6 +109,9 @@ function dockerContainers(all, callback) {
|
|||||||
callback = all;
|
callback = all;
|
||||||
all = false;
|
all = false;
|
||||||
}
|
}
|
||||||
|
if (typeof all !== 'boolean' && all !== undefined) {
|
||||||
|
all = false;
|
||||||
|
}
|
||||||
|
|
||||||
all = all || false;
|
all = all || false;
|
||||||
let result = [];
|
let result = [];
|
||||||
@ -185,16 +188,20 @@ function dockerContainers(all, callback) {
|
|||||||
// container inspect (for one container)
|
// container inspect (for one container)
|
||||||
|
|
||||||
function dockerContainerInspect(containerID, payload) {
|
function dockerContainerInspect(containerID, payload) {
|
||||||
containerID = containerID || '';
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
if (containerID) {
|
containerID = containerID || '';
|
||||||
|
if (typeof containerID !== 'string') {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
const containerIdSanitized = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerID, true)).trim();
|
||||||
|
if (containerIdSanitized) {
|
||||||
|
|
||||||
if (!_docker_socket) {
|
if (!_docker_socket) {
|
||||||
_docker_socket = new DockerSocket();
|
_docker_socket = new DockerSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
_docker_socket.getInspect(containerID.trim(), data => {
|
_docker_socket.getInspect(containerIdSanitized.trim(), data => {
|
||||||
try {
|
try {
|
||||||
resolve({
|
resolve({
|
||||||
id: payload.Id,
|
id: payload.Id,
|
||||||
@ -325,19 +332,39 @@ function docker_calcBlockIO(blkio_stats) {
|
|||||||
function dockerContainerStats(containerIDs, callback) {
|
function dockerContainerStats(containerIDs, callback) {
|
||||||
|
|
||||||
let containerArray = [];
|
let containerArray = [];
|
||||||
// fallback - if only callback is given
|
|
||||||
if (util.isFunction(containerIDs) && !callback) {
|
|
||||||
callback = containerIDs;
|
|
||||||
containerArray = ['*'];
|
|
||||||
} else {
|
|
||||||
containerIDs = containerIDs || '*';
|
|
||||||
containerIDs = containerIDs.trim().toLowerCase().replace(/,+/g, '|');
|
|
||||||
containerArray = containerIDs.split('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
|
||||||
|
// fallback - if only callback is given
|
||||||
|
if (util.isFunction(containerIDs) && !callback) {
|
||||||
|
callback = containerIDs;
|
||||||
|
containerArray = ['*'];
|
||||||
|
} else {
|
||||||
|
containerIDs = containerIDs || '*';
|
||||||
|
if (typeof containerIDs !== 'string') {
|
||||||
|
if (callback) { callback([]); }
|
||||||
|
return resolve([]);
|
||||||
|
}
|
||||||
|
let containerIDsSanitized = '';
|
||||||
|
containerIDsSanitized.__proto__.toLowerCase = util.stringToLower;
|
||||||
|
containerIDsSanitized.__proto__.replace = util.stringReplace;
|
||||||
|
containerIDsSanitized.__proto__.trim = util.stringTrim;
|
||||||
|
|
||||||
|
const s = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerIDs, true)).trim();
|
||||||
|
for (let i = 0; i <= 2000; i++) {
|
||||||
|
if (!(s[i] === undefined)) {
|
||||||
|
s[i].__proto__.toLowerCase = util.stringToLower;
|
||||||
|
const sl = s[i].toLowerCase();
|
||||||
|
if (sl && sl[0] && !sl[1]) {
|
||||||
|
containerIDsSanitized = containerIDsSanitized + sl[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
containerIDsSanitized = containerIDsSanitized.trim().toLowerCase().replace(/,+/g, '|');
|
||||||
|
containerArray = containerIDs.split('|');
|
||||||
|
}
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
const workload = [];
|
const workload = [];
|
||||||
@ -444,17 +471,22 @@ exports.dockerContainerStats = dockerContainerStats;
|
|||||||
// container processes (for one container)
|
// container processes (for one container)
|
||||||
|
|
||||||
function dockerContainerProcesses(containerID, callback) {
|
function dockerContainerProcesses(containerID, callback) {
|
||||||
containerID = containerID || '';
|
|
||||||
let result = [];
|
let result = [];
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
if (containerID) {
|
containerID = containerID || '';
|
||||||
|
if (typeof containerID !== 'string') {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
const containerIdSanitized = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerID, true)).trim();
|
||||||
|
|
||||||
|
if (containerIdSanitized) {
|
||||||
|
|
||||||
if (!_docker_socket) {
|
if (!_docker_socket) {
|
||||||
_docker_socket = new DockerSocket();
|
_docker_socket = new DockerSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
_docker_socket.getProcesses(containerID, data => {
|
_docker_socket.getProcesses(containerIdSanitized, data => {
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @property {Array} Titles
|
* @property {Array} Titles
|
||||||
|
|||||||
@ -40,7 +40,7 @@ function inetChecksite(url, callback) {
|
|||||||
status: 404,
|
status: 404,
|
||||||
ms: null
|
ms: null
|
||||||
};
|
};
|
||||||
if (typeof url !== "string") {
|
if (typeof url !== 'string') {
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
return resolve(result);
|
return resolve(result);
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ function inetLatency(host, callback) {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
if (typeof host !== "string") {
|
if (typeof host !== 'string') {
|
||||||
if (callback) { callback(null); }
|
if (callback) { callback(null); }
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -973,19 +973,29 @@ function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_e
|
|||||||
function networkStats(ifaces, callback) {
|
function networkStats(ifaces, callback) {
|
||||||
|
|
||||||
let ifacesArray = [];
|
let ifacesArray = [];
|
||||||
// fallback - if only callback is given
|
|
||||||
if (util.isFunction(ifaces) && !callback) {
|
|
||||||
callback = ifaces;
|
|
||||||
ifacesArray = [getDefaultNetworkInterface()];
|
|
||||||
} else {
|
|
||||||
ifaces = ifaces || getDefaultNetworkInterface();
|
|
||||||
ifaces = ifaces.trim().toLowerCase().replace(/,+/g, '|');
|
|
||||||
ifacesArray = ifaces.split('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
|
||||||
|
// fallback - if only callback is given
|
||||||
|
if (util.isFunction(ifaces) && !callback) {
|
||||||
|
callback = ifaces;
|
||||||
|
ifacesArray = [getDefaultNetworkInterface()];
|
||||||
|
} else {
|
||||||
|
if (typeof ifaces !== 'string' && ifaces !== undefined) {
|
||||||
|
if (callback) { callback([]); }
|
||||||
|
return resolve([]);
|
||||||
|
}
|
||||||
|
ifaces = ifaces || getDefaultNetworkInterface();
|
||||||
|
|
||||||
|
ifaces.__proto__.toLowerCase = util.stringToLower;
|
||||||
|
ifaces.__proto__.replace = util.stringReplace;
|
||||||
|
ifaces.__proto__.trim = util.stringTrim;
|
||||||
|
|
||||||
|
ifaces = ifaces.trim().toLowerCase().replace(/,+/g, '|');
|
||||||
|
ifacesArray = ifaces.split('|');
|
||||||
|
}
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
const workload = [];
|
const workload = [];
|
||||||
|
|||||||
@ -99,7 +99,7 @@ function services(srv, callback) {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
if (typeof srv !== "string") {
|
if (typeof srv !== 'string') {
|
||||||
if (callback) { callback([]); }
|
if (callback) { callback([]); }
|
||||||
return resolve([]);
|
return resolve([]);
|
||||||
}
|
}
|
||||||
@ -892,6 +892,13 @@ function processLoad(proc, callback) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
|
||||||
|
proc = proc || '';
|
||||||
|
|
||||||
|
if (typeof proc !== 'string') {
|
||||||
|
if (callback) { callback([]); }
|
||||||
|
return resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
let processesString = '';
|
let processesString = '';
|
||||||
processesString.__proto__.toLowerCase = util.stringToLower;
|
processesString.__proto__.toLowerCase = util.stringToLower;
|
||||||
processesString.__proto__.replace = util.stringReplace;
|
processesString.__proto__.replace = util.stringReplace;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user