Skip to content

Commit d248a6f

Browse files
committed
util: Adding warnings when NODE_DEBUG is set as http/http2
1 parent c3f8dd6 commit d248a6f

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

lib/util.js

+12
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,23 @@ if (process.env.NODE_DEBUG) {
306306
debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
307307
}
308308

309+
// Emits warning when user sets
310+
// NODE_DEBUG=http or NODE_DEBUG=http2.
311+
function emitWarningIfNeeded(set) {
312+
if ('HTTP' === set || 'HTTP2' === set) {
313+
process.emitWarning('Setting the NODE_DEBUG environment variable ' +
314+
'to \'' + set.toLowerCase() + '\' can expose sensitive ' +
315+
'data (such as passwords, tokens and authentication headers) ' +
316+
'in the resulting log.');
317+
}
318+
}
319+
309320
function debuglog(set) {
310321
set = set.toUpperCase();
311322
if (!debugs[set]) {
312323
if (debugEnvRegex.test(set)) {
313324
const pid = process.pid;
325+
emitWarningIfNeeded(set);
314326
debugs[set] = function debug() {
315327
const msg = exports.format.apply(exports, arguments);
316328
console.error('%s %d: %s', set, pid, msg);

test/parallel/test-http-conn-reset.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const options = {
3030
port: undefined
3131
};
3232

33+
process.env.NODE_DEBUG = 'http';
3334
// start a tcp server that closes incoming connections immediately
3435
const server = net.createServer(function(client) {
3536
client.destroy();

test/parallel/test-http-debug.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const child_process = require('child_process');
6+
const path = require('path');
7+
8+
process.env.NODE_DEBUG = 'http';
9+
const { stderr } = child_process.spawnSync(process.execPath, [
10+
path.resolve(__dirname, 'test-http-conn-reset.js')
11+
], { encoding: 'utf8' });
12+
13+
assert(stderr.match(/Setting the NODE_DEBUG environment variable to 'http' can expose sensitive data \(such as passwords, tokens and authentication headers\) in the resulting log\./),
14+
stderr);

test/parallel/test-http2-debug.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ const child_process = require('child_process');
77
const path = require('path');
88

99
process.env.NODE_DEBUG_NATIVE = 'http2';
10+
process.env.NODE_DEBUG = 'http2';
1011
const { stdout, stderr } = child_process.spawnSync(process.execPath, [
1112
path.resolve(__dirname, 'test-http2-ping.js')
1213
], { encoding: 'utf8' });
1314

15+
assert(stderr.match(/Setting the NODE_DEBUG environment variable to 'http2' can expose sensitive data \(such as passwords, tokens and authentication headers\) in the resulting log\./),
16+
stderr);
1417
assert(stderr.match(/Http2Session client \(\d+\) handling data frame for stream \d+/),
1518
stderr);
1619
assert(stderr.match(/HttpStream \d+ \(\d+\) \[Http2Session client \(\d+\)\] reading starting/),

0 commit comments

Comments
 (0)