@envoy/envoy-integrations-sdk 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yaml +15 -0
- package/index.js +2 -0
- package/lib/axios.js +23 -0
- package/package.json +6 -4
- package/test/axios.test.js +54 -0
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const HttpStatus = require('./lib/HttpStatus');
|
|
|
11
11
|
const middleware = require('./lib/middleware');
|
|
12
12
|
const errorMiddleware = require('./lib/errorMiddleware');
|
|
13
13
|
const asyncHandler = require('./lib/asyncHandler');
|
|
14
|
+
const createAxiosClient = require('./lib/axios');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @typedef {Object} Envoy
|
|
@@ -44,4 +45,5 @@ module.exports = {
|
|
|
44
45
|
middleware,
|
|
45
46
|
errorMiddleware,
|
|
46
47
|
asyncHandler,
|
|
48
|
+
createAxiosClient,
|
|
47
49
|
};
|
package/lib/axios.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { AxiosError } = require('axios');
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
|
|
4
|
+
function createAxiosClient(config) {
|
|
5
|
+
const client = axios.create(config);
|
|
6
|
+
client.interceptors.response.use(
|
|
7
|
+
(response) => {
|
|
8
|
+
return response
|
|
9
|
+
},
|
|
10
|
+
(error) => {
|
|
11
|
+
// if the response class type is AxiosError, scrub config fields containing sensitive data
|
|
12
|
+
if (error instanceof AxiosError) {
|
|
13
|
+
delete error.config.headers;
|
|
14
|
+
delete error.config.proxy;
|
|
15
|
+
}
|
|
16
|
+
return Promise.reject(error);
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return client;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = createAxiosClient;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envoy/envoy-integrations-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "jest"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/envoy/envoy-integrations-sdk-nodejs#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"axios": "^1.4.0",
|
|
20
21
|
"body-parser": "^1.19.0",
|
|
21
22
|
"dotenv": "^8.1.0",
|
|
22
|
-
"jsonwebtoken": "^
|
|
23
|
+
"jsonwebtoken": "^9.0.0",
|
|
23
24
|
"request": "^2.88.0",
|
|
24
25
|
"request-promise-native": "^1.0.7"
|
|
25
26
|
},
|
|
@@ -28,8 +29,9 @@
|
|
|
28
29
|
"eslint": "^5.16.0",
|
|
29
30
|
"eslint-config-airbnb-base": "^13.1.0",
|
|
30
31
|
"eslint-plugin-import": "^2.17.3",
|
|
32
|
+
"jest": "^29.5.0",
|
|
31
33
|
"jsdoc-to-markdown": "^5.0.0",
|
|
32
|
-
"mocha": "^
|
|
34
|
+
"mocha": "^10.2.0",
|
|
33
35
|
"proxyquire": "^2.1.0",
|
|
34
36
|
"sinon": "^7.3.2"
|
|
35
37
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const createClient = require('../lib/axios')
|
|
3
|
+
|
|
4
|
+
describe('axios', () => {
|
|
5
|
+
it('default client should leak credentials in AxiosError', async () => {
|
|
6
|
+
const client = axios.create({
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: 'Bearer 1234',
|
|
9
|
+
},
|
|
10
|
+
proxy: {
|
|
11
|
+
host: 'localhost',
|
|
12
|
+
auth: {
|
|
13
|
+
username: 'myWhackyUsername',
|
|
14
|
+
password: 'myWhackyPassword',
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
await client.get('http://localhost:3000/axios-error');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
expect(error.config.headers).toBeDefined();
|
|
22
|
+
expect(error.config.proxy).toBeDefined();
|
|
23
|
+
const errorStr = JSON.stringify(error);
|
|
24
|
+
expect(errorStr).toContain('Bearer 1234');
|
|
25
|
+
expect(errorStr).toContain('myWhackyUsername');
|
|
26
|
+
expect(errorStr).toContain('myWhackyPassword');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should sanitize AxiosError response', async () => {
|
|
31
|
+
const client = createClient({
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: 'Bearer 1234',
|
|
34
|
+
},
|
|
35
|
+
proxy: {
|
|
36
|
+
host: 'localhost',
|
|
37
|
+
auth: {
|
|
38
|
+
username: 'myWhackyUsername',
|
|
39
|
+
password: 'myWhackyPassword',
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
await client.get('http://localhost:3000/axios-error');
|
|
45
|
+
} catch (error) {
|
|
46
|
+
expect(error.config.headers).toBeUndefined();
|
|
47
|
+
expect(error.config.proxy).toBeUndefined();
|
|
48
|
+
const errorStr = JSON.stringify(error);
|
|
49
|
+
expect(errorStr).not.toContain('Bearer 1234');
|
|
50
|
+
expect(errorStr).not.toContain('myWhackyUsername');
|
|
51
|
+
expect(errorStr).not.toContain('myWhackyPassword');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|