Skip to content

Commit cb046aa

Browse files
feat(root): add @bitgo/logger with sensitive data sanitization
Created @bitgo/logger package that automatically sanitizes sensitive data (tokens, private keys, passwords) in test/staging environments. Changes: - Added logger to 5 modules: express, sdk-coin-apt, sdk-coin-sol, sdk-coin-vet, blockapis - Replaced 17 console.error/log statements with logger calls - Sanitizes keys: token, bearer, prv, xprv, privateKey, password, otp - Works recursively on nested objects/arrays TICKET: WP-7503
1 parent 8b4a279 commit cb046aa

27 files changed

Lines changed: 257 additions & 17 deletions

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ COPY --from=builder /tmp/bitgo/modules/statics /var/modules/statics/
4848
COPY --from=builder /tmp/bitgo/modules/utxo-lib /var/modules/utxo-lib/
4949
COPY --from=builder /tmp/bitgo/modules/blake2b /var/modules/blake2b/
5050
COPY --from=builder /tmp/bitgo/modules/blake2b-wasm /var/modules/blake2b-wasm/
51+
COPY --from=builder /tmp/bitgo/modules/logger /var/modules/logger/
5152
COPY --from=builder /tmp/bitgo/modules/bitgo /var/modules/bitgo/
5253
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
5354
COPY --from=builder /tmp/bitgo/modules/blockapis /var/modules/blockapis/
@@ -147,6 +148,7 @@ cd /var/modules/statics && yarn link && \
147148
cd /var/modules/utxo-lib && yarn link && \
148149
cd /var/modules/blake2b && yarn link && \
149150
cd /var/modules/blake2b-wasm && yarn link && \
151+
cd /var/modules/logger && yarn link && \
150152
cd /var/modules/bitgo && yarn link && \
151153
cd /var/modules/abstract-utxo && yarn link && \
152154
cd /var/modules/blockapis && yarn link && \
@@ -249,6 +251,7 @@ RUN cd /var/bitgo-express && \
249251
yarn link @bitgo/utxo-lib && \
250252
yarn link @bitgo/blake2b && \
251253
yarn link @bitgo/blake2b-wasm && \
254+
yarn link @bitgo/logger && \
252255
yarn link bitgo && \
253256
yarn link @bitgo/abstract-utxo && \
254257
yarn link @bitgo/blockapis && \

modules/blockapis/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"directory": "modules/blockapis"
2323
},
2424
"dependencies": {
25+
"@bitgo/logger": "^1.0.0",
2526
"@bitgo/utxo-lib": "^11.20.0",
2627
"@types/superagent": "4.1.16",
2728
"superagent": "^9.0.1"

modules/blockapis/src/BaseHttpClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as superagent from 'superagent';
2+
import { logger } from '@bitgo/logger';
23

34
export class ApiRequestError extends Error {
45
constructor(public url: string, public reason: Error | string) {
@@ -64,7 +65,7 @@ export class BaseHttpClient implements HttpClient {
6465
try {
6566
response = await superagent(method, url).send(requestBody as Record<string, unknown>);
6667
} catch (e) {
67-
console.error(e);
68+
logger.error(e);
6869
throw new ApiRequestError(url, e as Error);
6970
}
7071
if (!response.ok) {

modules/express/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@api-ts/io-ts-http": "^3.2.1",
4141
"@api-ts/typed-express-router": "2.0.0",
4242
"@bitgo/abstract-lightning": "^7.7.0",
43+
"@bitgo/logger": "^1.0.0",
4344
"@bitgo/sdk-core": "^36.30.0",
4445
"@bitgo/utxo-lib": "^11.20.0",
4546
"@types/proxyquire": "^1.3.31",

modules/express/src/clientRoutes.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @prettier
33
*/
4+
import { logger } from '@bitgo/logger';
45
import {
56
CommitmentShareRecord,
67
CreateNetworkConnectionParams,
@@ -491,7 +492,7 @@ export async function handleV2GenerateShareTSS(
491492
throw new Error(`MPC Algorithm ${coin.getMPCAlgorithm()} is not supported.`);
492493
}
493494
} catch (error) {
494-
console.error('error while signing wallet transaction ', error);
495+
logger.error('error while signing wallet transaction', error);
495496
throw error;
496497
}
497498
}
@@ -504,7 +505,7 @@ export async function handleV2SignTSSWalletTx(req: ExpressApiRouteRequest<'expre
504505
try {
505506
return await wallet.ensureCleanSigSharesAndSignTransaction(createTSSSendParams(req, wallet));
506507
} catch (error) {
507-
console.error('error while signing wallet transaction ', error);
508+
logger.error('error while signing wallet transaction', error);
508509
throw error;
509510
}
510511
}
@@ -536,7 +537,7 @@ export async function handleV2Sign(req: ExpressApiRouteRequest<'express.v2.coin.
536537
try {
537538
return await coin.signTransaction({ ...req.body, prv: privKey });
538539
} catch (error) {
539-
console.log('error while signing wallet transaction ', error);
540+
logger.error('error while signing wallet transaction', error);
540541
throw error;
541542
}
542543
}
@@ -586,7 +587,7 @@ export async function handleV2OFCSignPayloadInExtSigningMode(
586587
signature,
587588
};
588589
} catch (error) {
589-
console.log('Error while signing message.', error);
590+
logger.error('Error while signing message', error);
590591
throw error;
591592
}
592593
}
@@ -730,7 +731,7 @@ async function handleV2SignTxWallet(req: ExpressApiRouteRequest<'express.v2.wall
730731
try {
731732
return await wallet.signTransaction(createSendParams(req));
732733
} catch (error) {
733-
console.log('error while signing wallet transaction ', error);
734+
logger.error('error while signing wallet transaction', error);
734735
throw error;
735736
}
736737
}
@@ -745,7 +746,7 @@ async function handleV2SignTx(req: ExpressApiRouteRequest<'express.v2.coin.signt
745746
try {
746747
return await coin.signTransaction(req.decoded);
747748
} catch (error) {
748-
console.log('error while signing the transaction ', error);
749+
logger.error('error while signing the transaction', error);
749750
throw error;
750751
}
751752
}

modules/express/src/fetchEncryptedPrivKeys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright 2022, BitGo, Inc. All Rights Reserved.
99
*/
1010
import { writeFile } from 'fs';
11+
import { logger } from '@bitgo/logger';
1112
import { BitGo, EnvironmentName } from 'bitgo';
1213
import 'dotenv/config';
1314

@@ -112,4 +113,4 @@ export async function fetchKeys(ids: WalletIds, token: string, accessToken?: str
112113
return Promise.resolve(output);
113114
}
114115

115-
fetchKeys(walletIds, accessToken).catch((e) => console.error(e));
116+
fetchKeys(walletIds, accessToken).catch((e) => logger.error(e));

modules/logger/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

modules/logger/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
.nyc_output
4+
*.log

modules/logger/.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
src
2+
test
3+
.eslintignore
4+
.gitignore
5+
.prettierignore
6+
.prettierrc.yml
7+
.mocharc.js
8+
tsconfig.json
9+
.nyc_output

modules/logger/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

0 commit comments

Comments
 (0)