8000 refs #42: DON'T print sensitive info in trace log. · nullptr0-0/leetcode-cli@349b531 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 349b531

Browse files
committed
refs skygragon#42: DON'T print sensitive info in trace log.
* Cookie * X-CSRFToken * Set-Cookie Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent ed5353e commit 349b531

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _ = require('underscore');
77
var chalk = require('./chalk');
88
var config = require('./config');
99
var icon = require('./icon');
10+
var h = require('./helper');
1011

1112
// We are expecting a tier configuration like:
1213
// global config < local config < cli params
@@ -57,14 +58,13 @@ function setLogLevel() {
5758
args.unshift('[TRACE]');
5859
}
5960
console.log.apply(null, _.map(args, function(arg) {
60-
return chalk.gray(arg);
61+
return chalk.gray(h.printSafeHTTP(arg));
6162
}));
6263
});
6364
}
6465
}
6566

6667
function checkCache() {
67-
var h = require('./helper');
6868
var cacheDir = h.getCacheDir();
6969

7070
if (!fs.existsSync(cacheDir))

lib/helper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,10 @@ h.getSetCookieValue = function(resp, key) {
165165
return null;
166166
};
167167

168+
h.printSafeHTTP = function(msg) {
169+
return msg.replace(/(Cookie\s*:\s*)'.*?'/, '$1<hidden>')
170+
.replace(/('X-CSRFToken'\s*:\s*)'.*?'/, '$1<hidden>')
171+
.replace(/('set-cookie'\s*:\s*)\[.*?\]/, '$1<hidden>');
172+
};
173+
168174
module.exports = h;

0 commit comments

Comments
 (0)
0