Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Dont log apikey in default logger - Bon-61533 (#31)
Browse files Browse the repository at this point in the history
* Dont log apikey - Bon-61533
  • Loading branch information
BN-CRehn authored Aug 17, 2022
1 parent 2fd417c commit ef59b43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/splat-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function splatEntry(info) {
info.metaData = message.pop();
}
}
info.message = util.format(info.message, ...message);
const noapikey =
/(["]?(x-)?api-key["]?[:=]["]?)(([\s]?["]?[0-9a-fA-F]){8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}["]?)/gi;
info.message = util.format(info.message, ...message).replace(noapikey, /\1SECRET/);

if (!config.pretty) {
info.message = info.message.replace(/\n\s*/gm, " ");
Expand Down
28 changes: 28 additions & 0 deletions test/feature/logging-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ Feature("Logging", () => {
});
});

Scenario("Logging an api-key", () => {
const message = "Message";
const data = "x-api-key:8a1ba457-24bc-4941-b136-d401a717c223";

When("logging a huge message", () => {
logger.debug(message, data);
});

Then("log output should be trimmed", () => {
const logContent = transport.logs.shift();
logContent.message.should.equal("Message /\\1SECRET/");
});
});

Scenario("Logging an api-key as message", () => {
const message = "x-api-key:8a1ba457-24bc-4941-b136-d401a717c223";
const data = "some-data";

When("logging a huge message", () => {
logger.debug(message, data);
});

Then("log output should be trimmed", () => {
const logContent = transport.logs.shift();
logContent.message.should.equal("/\\1SECRET/ some-data");
});
});

Scenario("Should support prefixed package names", () => {
let newLogger;

Expand Down

0 comments on commit ef59b43

Please sign in to comment.