Skip to content

Commit 97482a0

Browse files
authored
fix: prevent sensitive data leakage in error logs (#5948)
1 parent 31a9ba6 commit 97482a0

File tree

6 files changed

+29
-80
lines changed

6 files changed

+29
-80
lines changed

packages/sync-server/src/app-gocardless/app-gocardless.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'path';
2-
import { inspect } from 'util';
32

43
import { isAxiosError } from 'axios';
54
import express from 'express';
@@ -244,7 +243,7 @@ app.post(
244243
});
245244
break;
246245
case error instanceof GenericGoCardlessError:
247-
console.log('Something went wrong', inspect(error, { depth: null }));
246+
console.log('Something went wrong', error.message);
248247
sendErrorResponse({
249248
error_type: 'SYNC_ERROR',
250249
error_code: 'NORDIGEN_ERROR',
@@ -253,15 +252,16 @@ app.post(
253252
case isAxiosError(error):
254253
console.log(
255254
'Something went wrong',
256-
inspect(error.response?.data || error, { depth: null }),
255+
error.message,
256+
error.response?.data?.summary || error.response?.data?.detail || '',
257257
);
258258
sendErrorResponse({
259259
error_type: 'SYNC_ERROR',
260260
error_code: 'NORDIGEN_ERROR',
261261
});
262262
break;
263263
default:
264-
console.log('Something went wrong', inspect(error, { depth: null }));
264+
console.log('Something went wrong', error.message || String(error));
265265
sendErrorResponse({
266266
error_type: 'UNKNOWN',
267267
error_code: 'UNKNOWN',

packages/sync-server/src/app-gocardless/banks/integration-bank.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export default {
2222
institutionIds: ['IntegrationBank'],
2323

2424
normalizeAccount(account) {
25-
console.debug(
26-
'Available account properties for new institution integration',
27-
{ account: JSON.stringify(account) },
28-
);
29-
3025
return {
3126
account_id: account.id,
3227
institution: account.institution,
@@ -80,24 +75,10 @@ export default {
8075
},
8176

8277
sortTransactions(transactions = []) {
83-
console.debug(
84-
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
85-
{ top10Transactions: JSON.stringify(transactions.slice(0, 10)) },
86-
);
8778
return sortByBookingDateOrValueDate(transactions);
8879
},
8980

9081
calculateStartingBalance(sortedTransactions = [], balances = []) {
91-
console.debug(
92-
'Available (first 10) transactions properties for new integration of institution in calculateStartingBalance function',
93-
{
94-
balances: JSON.stringify(balances),
95-
top10SortedTransactions: JSON.stringify(
96-
sortedTransactions.slice(0, 10),
97-
),
98-
},
99-
);
100-
10182
const currentBalance = balances
10283
.filter(item => SORTED_BALANCE_TYPE_LIST.includes(item.balanceType))
10384
.sort(

packages/sync-server/src/app-gocardless/banks/tests/integration_bank.spec.js

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import {
55
import IntegrationBank from '../integration-bank.js';
66

77
describe('IntegrationBank', () => {
8-
let consoleSpy;
9-
10-
beforeEach(() => {
11-
consoleSpy = vi.spyOn(console, 'debug');
12-
});
13-
148
describe('normalizeAccount', () => {
159
const account = mockExtendAccountsAboutInstitutions[0];
1610

@@ -42,16 +36,6 @@ describe('IntegrationBank', () => {
4236
type: 'checking',
4337
});
4438
});
45-
46-
it('normalizeAccount logs available account properties', () => {
47-
IntegrationBank.normalizeAccount(account);
48-
expect(consoleSpy).toHaveBeenCalledWith(
49-
'Available account properties for new institution integration',
50-
{
51-
account: JSON.stringify(account),
52-
},
53-
);
54-
});
5539
});
5640

5741
describe('sortTransactions', () => {
@@ -72,35 +56,26 @@ describe('IntegrationBank', () => {
7256
transactionAmount: { amount: '100', currency: 'EUR' },
7357
},
7458
];
75-
const sortedTransactions = [
76-
{
77-
date: '2022-01-03',
78-
bookingDate: '2022-01-03',
79-
transactionAmount: { amount: '100', currency: 'EUR' },
80-
},
81-
{
82-
date: '2022-01-02',
83-
bookingDate: '2022-01-02',
84-
transactionAmount: { amount: '100', currency: 'EUR' },
85-
},
86-
{
87-
date: '2022-01-01',
88-
bookingDate: '2022-01-01',
89-
transactionAmount: { amount: '100', currency: 'EUR' },
90-
},
91-
];
9259

9360
it('should return transactions sorted by bookingDate', () => {
9461
const sortedTransactions = IntegrationBank.sortTransactions(transactions);
95-
expect(sortedTransactions).toEqual(sortedTransactions);
96-
});
97-
98-
it('sortTransactions logs available transactions properties', () => {
99-
IntegrationBank.sortTransactions(transactions);
100-
expect(consoleSpy).toHaveBeenCalledWith(
101-
'Available (first 10) transactions properties for new integration of institution in sortTransactions function',
102-
{ top10Transactions: JSON.stringify(sortedTransactions.slice(0, 10)) },
103-
);
62+
expect(sortedTransactions).toEqual([
63+
{
64+
date: '2022-01-03',
65+
bookingDate: '2022-01-03',
66+
transactionAmount: { amount: '100', currency: 'EUR' },
67+
},
68+
{
69+
date: '2022-01-02',
70+
bookingDate: '2022-01-02',
71+
transactionAmount: { amount: '100', currency: 'EUR' },
72+
},
73+
{
74+
date: '2022-01-01',
75+
bookingDate: '2022-01-01',
76+
transactionAmount: { amount: '100', currency: 'EUR' },
77+
},
78+
]);
10479
});
10580
});
10681

@@ -141,16 +116,5 @@ describe('IntegrationBank', () => {
141116
);
142117
expect(startingBalance).toEqual(70000);
143118
});
144-
145-
it('logs available transactions and balances properties', () => {
146-
IntegrationBank.calculateStartingBalance(transactions, balances);
147-
expect(consoleSpy).toHaveBeenCalledWith(
148-
'Available (first 10) transactions properties for new integration of institution in calculateStartingBalance function',
149-
{
150-
balances: JSON.stringify(balances),
151-
top10SortedTransactions: JSON.stringify(transactions.slice(0, 10)),
152-
},
153-
);
154-
});
155119
});
156120
});

packages/sync-server/src/app-gocardless/util/handle-error.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { inspect } from 'util';
2-
31
export function handleError(func) {
42
return (req, res) => {
53
func(req, res).catch(err => {
6-
console.log('Error', req.originalUrl, inspect(err, { depth: null }));
4+
console.log('Error', req.originalUrl, err.message || String(err));
75
res.send({
86
status: 'ok',
97
data: {

packages/sync-server/src/app-simplefin/app-simplefin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function parseAccessKey(accessKey) {
294294
let password = null;
295295
let baseUrl = null;
296296
if (!accessKey || !accessKey.match(/^.*\/\/.*:.*@.*$/)) {
297-
console.log(`Invalid SimpleFIN access key: ${accessKey}`);
297+
console.log('Invalid SimpleFIN access key');
298298
throw new Error(`Invalid access key`);
299299
}
300300
[scheme, rest] = accessKey.split('//');

upcoming-release-notes/5948.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Enhancements
3+
authors: [MatissJanis]
4+
---
5+
6+
Remove sensitive data logging from sync-server

0 commit comments

Comments
 (0)