-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
tls: fix object prototype type confusion #14447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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('='); | ||
|
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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a
c.infoAccess[key] === undefined
would be more efficient?Or just save the value to a variable and use that value here and use it to skip the lookups below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlikely to matter because it's only a handful of keys (if it's set at all.) This is shorter so that's what I picked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a micro benchmark for that on TF&I. Small benefit for
in