Skip to content

Commit 4f22813

Browse files
authored
Merge pull request #142 from BitGo/WP-6567
fix(mbe): enforce an input check for send many pub keys
2 parents 8b42b65 + eb46327 commit 4f22813

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/__tests__/api/master/sendMany.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,4 +770,48 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
770770
sinon.assert.calledOnce(verifyStub);
771771
signNock.done();
772772
});
773+
774+
it('should throw an error when neither the pubkey nor the commonKeychain is provided', async () => {
775+
const walletGetNock = nock(bitgoApiUrl)
776+
.get(`/api/v2/${coin}/wallet/${walletId}`)
777+
.matchHeader('any', () => true)
778+
.reply(200, {
779+
id: walletId,
780+
type: 'advanced',
781+
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
782+
});
783+
784+
// Mock keychain get request
785+
const keychainGetNock = nock(bitgoApiUrl)
786+
.get(`/api/v2/${coin}/key/user-key-id`)
787+
.matchHeader('any', () => true)
788+
.reply(200, {
789+
id: 'user-key-id',
790+
pub: 'xpub_user',
791+
});
792+
793+
const response = await agent
794+
.post(`/api/${coin}/wallet/${walletId}/sendMany`)
795+
.set('Authorization', `Bearer ${accessToken}`)
796+
.send({
797+
recipients: [
798+
{
799+
address: 'tb1qtest1',
800+
amount: '100000',
801+
},
802+
],
803+
source: 'user',
804+
});
805+
806+
console.log(response.body);
807+
response.status.should.equal(400);
808+
response.body.should.have.property('error');
809+
response.body.error.should.equal('BadRequestError');
810+
response.body.details.should.equal(
811+
'Either pubkey or commonKeychain must be provided for user signing',
812+
);
813+
814+
walletGetNock.done();
815+
keychainGetNock.done();
816+
});
773817
});

src/masterBitgoExpress/handlers/handleSendMany.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
103103
if (!signingKeychain) {
104104
throw new NotFoundError(`Signing keychain for ${params.source} not found`);
105105
}
106+
if (!params.pubkey && !params.commonKeychain) {
107+
throw new BadRequestError(
108+
`Either pubkey or commonKeychain must be provided for ${params.source} signing`,
109+
);
110+
}
106111
if (params.pubkey && signingKeychain.pub !== params.pubkey) {
107112
throw new BadRequestError(
108113
`Pub provided does not match the keychain on wallet for ${params.source}`,

0 commit comments

Comments
 (0)