| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eededd1 commit d0e6f91
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ important than reliability against prototype pollution: | |||
| 9 | 9 | ||
| 10 | 10 | * `node:http` | |
| 11 | 11 | * `node:http2` | |
| 12 | + * `node:tls` | ||
| 12 | 13 | ||
| 13 | 14 | Usage of primordials should be preferred for new code in other areas, but | |
| 14 | 15 | replacing current code with primordials should be | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,9 +24,7 @@ | |||
| 24 | 24 | const tls = require('tls'); | |
| 25 | 25 | ||
| 26 | 26 | const { | |
| 27 | - ArrayPrototypePush, | ||
| 28 | 27 | JSONParse, | |
| 29 | - RegExpPrototypeSymbolReplace, | ||
| 30 | 28 | } = primordials; | |
| 31 | 29 | ||
| 32 | 30 | const { | |
@@ -133,21 +131,21 @@ function translatePeerCertificate(c) { | |||
| 133 | 131 | c.infoAccess = { __proto__: null }; | |
| 134 | 132 | ||
| 135 | 133 | // XXX: More key validation? | |
| 136 | - RegExpPrototypeSymbolReplace(/([^\n:]*):([^\n]*)(?:\n|$)/g, info, | ||
| 137 | - (all, key, val) => { | ||
| 138 | - if (val.charCodeAt(0) === 0x22) { | ||
| 139 | - // The translatePeerCertificate function is only | ||
| 140 | - // used on internally created legacy certificate | ||
| 141 | - // objects, and any value that contains a quote | ||
| 142 | - // will always be a valid JSON string literal, | ||
| 143 | - // so this should never throw. | ||
| 144 | - val = JSONParse(val); | ||
| 145 | - } | ||
| 146 | - if (key in c.infoAccess) | ||
| 147 | - ArrayPrototypePush(c.infoAccess[key], val); | ||
| 148 | - else | ||
| 149 | - c.infoAccess[key] = [val]; | ||
| 150 | - }); | ||
| 134 | + info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, | ||
| 135 | + (all, key, val) => { | ||
| 136 | + if (val.charCodeAt(0) === 0x22) { | ||
| 137 | + // The translatePeerCertificate function is only | ||
| 138 | + // used on internally created legacy certificate | ||
| 139 | + // objects, and any value that contains a quote | ||
| 140 | + // will always be a valid JSON string literal, | ||
| 141 | + // so this should never throw. | ||
| 142 | + val = JSONParse(val); | ||
| 143 | + } | ||
| 144 | + if (key in c.infoAccess) | ||
| 145 | + c.infoAccess[key].push(val); | ||
| 146 | + else | ||
| 147 | + c.infoAccess[key] = [val]; | ||
| 148 | + }); | ||
| 151 | 149 | } | |
| 152 | 150 | return c; | |
| 153 | 151 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,19 +22,11 @@ | |||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | - ArrayPrototypeForEach, | ||
| 26 | - ArrayPrototypeJoin, | ||
| 27 | - ArrayPrototypePush, | ||
| 28 | - FunctionPrototype, | ||
| 29 | 25 | ObjectAssign, | |
| 30 | 26 | ObjectDefineProperty, | |
| 31 | 27 | ObjectSetPrototypeOf, | |
| 32 | 28 | ReflectApply, | |
| 33 | 29 | RegExp, | |
| 34 | - RegExpPrototypeExec, | ||
| 35 | - RegExpPrototypeSymbolReplace, | ||
| 36 | - StringPrototypeReplaceAll, | ||
| 37 | - StringPrototypeSlice, | ||
| 38 | 30 | Symbol, | |
| 39 | 31 | SymbolFor, | |
| 40 | 32 | } = primordials; | |
@@ -117,7 +109,7 @@ const kPskIdentityHint = Symbol('pskidentityhint'); | |||
| 117 | 109 | const kPendingSession = Symbol('pendingSession'); | |
| 118 | 110 | const kIsVerified = Symbol('verified'); | |
| 119 | 111 | ||
| 120 | - const noop = FunctionPrototype; | ||
| 112 | + const noop = () => {}; | ||
| 121 | 113 | ||
| 122 | 114 | let ipServernameWarned = false; | |
| 123 | 115 | let tlsTracingWarned = false; | |
@@ -473,8 +465,7 @@ function onerror(err) { | |||
| 473 | 465 | owner.destroy(err); | |
| 474 | 466 | } else if (owner._tlsOptions?.isServer && | |
| 475 | 467 | owner._rejectUnauthorized && | |
| 476 | - RegExpPrototypeExec(/peer did not return a certificate/, | ||
| 477 | - err.message) !== null) { | ||
| 468 | + /peer did not return a certificate/.test(err.message)) { | ||
| 478 | 469 | // Ignore server's authorization errors | |
| 479 | 470 | owner.destroy(); | |
| 480 | 471 | } else { | |
@@ -1171,7 +1162,7 @@ function makeSocketMethodProxy(name) { | |||
| 1171 | 1162 | }; | |
| 1172 | 1163 | } | |
| 1173 | 1164 | ||
| 1174 | - ArrayPrototypeForEach([ | ||
| 1165 | + [ | ||
| 1175 | 1166 | 'getCipher', | |
| 1176 | 1167 | 'getSharedSigalgs', | |
| 1177 | 1168 | 'getEphemeralKeyInfo', | |
@@ -1182,7 +1173,7 @@ ArrayPrototypeForEach([ | |||
| 1182 | 1173 | 'getTLSTicket', | |
| 1183 | 1174 | 'isSessionReused', | |
| 1184 | 1175 | 'enableTrace', | |
| 1185 | - ], (method) => { | ||
| 1176 | + ].forEach((method) => { | ||
| 1186 | 1177 | TLSSocket.prototype[method] = makeSocketMethodProxy(method); | |
| 1187 | 1178 | }); | |
| 1188 | 1179 | ||
@@ -1479,10 +1470,10 @@ Server.prototype.setSecureContext = function(options) { | |||
| 1479 | 1470 | if (options.sessionIdContext) { | |
| 1480 | 1471 | this.sessionIdContext = options.sessionIdContext; | |
| 1481 | 1472 | } else { | |
| 1482 | - this.sessionIdContext = StringPrototypeSlice( | ||
| 1483 | - crypto.createHash('sha1') | ||
| 1484 | - .update(ArrayPrototypeJoin(process.argv, ' ')) | ||
| 1485 | - .digest('hex'), 0, 32); | ||
| 1473 | + this.sessionIdContext = crypto.createHash('sha1') | ||
| 1474 | + .update(process.argv.join(' ')) | ||
| 1475 | + .digest('hex') | ||
| 1476 | + .slice(0, 32); | ||
| 1486 | 1477 | } | |
| 1487 | 1478 | ||
| 1488 | 1479 | if (options.sessionTimeout) | |
@@ -1577,10 +1568,10 @@ Server.prototype.setOptions = deprecate(function(options) { | |||
| 1577 | 1568 | if (options.sessionIdContext) { | |
| 1578 | 1569 | this.sessionIdContext = options.sessionIdContext; | |
| 1579 | 1570 | } else { | |
| 1580 | - this.sessionIdContext = StringPrototypeSlice( | ||
| 1581 | - crypto.createHash('sha1') | ||
| 1582 | - .update(ArrayPrototypeJoin(process.argv, ' ')) | ||
| 1583 | - .digest('hex'), 0, 32); | ||
| 1571 | + this.sessionIdContext = crypto.createHash('sha1') | ||
| 1572 | + .update(process.argv.join(' ')) | ||
| 1573 | + .digest('hex') | ||
| 1574 | + .slice(0, 32); | ||
| 1584 | 1575 | } | |
| 1585 | 1576 | if (options.pskCallback) this[kPskCallback] = options.pskCallback; | |
| 1586 | 1577 | if (options.pskIdentityHint) this[kPskIdentityHint] = options.pskIdentityHint; | |
@@ -1597,14 +1588,15 @@ Server.prototype.addContext = function(servername, context) { | |||
| 1597 | 1588 | throw new ERR_TLS_REQUIRED_SERVER_NAME(); | |
| 1598 | 1589 | } | |
| 1599 | 1590 | ||
| 1600 | - const re = new RegExp('^' + StringPrototypeReplaceAll( | ||
| 1601 | - RegExpPrototypeSymbolReplace(/([.^$+?\-\\[\]{}])/g, servername, '\\$1'), | ||
| 1602 | - '*', '[^.]*', | ||
| 1603 | - ) + '$'); | ||
| 1591 | + const re = new RegExp(`^${ | ||
| 1592 | + servername | ||
| 1593 | + .replace(/([.^$+?\-\\[\]{}])/g, '\\$1') | ||
| 1594 | + .replaceAll('*', '[^.]*') | ||
| 1595 | + }$`); | ||
| 1604 | 1596 | ||
| 1605 | 1597 | const secureContext = | |
| 1606 | 1598 | context instanceof common.SecureContext ? context : tls.createSecureContext(context); | |
| 1607 | - ArrayPrototypePush(this._contexts, [re, secureContext.context]); | ||
| 1599 | + this._contexts.push([re, secureContext.context]); | ||
| 1608 | 1600 | }; | |
| 1609 | 1601 | ||
| 1610 | 1602 | Server.prototype[EE.captureRejectionSymbol] = function( | |
@@ -1625,7 +1617,7 @@ function SNICallback(servername, callback) { | |||
| 1625 | 1617 | ||
| 1626 | 1618 | for (let i = contexts.length - 1; i >= 0; --i) { | |
| 1627 | 1619 | const elem = contexts[i]; | |
| 1628 | - if (RegExpPrototypeExec(elem[0], servername) !== null) { | ||
| 1620 | + if (elem[0].test(servername)) { | ||
| 1629 | 1621 | callback(null, elem[1]); | |
| 1630 | 1622 | return; | |
| 1631 | 1623 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,26 +24,10 @@ | |||
| 24 | 24 | const { | |
| 25 | 25 | Array, | |
| 26 | 26 | ArrayIsArray, | |
| 27 | - ArrayPrototypeForEach, | ||
| 28 | - ArrayPrototypeIncludes, | ||
| 29 | - ArrayPrototypeJoin, | ||
| 30 | - ArrayPrototypePush, | ||
| 31 | - ArrayPrototypeReduce, | ||
| 32 | - ArrayPrototypeSome, | ||
| 33 | 27 | JSONParse, | |
| 34 | 28 | ObjectDefineProperty, | |
| 35 | 29 | ObjectFreeze, | |
| 36 | - RegExpPrototypeExec, | ||
| 37 | - RegExpPrototypeSymbolReplace, | ||
| 38 | 30 | StringFromCharCode, | |
| 39 | - StringPrototypeCharCodeAt, | ||
| 40 | - StringPrototypeEndsWith, | ||
| 41 | - StringPrototypeIncludes, | ||
| 42 | - StringPrototypeIndexOf, | ||
| 43 | - StringPrototypeSlice, | ||
| 44 | - StringPrototypeSplit, | ||
| 45 | - StringPrototypeStartsWith, | ||
| 46 | - StringPrototypeSubstring, | ||
| 47 | 31 | } = primordials; | |
| 48 | 32 | ||
| 49 | 33 | const { | |
@@ -122,7 +106,7 @@ ObjectDefineProperty(exports, 'rootCertificates', { | |||
| 122 | 106 | // ("\x06spdy/2\x08http/1.1\x08http/1.0") | |
| 123 | 107 | function convertProtocols(protocols) { | |
| 124 | 108 | const lens = new Array(protocols.length); | |
| 125 | - const buff = Buffer.allocUnsafe(ArrayPrototypeReduce(protocols, (p, c, i) => { | ||
| 109 | + const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => { | ||
| 126 | 110 | const len = Buffer.byteLength(c); | |
| 127 | 111 | if (len > 255) { | |
| 128 | 112 | throw new ERR_OUT_OF_RANGE('The byte length of the protocol at index ' + | |
@@ -158,20 +142,17 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) { | |||
| 158 | 142 | }; | |
| 159 | 143 | ||
| 160 | 144 | function unfqdn(host) { | |
| 161 | - return RegExpPrototypeSymbolReplace(/[.]$/, host, ''); | ||
| 145 | + return host.replace(/[.]$/, ''); | ||
| 162 | 146 | } | |
| 163 | 147 | ||
| 164 | 148 | // String#toLowerCase() is locale-sensitive so we use | |
| 165 | 149 | // a conservative version that only lowercases A-Z. | |
| 166 | 150 | function toLowerCase(c) { | |
| 167 | - return StringFromCharCode(32 + StringPrototypeCharCodeAt(c, 0)); | ||
| 151 | + return StringFromCharCode(32 + c.charCodeAt(0)); | ||
| 168 | 152 | } | |
| 169 | 153 | ||
| 170 | 154 | function splitHost(host) { | |
| 171 | - return StringPrototypeSplit( | ||
| 172 | - RegExpPrototypeSymbolReplace(/[A-Z]/g, unfqdn(host), toLowerCase), | ||
| 173 | - '.', | ||
| 174 | - ); | ||
| 155 | + return unfqdn(host).replace(/[A-Z]/g, toLowerCase).split('.'); | ||
| 175 | 156 | } | |
| 176 | 157 | ||
| 177 | 158 | function check(hostParts, pattern, wildcards) { | |
@@ -185,15 +166,15 @@ function check(hostParts, pattern, wildcards) { | |||
| 185 | 166 | return false; | |
| 186 | 167 | ||
| 187 | 168 | // Pattern has empty components, e.g. "bad..example.com". | |
| 188 | - if (ArrayPrototypeIncludes(patternParts, '')) | ||
| 169 | + if (patternParts.includes('')) | ||
| 189 | 170 | return false; | |
| 190 | 171 | ||
| 191 | 172 | // RFC 6125 allows IDNA U-labels (Unicode) in names but we have no | |
| 192 | 173 | // good way to detect their encoding or normalize them so we simply | |
| 193 | 174 | // reject them. Control characters and blanks are rejected as well | |
| 194 | 175 | // because nothing good can come from accepting them. | |
| 195 | - const isBad = (s) => RegExpPrototypeExec(/[^\u0021-\u007F]/u, s) !== null; | ||
| 196 | - if (ArrayPrototypeSome(patternParts, isBad)) | ||
| 176 | + const isBad = (s) => /[^\u0021-\u007F]/u.test(s); | ||
| 177 | + if (patternParts.some(isBad)) | ||
| 197 | 178 | return false; | |
| 198 | 179 | ||
| 199 | 180 | // Check host parts from right to left first. | |
@@ -204,13 +185,13 @@ function check(hostParts, pattern, wildcards) { | |||
| 204 | 185 | ||
| 205 | 186 | const hostSubdomain = hostParts[0]; | |
| 206 | 187 | const patternSubdomain = patternParts[0]; | |
| 207 | - const patternSubdomainParts = StringPrototypeSplit(patternSubdomain, '*'); | ||
| 188 | + const patternSubdomainParts = patternSubdomain.split('*'); | ||
| 208 | 189 | ||
| 209 | 190 | // Short-circuit when the subdomain does not contain a wildcard. | |
| 210 | 191 | // RFC 6125 does not allow wildcard substitution for components | |
| 211 | 192 | // containing IDNA A-labels (Punycode) so match those verbatim. | |
| 212 | 193 | if (patternSubdomainParts.length === 1 || | |
| 213 | - StringPrototypeIncludes(patternSubdomain, 'xn--')) | ||
| 194 | + patternSubdomain.includes('xn--')) | ||
| 214 | 195 | return hostSubdomain === patternSubdomain; | |
| 215 | 196 | ||
| 216 | 197 | if (!wildcards) | |
@@ -229,10 +210,10 @@ function check(hostParts, pattern, wildcards) { | |||
| 229 | 210 | if (prefix.length + suffix.length > hostSubdomain.length) | |
| 230 | 211 | return false; | |
| 231 | 212 | ||
| 232 | - if (!StringPrototypeStartsWith(hostSubdomain, prefix)) | ||
| 213 | + if (!hostSubdomain.startsWith(prefix)) | ||
| 233 | 214 | return false; | |
| 234 | 215 | ||
| 235 | - if (!StringPrototypeEndsWith(hostSubdomain, suffix)) | ||
| 216 | + if (!hostSubdomain.endsWith(suffix)) | ||
| 236 | 217 | return false; | |
| 237 | 218 | ||
| 238 | 219 | return true; | |
@@ -250,30 +231,29 @@ function splitEscapedAltNames(altNames) { | |||
| 250 | 231 | let currentToken = ''; | |
| 251 | 232 | let offset = 0; | |
| 252 | 233 | while (offset !== altNames.length) { | |
| 253 | - const nextSep = StringPrototypeIndexOf(altNames, ', ', offset); | ||
| 254 | - const nextQuote = StringPrototypeIndexOf(altNames, '"', offset); | ||
| 234 | + const nextSep = altNames.indexOf(',', offset); | ||
| 235 | + const nextQuote = altNames.indexOf('"', offset); | ||
| 255 | 236 | if (nextQuote !== -1 && (nextSep === -1 || nextQuote < nextSep)) { | |
| 256 | 237 | // There is a quote character and there is no separator before the quote. | |
| 257 | - currentToken += StringPrototypeSubstring(altNames, offset, nextQuote); | ||
| 258 | - const match = RegExpPrototypeExec( | ||
| 259 | - jsonStringPattern, StringPrototypeSubstring(altNames, nextQuote)); | ||
| 238 | + currentToken += altNames.substring(offset, nextQuote); | ||
| 239 | + const match = jsonStringPattern.exec(altNames.substring(nextQuote)); | ||
| 260 | 240 | if (!match) { | |
| 261 | 241 | throw new ERR_TLS_CERT_ALTNAME_FORMAT(); | |
| 262 | 242 | } | |
| 263 | 243 | currentToken += JSONParse(match[0]); | |
| 264 | 244 | offset = nextQuote + match[0].length; | |
| 265 | 245 | } else if (nextSep !== -1) { | |
| 266 | 246 | // There is a separator and no quote before it. | |
| 267 | - currentToken += StringPrototypeSubstring(altNames, offset, nextSep); | ||
| 268 | - ArrayPrototypePush(result, currentToken); | ||
| 247 | + currentToken += altNames.substring(offset, nextSep); | ||
| 248 | + result.push(currentToken); | ||
| 269 | 249 | currentToken = ''; | |
| 270 | 250 | offset = nextSep + 2; | |
| 271 | 251 | } else { | |
| 272 | - currentToken += StringPrototypeSubstring(altNames, offset); | ||
| 252 | + currentToken += altNames.substring(offset); | ||
| 273 | 253 | offset = altNames.length; | |
| 274 | 254 | } | |
| 275 | 255 | } | |
| 276 | - ArrayPrototypePush(result, currentToken); | ||
| 256 | + result.push(currentToken); | ||
| 277 | 257 | return result; | |
| 278 | 258 | } | |
| 279 | 259 | ||
@@ -286,14 +266,14 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 286 | 266 | hostname = '' + hostname; | |
| 287 | 267 | ||
| 288 | 268 | if (altNames) { | |
| 289 | - const splitAltNames = StringPrototypeIncludes(altNames, '"') ? | ||
| 269 | + const splitAltNames = altNames.includes('"') ? | ||
| 290 | 270 | splitEscapedAltNames(altNames) : | |
| 291 | - StringPrototypeSplit(altNames, ', '); | ||
| 292 | - ArrayPrototypeForEach(splitAltNames, (name) => { | ||
| 293 | - if (StringPrototypeStartsWith(name, 'DNS:')) { | ||
| 294 | - ArrayPrototypePush(dnsNames, StringPrototypeSlice(name, 4)); | ||
| 295 | - } else if (StringPrototypeStartsWith(name, 'IP Address:')) { | ||
| 296 | - ArrayPrototypePush(ips, canonicalizeIP(StringPrototypeSlice(name, 11))); | ||
| 271 | + altNames.split(', '); | ||
| 272 | + splitAltNames.forEach((name) => { | ||
| 273 | + if (name.startsWith('DNS:')) { | ||
| 274 | + dnsNames.push(name.slice(4)); | ||
| 275 | + } else if (name.startsWith('IP Address:')) { | ||
| 276 | + ips.push(canonicalizeIP(name.slice(11))); | ||
| 297 | 277 | } | |
| 298 | 278 | }); | |
| 299 | 279 | } | |
@@ -304,16 +284,15 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 304 | 284 | hostname = unfqdn(hostname); // Remove trailing dot for error messages. | |
| 305 | 285 | ||
| 306 | 286 | if (net.isIP(hostname)) { | |
| 307 | - valid = ArrayPrototypeIncludes(ips, canonicalizeIP(hostname)); | ||
| 287 | + valid = ips.includes(canonicalizeIP(hostname)); | ||
| 308 | 288 | if (!valid) | |
| 309 | - reason = `IP: ${hostname} is not in the cert's list: ` + | ||
| 310 | - ArrayPrototypeJoin(ips, ', '); | ||
| 289 | + reason = `IP: ${hostname} is not in the cert's list: ` + ips.join(', '); | ||
| 311 | 290 | } else if (dnsNames.length > 0 || subject?.CN) { | |
| 312 | 291 | const hostParts = splitHost(hostname); | |
| 313 | 292 | const wildcard = (pattern) => check(hostParts, pattern, true); | |
| 314 | 293 | ||
| 315 | 294 | if (dnsNames.length > 0) { | |
| 316 | - valid = ArrayPrototypeSome(dnsNames, wildcard); | ||
| 295 | + valid = dnsNames.some(wildcard); | ||
| 317 | 296 | if (!valid) | |
| 318 | 297 | reason = | |
| 319 | 298 | `Host: ${hostname}. is not in the cert's altnames: ${altNames}`; | |
@@ -322,7 +301,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 322 | 301 | const cn = subject.CN; | |
| 323 | 302 | ||
| 324 | 303 | if (ArrayIsArray(cn)) | |
| 325 | - valid = ArrayPrototypeSome(cn, wildcard); | ||
| 304 | + valid = cn.some(wildcard); | ||
| 326 | 305 | else if (cn) | |
| 327 | 306 | valid = wildcard(cn); | |
| 328 | 307 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments