Skip to content

Commit 20dd723

Browse files
Cr 3219 - security vulnerabilities (#66)
* fix security vunrabilities * downgrade node to 10 * bump * trigger ci * moving to eslint * fix mocha * wip Co-authored-by: Oren Gurfinkel <[email protected]>
1 parent 4c7697f commit 20dd723

13 files changed

+1784
-2526
lines changed

.eslintrc

+68-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
// Codefresh Code Style - eslint ruleset
2-
// Based on AirBnB.
3-
//
4-
// More details: https://codefresh-io.atlassian.net/wiki/display/COD/Code+Style+Guide
51
{
6-
72
"extends": "airbnb",
3+
"ignorePatterns":[
4+
"node_modules"
5+
],
86
"parserOptions": {
9-
"ecmaVersion": 6,
7+
"ecmaVersion": 2018,
108
"sourceType": "script",
119
"ecmaFeatures": {
12-
"jsx": true
10+
"impliedStrict": true
1311
}
1412
},
1513

14+
"env": {
15+
"node": true,
16+
"mocha": true
17+
},
18+
19+
"plugins": [
20+
"chai-friendly",
21+
"import",
22+
"mocha",
23+
"node",
24+
"promise"
25+
],
26+
1627
"rules": {
1728
"indent": [
1829
"error",
@@ -33,15 +44,27 @@
3344
"allowTemplateLiterals": true
3445
}
3546
],
47+
"max-len": [
48+
2,
49+
{
50+
"code": 180,
51+
"tabWidth": 4,
52+
"ignoreUrls": true
53+
}
54+
],
55+
"no-use-before-define": "off",
56+
"no-plusplus": "off",
57+
"consistent-return": "warn",
58+
"class-methods-use-this": "off",
3659
"no-underscore-dangle": "off",
60+
"no-multi-spaces": "off",
3761
"no-param-reassign": "off",
3862
"no-else-return": "off",
3963
"arrow-body-style": "off",
4064
"strict": [
4165
"error",
4266
"global"
4367
],
44-
"no-multi-spaces": "off",
4568
"padded-blocks": "off",
4669
"import/no-extraneous-dependencies": [
4770
2,
@@ -52,6 +75,41 @@
5275
"guard-for-in": "error",
5376
"no-console": "off",
5477
"comma-dangle": ["error", "only-multiline"],
55-
"quote-props": ["error", "consistent"]
56-
}
78+
"quote-props": ["error", "consistent"],
79+
80+
"promise/catch-or-return": ["error", { "allowThen": true }],
81+
"promise/no-native": "error",
82+
83+
"mocha/no-exclusive-tests": "error",
84+
85+
"no-unused-expressions": "off",
86+
"chai-friendly/no-unused-expressions": "error",
87+
88+
"node/no-unsupported-features": "error",
89+
"node/process-exit-as-throw": "error",
90+
"node/shebang": "warn",
91+
"node/no-deprecated-api": "warn",
92+
"no-useless-constructor": "warn",
93+
"no-return-await": "off"
94+
},
95+
"overrides": [
96+
{
97+
"plugins": ["jest"],
98+
"env": {
99+
"jest": true
100+
},
101+
"files": [
102+
"**/__tests__/**/*.[jt]s?(x)",
103+
"__mocks__/**/*.js",
104+
"**/__mocks__/**/*.js"
105+
],
106+
"rules": {
107+
"jest/no-disabled-tests": "warn",
108+
"jest/no-focused-tests": "error",
109+
"jest/no-identical-title": "error",
110+
"jest/prefer-to-have-length": "warn",
111+
"jest/valid-expect": "error"
112+
}
113+
}
114+
]
57115
}

.jshintrc

-26
This file was deleted.

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM node:11.10.0-alpine
1+
FROM node:10.24.0-alpine3.11
22

33
WORKDIR /root/cf-runtime
44

5+
RUN apk -U upgrade
6+
57
RUN apk add --no-cache bash git openssh-client tini
68

79
COPY package.json ./

lib/ContainerLogger.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
2-
31
const EventEmitter = require('events');
42
const Q = require('q');
53
const logger = require('cf-logs').Logger('codefresh:containerLogger');
64
const CFError = require('cf-errors');
7-
const LoggerStrategy = require('./enums').LoggerStrategy;
85
const { Transform } = require('stream');
6+
const { LoggerStrategy } = require('./enums');
97

108
class ContainerLogger extends EventEmitter {
119

@@ -104,7 +102,7 @@ class ContainerLogger extends EventEmitter {
104102
logger.info(`Piping stdout and stderr step streams`);
105103

106104
const stepLoggerWritableStream = this.stepLogger.writeStream();
107-
stepLoggerWritableStream.on('error', err => logger.error(`stepLoggerWritableStream: ${err}`));
105+
stepLoggerWritableStream.on('error', (err) => logger.error(`stepLoggerWritableStream: ${err}`));
108106

109107
// Attention(!) all streams piped to step logger writable stream must be a new streams(!) in order to avoid message piping twice to writable stream.
110108
// { end = false } on the stepLoggerWritableStream because there is only one instance of it for all the steps.
@@ -113,9 +111,8 @@ class ContainerLogger extends EventEmitter {
113111
.pipe(this._logSizeLimitStream())
114112
.pipe(this.stepLogger.createMaskingStream())
115113
.pipe(this.stepLogger.stepNameTransformStream().once('end', this._handleFinished.bind(this)))
116-
.pipe(stepLoggerWritableStream, {end: false});
114+
.pipe(stepLoggerWritableStream, { end: false });
117115

118-
119116
if (!stderr) {
120117
return;
121118
}
@@ -126,7 +123,7 @@ class ContainerLogger extends EventEmitter {
126123
.pipe(this._errorTransformerStream())
127124
.pipe(this.stepLogger.createMaskingStream())
128125
.pipe(this.stepLogger.stepNameTransformStream().once('end', this._handleFinished.bind(this)))
129-
.pipe(stepLoggerWritableStream, {end: false});
126+
.pipe(stepLoggerWritableStream, { end: false });
130127

131128
stderr.once('end', () => {
132129
this.stepFinished = true;
@@ -150,9 +147,7 @@ class ContainerLogger extends EventEmitter {
150147
this.handledStreams++;
151148
stream.on('end', this._handleFinished.bind(this));
152149
stream.on('data', (chunk) => {
153-
const buf = new Buffer(chunk);
154-
const message = buf.toString('utf8');
155-
this._logMessage(message, isError);
150+
this._logMessage(Buffer.from(chunk).toString('utf-8'), isError);
156151
});
157152
logger.info(`Listening on stream 'data' event for container: ${this.containerId}`);
158153
}
@@ -166,7 +161,7 @@ class ContainerLogger extends EventEmitter {
166161
if (payload === null) {
167162
break;
168163
}
169-
this._logMessage(new Buffer(payload).toString('utf8'), isError);
164+
this._logMessage(Buffer.from(payload).toString('utf8'), isError);
170165
header = stream.read(8);
171166
}
172167
});
@@ -182,7 +177,9 @@ class ContainerLogger extends EventEmitter {
182177
if (this.logSizeLimit && (this._stepLogSizeExceeded() || this.isWorkflowLogSizeExceeded()) && !isError) {
183178
if (!this.logExceededLimitsNotified) {
184179
this.logExceededLimitsNotified = true;
185-
message = `\x1B[01;93mLog size exceeded for ${this._stepLogSizeExceeded() ? 'this step' : 'the workflow'}.\nThe step will continue to execute until it finished but new logs will not be stored.\x1B[0m\r\n`;
180+
message = `\x1B[01;93mLog size exceeded for ${this._stepLogSizeExceeded()
181+
? 'this step'
182+
: 'the workflow'}.\nThe step will continue to execute until it finished but new logs will not be stored.\x1B[0m\r\n`;
186183
} else {
187184
return;
188185
}
@@ -216,7 +213,9 @@ class ContainerLogger extends EventEmitter {
216213
if (this.logSizeLimit && (this._stepLogSizeExceeded() || this.isWorkflowLogSizeExceeded())) {
217214
if (!this.logExceededLimitsNotified) {
218215
this.logExceededLimitsNotified = true;
219-
const message = `\x1B[01;93mLog size exceeded for ${this._stepLogSizeExceeded() ? 'this step' : 'the workflow'}.\nThe step will continue to execute until it finished but new logs will not be stored.\x1B[0m\r\n`;
216+
const message = `\x1B[01;93mLog size exceeded for ${this._stepLogSizeExceeded()
217+
? 'this step'
218+
: 'the workflow'}.\nThe step will continue to execute until it finished but new logs will not be stored.\x1B[0m\r\n`;
220219
done(null, Buffer.from(message));
221220
return;
222221
}

lib/addNewMask.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const rp = require('request-promise');
22

3-
43
function updateMasks(secret) {
54
const port = process.env.PORT || 8080;
65
const host = process.env.HOST || 'localhost';
7-
6+
87
const opt = {
98
uri: `http://${host}:${port}/secrets`,
109
method: 'POST',
@@ -39,4 +38,4 @@ if (require.main === module) {
3938
updateMasks({ key, value });
4039
} else {
4140
module.exports = updateMasks;
42-
}
41+
}

lib/enums.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const ContainerStatus = {
42
CREATE: 'create'
53
};
@@ -13,10 +11,8 @@ const ContainerHandlingStatus = {
1311
LISTENING: 'listening'
1412
};
1513

16-
1714
module.exports = {
1815
ContainerStatus,
1916
LoggerStrategy,
2017
ContainerHandlingStatus
2118
};
22-

lib/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const path = require('path');
42
const cflogs = require('cf-logs');
53
const Q = require('q');
@@ -16,15 +14,16 @@ const loggerOptions = {
1614
cflogs.init(loggerOptions);
1715

1816
const Logger = require('./logger');
17+
1918
const buildFinishedPromise = Q.defer();
2019

2120
const logger = new Logger({
2221
loggerId: process.env.LOGGER_ID,
2322
taskLoggerConfig: JSON.parse(process.env.TASK_LOGGER_CONFIG),
2423
findExistingContainers: process.env.LISTEN_ON_EXISTING,
25-
logSizeLimit: process.env.LOG_SIZE_LIMIT ? (parseInt(process.env.LOG_SIZE_LIMIT) * 1000000) : undefined,
24+
logSizeLimit: process.env.LOG_SIZE_LIMIT ? (parseInt(process.env.LOG_SIZE_LIMIT, 10) * 1000000) : undefined,
2625
buildFinishedPromise: buildFinishedPromise.promise,
27-
showProgress: process.env.SHOW_PROGRESS === 'true' ? true : false,
26+
showProgress: process.env.SHOW_PROGRESS === 'true',
2827
});
2928

3029
logger.validate();
@@ -56,4 +55,4 @@ process.on('unhandledRejection', (reason) => {
5655
console.log(`unhandledRejection: ${reason}`);
5756
logger.state.unhandledRejection = reason;
5857
logger._writeNewState();
59-
});
58+
});

0 commit comments

Comments
 (0)