Skip to content

Commit ec7bf3d

Browse files
authored
Merge pull request #7055 from BitGo/DX-1558-Replace-Request-With-Axios
Dx 1558 replace vulnerable request package with axios
2 parents d9d167b + ef5121f commit ec7bf3d

File tree

3 files changed

+30
-55
lines changed

3 files changed

+30
-55
lines changed

modules/bitgo/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@
154154
"keccak": "3.0.3",
155155
"libsodium-wrappers-sumo": "^0.7.9",
156156
"puppeteer": "2.1.1",
157-
"q": "^1.1.2",
158-
"request": "^2.88.0",
159-
"request-promise": "^4.2.2"
157+
"q": "^1.1.2"
160158
},
161159
"optionalDependencies": {
162160
"@ethereumjs/common": "^2.6.5",

modules/bitgo/test/unit/bitgo.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { common, generateGPGKeyPair } from '@bitgo/sdk-core';
1111
import { bip32, ECPair } from '@bitgo/utxo-lib';
1212
import * as _ from 'lodash';
1313
import * as BitGoJS from '../../src/index';
14-
const rp = require('request-promise');
14+
import axios from 'axios';
1515

1616
import { TestBitGo } from '@bitgo/sdk-test';
1717
import { BitGo } from '../../src/bitgo';
@@ -473,27 +473,26 @@ describe('BitGo Prototype Methods', function () {
473473
timestamp: '1521590532925',
474474
});
475475

476-
const responseData = (await rp({
477-
uri: url,
478-
method: 'GET',
476+
const response = await axios.get(url, {
479477
headers: requestHeaders,
480-
transform: (body, response) => {
481-
// verify the response headers
482-
const url = response.request.href;
483-
const hmac = response.headers.hmac;
484-
const timestamp = response.headers.timestamp;
485-
const statusCode = response.statusCode;
486-
const verificationParams = {
487-
url,
488-
hmac,
489-
timestamp,
490-
token,
491-
statusCode,
492-
text: body,
493-
};
494-
return bitgo.verifyResponse(verificationParams);
495-
},
496-
})) as any;
478+
transformResponse: [],
479+
});
480+
481+
const finalUrl = response.request.responseURL || url;
482+
const hmac = response.headers.hmac;
483+
const timestamp = response.headers.timestamp;
484+
const statusCode = response.status;
485+
486+
const verificationParams = {
487+
url: finalUrl,
488+
hmac,
489+
timestamp,
490+
token,
491+
statusCode,
492+
text: response.data,
493+
};
494+
495+
const responseData = bitgo.verifyResponse(verificationParams) as any;
497496
responseData.signatureSubject.should.equal(
498497
'1521590532925|/api/v2/tltc/wallet/5941b202b42fcbc707170d5b597491d9/address/QNc4RFAcbvqmtrR1kR2wbGLCx6tEvojFYE?segwit=1|200|{"id":"5a7ca8bcaf52c8e807c575fb692609ec","address":"QNc4RFAcbvqmtrR1kR2wbGLCx6tEvojFYE","chain":0,"index":2,"coin":"tltc","wallet":"5941b202b42fcbc707170d5b597491d9","coinSpecific":{"redeemScript":"522102835bcfd130f7a56f72c905b782d90b66e22f88ad3309cf72af5138a7d44be8b3210322c7f42a1eb212868eab78db7ba64846075d98c7f4c7aa25a02e57871039e0cd210265825be0d5bf957fb72abd7c23bf0836a78a15f951a073467cd5c99e03ce7ab753ae"},"balance":{"updated":"2018-02-28T23:48:07.341Z","numTx":1,"numUnspents":1,"totalReceived":20000000}}'
499498
);

yarn.lock

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18057,24 +18057,7 @@ request-progress@^3.0.0:
1805718057
dependencies:
1805818058
throttleit "^1.0.0"
1805918059

18060-
18061-
version "1.1.4"
18062-
resolved "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.4.tgz"
18063-
integrity sha512-TTbAfBBRdWD7aNNOoVOBH4pN/KigV6LyapYNNlAPA8JwbovRti1E88m3sYAwsLi5ryhPKsE9APwnjFTgdUjTpw==
18064-
dependencies:
18065-
lodash "^4.17.19"
18066-
18067-
request-promise@^4.2.2:
18068-
version "4.2.6"
18069-
resolved "https://registry.npmjs.org/request-promise/-/request-promise-4.2.6.tgz"
18070-
integrity sha512-HCHI3DJJUakkOr8fNoCc73E5nU5bqITjOYFMDrKHYOXWXrgD/SBaC7LjwuPymUprRyuF06UK7hd/lMHkmUXglQ==
18071-
dependencies:
18072-
bluebird "^3.5.0"
18073-
request-promise-core "1.1.4"
18074-
stealthy-require "^1.1.1"
18075-
tough-cookie "^2.3.3"
18076-
18077-
request@^2.79.0, request@^2.88.0:
18060+
request@^2.79.0:
1807818061
version "2.88.2"
1807918062
resolved "https://registry.npmjs.org/request/-/request-2.88.2.tgz"
1808018063
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
@@ -19218,11 +19201,6 @@ [email protected]:
1921819201
resolved "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz"
1921919202
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
1922019203

19221-
stealthy-require@^1.1.1:
19222-
version "1.1.1"
19223-
resolved "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz"
19224-
integrity sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g==
19225-
1922619204
stellar-base@^8.2.2:
1922719205
version "8.2.2"
1922819206
resolved "https://registry.npmjs.org/stellar-base/-/stellar-base-8.2.2.tgz"
@@ -20014,21 +19992,21 @@ tonweb@^0.0.62:
2001419992
node-fetch "2.6.7"
2001519993
tweetnacl "1.0.3"
2001619994

20017-
tough-cookie@^2.3.3, tough-cookie@~2.5.0:
20018-
version "2.5.0"
20019-
resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz"
20020-
integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==
20021-
dependencies:
20022-
psl "^1.1.28"
20023-
punycode "^2.1.1"
20024-
2002519995
tough-cookie@^5.0.0:
2002619996
version "5.1.2"
2002719997
resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz"
2002819998
integrity sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==
2002919999
dependencies:
2003020000
tldts "^6.1.32"
2003120001

20002+
tough-cookie@~2.5.0:
20003+
version "2.5.0"
20004+
resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz"
20005+
integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==
20006+
dependencies:
20007+
psl "^1.1.28"
20008+
punycode "^2.1.1"
20009+
2003220010
tr46@~0.0.3:
2003320011
version "0.0.3"
2003420012
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"

0 commit comments

Comments
 (0)