Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Censor sensitive numbers #152

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tools/cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const recurseCleanFuncs = (obj, path) => {
// Recurse a nested object replace all instances of keys->vals in the bank.
const recurseReplaceBank = (obj, bank = {}) => {
const replacer = out => {
if (typeof out === 'number') {
out = String(out);
}
if (typeof out !== 'string') {
return out;
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/create-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const makeSensitiveBank = (event, data) => {
// keeps short values from spamming censor strings in logs, < 6 chars is not a proper secret
// see https://github.com/zapier/zapier-platform-core/issues/4#issuecomment-277855071
if (val && String(val).length > 5) {
val = String(val);
const censored = hashing.snipify(val);
bank[val] = censored;
bank[encodeURIComponent(val)] = censored;
Expand Down
35 changes: 35 additions & 0 deletions test/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,41 @@ describe('logger', () => {
});
});

it('should replace sensitive data that is not a string', () => {
const bundle = {
authData: {
numerical_token: 314159265
}
};
const logger = createlogger({ bundle }, options);

const data = {
response_json: {
hello: 314159265
},
response_content: `{
"hello": 314159265
}`
};

return logger('test', data).then(response => {
response.status.should.eql(200);
response.content.json.should.eql({
token: options.token,
message: 'test',
data: {
response_json: {
hello: ':censored:9:9cb84e8ccc:'
},
response_content: `{
"hello": :censored:9:9cb84e8ccc:
}`,
log_type: 'console'
}
});
});
});

it('should not replace safe log keys', () => {
const bundle = {
authData: {
Expand Down