Skip to content

Commit

Permalink
feat: redact 'accessToken' and 'apiKey'
Browse files Browse the repository at this point in the history
  • Loading branch information
KatoakDR committed Jan 22, 2024
1 parent d7baa9e commit 42488ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions electron/common/logger/__tests__/logger-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ describe('logger-format', () => {
it('should mask sensitive values', () => {
const data = {
password: 'secret',
key: 'secret',
apiKey: 'secret',
};

const result = formatLogData(data);

expect(result).toEqual({
password: '***REDACTED***',
key: '***REDACTED***',
apiKey: '***REDACTED***',
});
});
});
Expand Down
22 changes: 11 additions & 11 deletions electron/common/logger/__tests__/logger-mask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import { isNotMaskable, maskSensitiveValues } from '../logger.mask';
describe('logger-mask', () => {
describe('#maskSensitiveValues', () => {
const data: Record<string, any> = {
key: 'key1',
accessToken: 'accessToken1',
password: 'password1',
apiKey: 'apiKey1',
credential: 'credential1',
nested: {
key: 'key2',
accessToken: 'accessToken2',
password: 'password2',
apiKey: 'apiKey2',
credential: 'credential2',
},
};

it('should mask password and key properties by default', () => {
it('should mask password, accessToken, and apiKey properties by default', () => {
const result = maskSensitiveValues({
json: data,
});

expect(result).toEqual({
key: '***REDACTED***',
accessToken: '***REDACTED***',
password: '***REDACTED***',
apiKey: 'apiKey1',
apiKey: '***REDACTED***',
credential: 'credential1',
nested: {
key: '***REDACTED***',
accessToken: '***REDACTED***',
password: '***REDACTED***',
apiKey: 'apiKey2',
apiKey: '***REDACTED***',
credential: 'credential2',
},
});
Expand All @@ -41,12 +41,12 @@ describe('logger-mask', () => {
});

expect(result).toEqual({
key: 'key1',
accessToken: 'accessToken1',
password: 'password1',
apiKey: '***REDACTED***',
credential: '***REDACTED***',
nested: {
key: 'key2',
accessToken: 'accessToken2',
password: 'password2',
apiKey: '***REDACTED***',
credential: '***REDACTED***',
Expand All @@ -62,12 +62,12 @@ describe('logger-mask', () => {
});

expect(result).toEqual({
key: 'key1',
accessToken: 'accessToken1',
password: 'password1',
apiKey: '***MASKED***',
credential: '***MASKED***',
nested: {
key: 'key2',
accessToken: 'accessToken2',
password: 'password2',
apiKey: '***MASKED***',
credential: '***MASKED***',
Expand Down
6 changes: 5 additions & 1 deletion electron/common/logger/logger.mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export function maskSensitiveValues(options: {
*/
mask?: string;
}): any {
const { json, keys = ['password', 'key'], mask = '***REDACTED***' } = options;
const {
json,
keys = ['password', 'accessToken', 'apiKey'],
mask = '***REDACTED***',
} = options;

if (isNotMaskable(json)) {
return json;
Expand Down

0 comments on commit 42488ab

Please sign in to comment.