Skip to content

Commit 349b531

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

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/cli.js

+2-2
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

+6
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)