Skip to content

Commit d6969a7

Browse files
ChALkeRMylesBorins
authored andcommitted
http: use Buffer.from to avoid Buffer(num) call
This fixes a potential Buffer(num) call when the user passes a number as the 'auth' property. This now throws instead of allocating an unitialized memory Buffer and sending that in the Authorization header. Fixes: https://github.com/nodejs/security/issues/111 PR-URL: https://github.com/nodejs/node-private/pull/83 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 681cebb commit d6969a7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/_http_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function ClientRequest(options, cb) {
102102
if (options.auth && !this.getHeader('Authorization')) {
103103
//basic auth
104104
this.setHeader('Authorization', 'Basic ' +
105-
new Buffer(options.auth).toString('base64'));
105+
Buffer.from(options.auth).toString('base64'));
106106
}
107107

108108
if (method === 'GET' ||
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
require('../common');
4+
const http = require('http');
5+
const url = require('url');
6+
const assert = require('assert');
7+
8+
const opts = url.parse('http://127.0.0.1:8180');
9+
opts.auth = 100;
10+
11+
assert.throws(() => {
12+
http.get(opts);
13+
}, /^TypeError: "value" argument must not be a number$/);

0 commit comments

Comments
 (0)