Skip to content

Commit 11f21de

Browse files
fix webhook plugin vulnerabilities (#570)
* fix webhook plugin vulnerabilities * bump
1 parent e3362cf commit 11f21de

File tree

9 files changed

+251
-334
lines changed

9 files changed

+251
-334
lines changed

incubating/webhook/.eslintrc.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
{
2-
"extends": "airbnb-base"
2+
"extends": "airbnb-base",
3+
"rules": {
4+
"indent": [ "error", 4 ],
5+
"class-methods-use-this": "off",
6+
"max-len": "off",
7+
"no-underscore-dangle": "off"
8+
},
9+
"settings": {
10+
"import/resolver": {
11+
"node": {
12+
"extensions": [".js", ".jsx", ".ts", ".tsx"],
13+
"moduleDirectory": ["node_modules", "src/"]
14+
}
15+
}
16+
}
317
}

incubating/webhook/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14.21.1-bullseye-slim
1+
FROM node:14.21.3-bullseye-slim
22

33
#RUN apk add --no-cache bash git openssh-client
44

incubating/webhook/helpers/codefresh.api.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
const request = require('request-promise');
1+
const got = require('got');
22

33
class Codefresh {
44
/**
55
*
6-
* @return {{build: {trigger: *, initiator: *, id: *, timestamp: *, url: *}, repo: {owner: *, name: *}, commit: {author: *, url: *, message: *}, revision: *, branch: *, apiKey: *}}
6+
* @return {{
7+
* build: {trigger: *, initiator: *, id: *, timestamp: *, url: *},
8+
* repo: {owner: *, name: *},
9+
* commit: {author: *, url: *, message: *},
10+
* revision: *,
11+
* branch: *,
12+
* apiKey: *
13+
* }}
714
*/
815
get info() {
916
return {
@@ -26,20 +33,22 @@ class Codefresh {
2633
revision: process.env.CF_REVISION,
2734
branch: process.env.CF_BRANCH_TAG_NORMALIZED,
2835
apiKey: process.env.CF_API_KEY,
29-
cfUrl: process.env.CF_URL
36+
cfUrl: process.env.CF_URL,
3037
};
3138
}
3239

3340
async buildFailureCauses(buildId, token, cfUrl) {
3441
console.log(token, buildId);
35-
const data = await request({
36-
uri: `${cfUrl}/api/workflow/${buildId}/context-revision`,
37-
method: 'GET',
38-
headers: {
39-
'authorization': token,
42+
43+
const data = await got(
44+
{
45+
url: `${cfUrl}/api/workflow/${buildId}/context-revision`,
46+
method: 'GET',
47+
headers: {
48+
authorization: token,
49+
},
4050
},
41-
json: true,
42-
});
51+
).json();
4352

4453
return Object.entries(data.pop().context.stepsMetadata)
4554
.filter(([, stepInfo]) => stepInfo.status === 'failure')

incubating/webhook/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const pluginController = require('./plugin/plugin.controller');
22

33
pluginController.sendNotify()
4-
.then(console.log)
54
.catch(console.error);

incubating/webhook/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"json-schema": "0.4.0"
1111
},
1212
"dependencies": {
13-
"handlebars": "^4.7.7",
14-
"request": "^2.88.2",
15-
"request-promise": "^4.2.6"
13+
"got": "^11.8.3",
14+
"handlebars": "^4.7.7"
1615
},
1716
"devDependencies": {
1817
"eslint": "^4.18.2",

incubating/webhook/plugin/plugin.controller.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const pluginLogic = require('./plugin.logic');
33
const Codefresh = require('../helpers/codefresh.api');
44

55
class PluginController {
6-
76
constructor() {
87
this.sendNotify = this.sendNotify.bind(this);
98
}
@@ -46,7 +45,7 @@ class PluginController {
4645
this._validate();
4746
const isCorrectMethod = config.method && this._isAllowedMethod(config.method);
4847
const method = isCorrectMethod ? config.method : 'POST';
49-
const body = config.body;
48+
const { body } = config;
5049
const defaultHeaders = {
5150
'Content-Type': 'application/json',
5251
};
@@ -61,7 +60,6 @@ class PluginController {
6160
tplData,
6261
defaultHeaders,
6362
});
64-
6563
}
6664
}
6765

incubating/webhook/plugin/plugin.logic.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const config = require('../config');
2-
const request = require('request-promise');
1+
const got = require('got');
32
const Handlebars = require('handlebars');
3+
const config = require('../config');
44

55
class PluginLogic {
66
constructor() {
@@ -31,26 +31,17 @@ class PluginLogic {
3131
}, {});
3232
}
3333

34-
/**
35-
* Resolve options for auth
36-
* @return {*}
37-
* @private
38-
*/
39-
_resolveAuth() {
34+
_resolveAuthHeaders() {
4035
if (config.token) {
4136
return {
42-
auth: {
43-
bearer: config.token,
44-
},
37+
Authorization: `Bearer ${config.token}`,
4538
};
4639
}
4740

4841
if (config.username && config.password) {
42+
const base64Payload = Buffer.from(`${config.username}:${config.password}`).toString('base64');
4943
return {
50-
auth: {
51-
user: config.username,
52-
pass: config.password,
53-
},
44+
Authorization: `Basic ${base64Payload}`,
5445
};
5546
}
5647

@@ -77,14 +68,20 @@ class PluginLogic {
7768
* @param tplData
7869
* @return {Promise<void>}
7970
*/
80-
sendRequest({ uri, method, body, tplData = {}, defaultHeaders = {} }) {
81-
return request({
82-
uri,
71+
72+
sendRequest({
73+
uri, method, body, tplData = {}, defaultHeaders = {},
74+
}) {
75+
return got({
76+
url: uri,
8377
method,
8478
body: this._processTemplate(body, tplData),
85-
qs: this._resolveEnvArray('QUERY', tplData),
86-
headers: Object.assign(defaultHeaders, this._resolveEnvArray('HEADER', tplData)),
87-
...this._resolveAuth(),
79+
searchParams: this._resolveEnvArray('QUERY', tplData),
80+
headers: Object.assign(
81+
defaultHeaders,
82+
this._resolveAuthHeaders(),
83+
this._resolveEnvArray('HEADER', tplData),
84+
),
8885
});
8986
}
9087
}

incubating/webhook/step.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: webhook
55
title: Call a custom webhook
66
latest: true
7-
version: 0.0.11
7+
version: 0.0.12
88
isPublic: true
99
description: Notify any webook URL with any custom request body.
1010
sources:
@@ -70,7 +70,7 @@ spec:
7070
steps:
7171
main:
7272
name: webhook
73-
image: quay.io/codefreshplugins/webhook-plugin:0.0.11
73+
image: quay.io/codefreshplugins/webhook-plugin:0.0.12
7474
environment:
7575
- 'WEBHOOK_USERNAME=${{WEBHOOK_USERNAME}}'
7676
- 'WEBHOOK_PASSWORD=${{WEBHOOK_PASSWORD}}'

0 commit comments

Comments
 (0)