Skip to content

Commit 980877f

Browse files
antsmartianmcollina
authored andcommitted
util: adding warnings when NODE_DEBUG is set as http/http2
PR-URL: #21914 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 933d8eb commit 980877f

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
@@ -344,11 +344,23 @@ if (process.env.NODE_DEBUG) {
344344
debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
345345
}
346346

347+
// Emits warning when user sets
348+
// NODE_DEBUG=http or NODE_DEBUG=http2.
349+
function emitWarningIfNeeded(set) {
350+
if ('HTTP' === set || 'HTTP2' === set) {
351+
process.emitWarning('Setting the NODE_DEBUG environment variable ' +
352+
'to \'' + set.toLowerCase() + '\' can expose sensitive ' +
353+
'data (such as passwords, tokens and authentication headers) ' +
354+
'in the resulting log.');
355+
}
356+
}
357+
347358
function debuglog(set) {
348359
set = set.toUpperCase();
349360
if (!debugs[set]) {
350361
if (debugEnvRegex.test(set)) {
351362
const pid = process.pid;
363+
emitWarningIfNeeded(set);
352364
debugs[set] = function debug() {
353365
const msg = exports.format.apply(exports, arguments);
354366
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)