-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: fix object prototype type confusion
Use `Object.create(null)` for dictionary objects so that keys from certificate strings or the authorityInfoAccess field cannot conflict with Object.prototype properties. PR-URL: #14447 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
1 parent
6eeb06f
commit 0f7c06e
Showing
4 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { | |
// Example: | ||
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\[email protected] | ||
exports.parseCertString = function parseCertString(s) { | ||
var out = {}; | ||
var out = Object.create(null); | ||
var parts = s.split('\n'); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
var sepIndex = parts[i].indexOf('='); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable no-proto */ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
|
@@ -11,6 +12,7 @@ const tls = require('tls'); | |
'CN=ca1\[email protected]'; | ||
const singlesOut = tls.parseCertString(singles); | ||
assert.deepStrictEqual(singlesOut, { | ||
__proto__: null, | ||
C: 'US', | ||
ST: 'CA', | ||
L: 'SF', | ||
|
@@ -26,6 +28,7 @@ const tls = require('tls'); | |
'CN=*.nodejs.org'; | ||
const doublesOut = tls.parseCertString(doubles); | ||
assert.deepStrictEqual(doublesOut, { | ||
__proto__: null, | ||
OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], | ||
CN: '*.nodejs.org' | ||
}); | ||
|
@@ -34,5 +37,13 @@ const tls = require('tls'); | |
{ | ||
const invalid = 'fhqwhgads'; | ||
const invalidOut = tls.parseCertString(invalid); | ||
assert.deepStrictEqual(invalidOut, {}); | ||
assert.deepStrictEqual(invalidOut, { __proto__: null }); | ||
} | ||
|
||
{ | ||
const input = '__proto__=mostly harmless\nhasOwnProperty=not a function'; | ||
const expected = Object.create(null); | ||
expected.__proto__ = 'mostly harmless'; | ||
expected.hasOwnProperty = 'not a function'; | ||
assert.deepStrictEqual(tls.parseCertString(input), expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters