aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node_modules/undici
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2025-12-16 16:51:48 +0100
committerEgor Tensin <egor@tensin.name>2025-12-16 16:51:54 +0100
commit342fb8ba128c1fbbf5195a7b5d56cb5b8f8fdca9 (patch)
tree1af9b90985a2685c70e8e756eabc62a21ca362bb /node_modules/undici
parentbump dependencies (diff)
downloadcleanup-path-342fb8ba128c1fbbf5195a7b5d56cb5b8f8fdca9.tar.gz
cleanup-path-342fb8ba128c1fbbf5195a7b5d56cb5b8f8fdca9.zip
bump dependencies
Diffstat (limited to 'node_modules/undici')
-rw-r--r--node_modules/undici/lib/cookies/index.js7
-rw-r--r--node_modules/undici/lib/cookies/util.js35
-rw-r--r--node_modules/undici/lib/core/constants.js118
-rw-r--r--node_modules/undici/lib/core/util.js11
-rw-r--r--node_modules/undici/lib/fetch/body.js10
-rw-r--r--node_modules/undici/lib/fetch/headers.js4
-rw-r--r--node_modules/undici/lib/fetch/index.js3
-rw-r--r--node_modules/undici/lib/fetch/util.js143
-rw-r--r--node_modules/undici/lib/handler/RedirectHandler.js17
-rw-r--r--node_modules/undici/lib/pool.js14
-rw-r--r--node_modules/undici/package.json4
11 files changed, 292 insertions, 74 deletions
diff --git a/node_modules/undici/lib/cookies/index.js b/node_modules/undici/lib/cookies/index.js
index c9c1f28..f867b19 100644
--- a/node_modules/undici/lib/cookies/index.js
+++ b/node_modules/undici/lib/cookies/index.js
@@ -1,7 +1,7 @@
'use strict'
const { parseSetCookie } = require('./parse')
-const { stringify, getHeadersList } = require('./util')
+const { stringify } = require('./util')
const { webidl } = require('../fetch/webidl')
const { Headers } = require('../fetch/headers')
@@ -77,14 +77,13 @@ function getSetCookies (headers) {
webidl.brandCheck(headers, Headers, { strict: false })
- const cookies = getHeadersList(headers).cookies
+ const cookies = headers.getSetCookie()
if (!cookies) {
return []
}
- // In older versions of undici, cookies is a list of name:value.
- return cookies.map((pair) => parseSetCookie(Array.isArray(pair) ? pair[1] : pair))
+ return cookies.map((pair) => parseSetCookie(pair))
}
/**
diff --git a/node_modules/undici/lib/cookies/util.js b/node_modules/undici/lib/cookies/util.js
index 2290329..be3ccbe 100644
--- a/node_modules/undici/lib/cookies/util.js
+++ b/node_modules/undici/lib/cookies/util.js
@@ -1,8 +1,9 @@
'use strict'
-const assert = require('assert')
-const { kHeadersList } = require('../core/symbols')
-
+/**
+ * @param {string} value
+ * @returns {boolean}
+ */
function isCTLExcludingHtab (value) {
if (value.length === 0) {
return false
@@ -263,29 +264,11 @@ function stringify (cookie) {
return out.join('; ')
}
-let kHeadersListNode
-
-function getHeadersList (headers) {
- if (headers[kHeadersList]) {
- return headers[kHeadersList]
- }
-
- if (!kHeadersListNode) {
- kHeadersListNode = Object.getOwnPropertySymbols(headers).find(
- (symbol) => symbol.description === 'headers list'
- )
-
- assert(kHeadersListNode, 'Headers cannot be parsed')
- }
-
- const headersList = headers[kHeadersListNode]
- assert(headersList)
-
- return headersList
-}
-
module.exports = {
isCTLExcludingHtab,
- stringify,
- getHeadersList
+ validateCookieName,
+ validateCookiePath,
+ validateCookieValue,
+ toIMFDate,
+ stringify
}
diff --git a/node_modules/undici/lib/core/constants.js b/node_modules/undici/lib/core/constants.js
new file mode 100644
index 0000000..6ec770d
--- /dev/null
+++ b/node_modules/undici/lib/core/constants.js
@@ -0,0 +1,118 @@
+'use strict'
+
+/** @type {Record<string, string | undefined>} */
+const headerNameLowerCasedRecord = {}
+
+// https://developer.mozilla.org/docs/Web/HTTP/Headers
+const wellknownHeaderNames = [
+ 'Accept',
+ 'Accept-Encoding',
+ 'Accept-Language',
+ 'Accept-Ranges',
+ 'Access-Control-Allow-Credentials',
+ 'Access-Control-Allow-Headers',
+ 'Access-Control-Allow-Methods',
+ 'Access-Control-Allow-Origin',
+ 'Access-Control-Expose-Headers',
+ 'Access-Control-Max-Age',
+ 'Access-Control-Request-Headers',
+ 'Access-Control-Request-Method',
+ 'Age',
+ 'Allow',
+ 'Alt-Svc',
+ 'Alt-Used',
+ 'Authorization',
+ 'Cache-Control',
+ 'Clear-Site-Data',
+ 'Connection',
+ 'Content-Disposition',
+ 'Content-Encoding',
+ 'Content-Language',
+ 'Content-Length',
+ 'Content-Location',
+ 'Content-Range',
+ 'Content-Security-Policy',
+ 'Content-Security-Policy-Report-Only',
+ 'Content-Type',
+ 'Cookie',
+ 'Cross-Origin-Embedder-Policy',
+ 'Cross-Origin-Opener-Policy',
+ 'Cross-Origin-Resource-Policy',
+ 'Date',
+ 'Device-Memory',
+ 'Downlink',
+ 'ECT',
+ 'ETag',
+ 'Expect',
+ 'Expect-CT',
+ 'Expires',
+ 'Forwarded',
+ 'From',
+ 'Host',
+ 'If-Match',
+ 'If-Modified-Since',
+ 'If-None-Match',
+ 'If-Range',
+ 'If-Unmodified-Since',
+ 'Keep-Alive',
+ 'Last-Modified',
+ 'Link',
+ 'Location',
+ 'Max-Forwards',
+ 'Origin',
+ 'Permissions-Policy',
+ 'Pragma',
+ 'Proxy-Authenticate',
+ 'Proxy-Authorization',
+ 'RTT',
+ 'Range',
+ 'Referer',
+ 'Referrer-Policy',
+ 'Refresh',
+ 'Retry-After',
+ 'Sec-WebSocket-Accept',
+ 'Sec-WebSocket-Extensions',
+ 'Sec-WebSocket-Key',
+ 'Sec-WebSocket-Protocol',
+ 'Sec-WebSocket-Version',
+ 'Server',
+ 'Server-Timing',
+ 'Service-Worker-Allowed',
+ 'Service-Worker-Navigation-Preload',
+ 'Set-Cookie',
+ 'SourceMap',
+ 'Strict-Transport-Security',
+ 'Supports-Loading-Mode',
+ 'TE',
+ 'Timing-Allow-Origin',
+ 'Trailer',
+ 'Transfer-Encoding',
+ 'Upgrade',
+ 'Upgrade-Insecure-Requests',
+ 'User-Agent',
+ 'Vary',
+ 'Via',
+ 'WWW-Authenticate',
+ 'X-Content-Type-Options',
+ 'X-DNS-Prefetch-Control',
+ 'X-Frame-Options',
+ 'X-Permitted-Cross-Domain-Policies',
+ 'X-Powered-By',
+ 'X-Requested-With',
+ 'X-XSS-Protection'
+]
+
+for (let i = 0; i < wellknownHeaderNames.length; ++i) {
+ const key = wellknownHeaderNames[i]
+ const lowerCasedKey = key.toLowerCase()
+ headerNameLowerCasedRecord[key] = headerNameLowerCasedRecord[lowerCasedKey] =
+ lowerCasedKey
+}
+
+// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`.
+Object.setPrototypeOf(headerNameLowerCasedRecord, null)
+
+module.exports = {
+ wellknownHeaderNames,
+ headerNameLowerCasedRecord
+}
diff --git a/node_modules/undici/lib/core/util.js b/node_modules/undici/lib/core/util.js
index 8d5450b..5741650 100644
--- a/node_modules/undici/lib/core/util.js
+++ b/node_modules/undici/lib/core/util.js
@@ -9,6 +9,7 @@ const { InvalidArgumentError } = require('./errors')
const { Blob } = require('buffer')
const nodeUtil = require('util')
const { stringify } = require('querystring')
+const { headerNameLowerCasedRecord } = require('./constants')
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v))
@@ -218,6 +219,15 @@ function parseKeepAliveTimeout (val) {
return m ? parseInt(m[1], 10) * 1000 : null
}
+/**
+ * Retrieves a header name and returns its lowercase value.
+ * @param {string | Buffer} value Header name
+ * @returns {string}
+ */
+function headerNameToString (value) {
+ return headerNameLowerCasedRecord[value] || value.toLowerCase()
+}
+
function parseHeaders (headers, obj = {}) {
// For H2 support
if (!Array.isArray(headers)) return headers
@@ -489,6 +499,7 @@ module.exports = {
isIterable,
isAsyncIterable,
isDestroyed,
+ headerNameToString,
parseRawHeaders,
parseHeaders,
parseKeepAliveTimeout,
diff --git a/node_modules/undici/lib/fetch/body.js b/node_modules/undici/lib/fetch/body.js
index fd8481b..4afcfdf 100644
--- a/node_modules/undici/lib/fetch/body.js
+++ b/node_modules/undici/lib/fetch/body.js
@@ -22,6 +22,14 @@ const { isUint8Array, isArrayBuffer } = require('util/types')
const { File: UndiciFile } = require('./file')
const { parseMIMEType, serializeAMimeType } = require('./dataURL')
+let random
+try {
+ const crypto = require('node:crypto')
+ random = (max) => crypto.randomInt(0, max)
+} catch {
+ random = (max) => Math.floor(Math.random(max))
+}
+
let ReadableStream = globalThis.ReadableStream
/** @type {globalThis['File']} */
@@ -107,7 +115,7 @@ function extractBody (object, keepalive = false) {
// Set source to a copy of the bytes held by object.
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
} else if (util.isFormDataLike(object)) {
- const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
+ const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
diff --git a/node_modules/undici/lib/fetch/headers.js b/node_modules/undici/lib/fetch/headers.js
index 2f1c0be..fcab732 100644
--- a/node_modules/undici/lib/fetch/headers.js
+++ b/node_modules/undici/lib/fetch/headers.js
@@ -10,6 +10,7 @@ const {
isValidHeaderName,
isValidHeaderValue
} = require('./util')
+const util = require('util')
const { webidl } = require('./webidl')
const assert = require('assert')
@@ -563,6 +564,9 @@ Object.defineProperties(Headers.prototype, {
[Symbol.toStringTag]: {
value: 'Headers',
configurable: true
+ },
+ [util.inspect.custom]: {
+ enumerable: false
}
})
diff --git a/node_modules/undici/lib/fetch/index.js b/node_modules/undici/lib/fetch/index.js
index 17c3d87..dea2069 100644
--- a/node_modules/undici/lib/fetch/index.js
+++ b/node_modules/undici/lib/fetch/index.js
@@ -1203,6 +1203,9 @@ function httpRedirectFetch (fetchParams, response) {
// https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
request.headersList.delete('authorization')
+ // https://fetch.spec.whatwg.org/#authentication-entries
+ request.headersList.delete('proxy-authorization', true)
+
// "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
request.headersList.delete('cookie')
request.headersList.delete('host')
diff --git a/node_modules/undici/lib/fetch/util.js b/node_modules/undici/lib/fetch/util.js
index b12142c..ede4ec4 100644
--- a/node_modules/undici/lib/fetch/util.js
+++ b/node_modules/undici/lib/fetch/util.js
@@ -7,14 +7,18 @@ const { isBlobLike, toUSVString, ReadableStreamFrom } = require('../core/util')
const assert = require('assert')
const { isUint8Array } = require('util/types')
+let supportedHashes = []
+
// https://nodejs.org/api/crypto.html#determining-if-crypto-support-is-unavailable
/** @type {import('crypto')|undefined} */
let crypto
try {
crypto = require('crypto')
+ const possibleRelevantHashes = ['sha256', 'sha384', 'sha512']
+ supportedHashes = crypto.getHashes().filter((hash) => possibleRelevantHashes.includes(hash))
+/* c8 ignore next 3 */
} catch {
-
}
function responseURL (response) {
@@ -542,66 +546,56 @@ function bytesMatch (bytes, metadataList) {
return true
}
- // 3. If parsedMetadata is the empty set, return true.
+ // 3. If response is not eligible for integrity validation, return false.
+ // TODO
+
+ // 4. If parsedMetadata is the empty set, return true.
if (parsedMetadata.length === 0) {
return true
}
- // 4. Let metadata be the result of getting the strongest
+ // 5. Let metadata be the result of getting the strongest
// metadata from parsedMetadata.
- const list = parsedMetadata.sort((c, d) => d.algo.localeCompare(c.algo))
- // get the strongest algorithm
- const strongest = list[0].algo
- // get all entries that use the strongest algorithm; ignore weaker
- const metadata = list.filter((item) => item.algo === strongest)
+ const strongest = getStrongestMetadata(parsedMetadata)
+ const metadata = filterMetadataListByAlgorithm(parsedMetadata, strongest)
- // 5. For each item in metadata:
+ // 6. For each item in metadata:
for (const item of metadata) {
// 1. Let algorithm be the alg component of item.
const algorithm = item.algo
// 2. Let expectedValue be the val component of item.
- let expectedValue = item.hash
+ const expectedValue = item.hash
// See https://github.com/web-platform-tests/wpt/commit/e4c5cc7a5e48093220528dfdd1c4012dc3837a0e
// "be liberal with padding". This is annoying, and it's not even in the spec.
- if (expectedValue.endsWith('==')) {
- expectedValue = expectedValue.slice(0, -2)
- }
-
// 3. Let actualValue be the result of applying algorithm to bytes.
let actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')
- if (actualValue.endsWith('==')) {
- actualValue = actualValue.slice(0, -2)
+ if (actualValue[actualValue.length - 1] === '=') {
+ if (actualValue[actualValue.length - 2] === '=') {
+ actualValue = actualValue.slice(0, -2)
+ } else {
+ actualValue = actualValue.slice(0, -1)
+ }
}
// 4. If actualValue is a case-sensitive match for expectedValue,
// return true.
- if (actualValue === expectedValue) {
- return true
- }
-
- let actualBase64URL = crypto.createHash(algorithm).update(bytes).digest('base64url')
-
- if (actualBase64URL.endsWith('==')) {
- actualBase64URL = actualBase64URL.slice(0, -2)
- }
-
- if (actualBase64URL === expectedValue) {
+ if (compareBase64Mixed(actualValue, expectedValue)) {
return true
}
}
- // 6. Return false.
+ // 7. Return false.
return false
}
// https://w3c.github.io/webappsec-subresource-integrity/#grammardef-hash-with-options
// https://www.w3.org/TR/CSP2/#source-list-syntax
// https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1
-const parseHashWithOptions = /((?<algo>sha256|sha384|sha512)-(?<hash>[A-z0-9+/]{1}.*={0,2}))( +[\x21-\x7e]?)?/i
+const parseHashWithOptions = /(?<algo>sha256|sha384|sha512)-((?<hash>[A-Za-z0-9+/]+|[A-Za-z0-9_-]+)={0,2}(?:\s|$)( +[!-~]*)?)?/i
/**
* @see https://w3c.github.io/webappsec-subresource-integrity/#parse-metadata
@@ -615,8 +609,6 @@ function parseMetadata (metadata) {
// 2. Let empty be equal to true.
let empty = true
- const supportedHashes = crypto.getHashes()
-
// 3. For each token returned by splitting metadata on spaces:
for (const token of metadata.split(' ')) {
// 1. Set empty to false.
@@ -626,7 +618,11 @@ function parseMetadata (metadata) {
const parsedToken = parseHashWithOptions.exec(token)
// 3. If token does not parse, continue to the next token.
- if (parsedToken === null || parsedToken.groups === undefined) {
+ if (
+ parsedToken === null ||
+ parsedToken.groups === undefined ||
+ parsedToken.groups.algo === undefined
+ ) {
// Note: Chromium blocks the request at this point, but Firefox
// gives a warning that an invalid integrity was given. The
// correct behavior is to ignore these, and subsequently not
@@ -635,11 +631,11 @@ function parseMetadata (metadata) {
}
// 4. Let algorithm be the hash-algo component of token.
- const algorithm = parsedToken.groups.algo
+ const algorithm = parsedToken.groups.algo.toLowerCase()
// 5. If algorithm is a hash function recognized by the user
// agent, add the parsed token to result.
- if (supportedHashes.includes(algorithm.toLowerCase())) {
+ if (supportedHashes.includes(algorithm)) {
result.push(parsedToken.groups)
}
}
@@ -652,6 +648,82 @@ function parseMetadata (metadata) {
return result
}
+/**
+ * @param {{ algo: 'sha256' | 'sha384' | 'sha512' }[]} metadataList
+ */
+function getStrongestMetadata (metadataList) {
+ // Let algorithm be the algo component of the first item in metadataList.
+ // Can be sha256
+ let algorithm = metadataList[0].algo
+ // If the algorithm is sha512, then it is the strongest
+ // and we can return immediately
+ if (algorithm[3] === '5') {
+ return algorithm
+ }
+
+ for (let i = 1; i < metadataList.length; ++i) {
+ const metadata = metadataList[i]
+ // If the algorithm is sha512, then it is the strongest
+ // and we can break the loop immediately
+ if (metadata.algo[3] === '5') {
+ algorithm = 'sha512'
+ break
+ // If the algorithm is sha384, then a potential sha256 or sha384 is ignored
+ } else if (algorithm[3] === '3') {
+ continue
+ // algorithm is sha256, check if algorithm is sha384 and if so, set it as
+ // the strongest
+ } else if (metadata.algo[3] === '3') {
+ algorithm = 'sha384'
+ }
+ }
+ return algorithm
+}
+
+function filterMetadataListByAlgorithm (metadataList, algorithm) {
+ if (metadataList.length === 1) {
+ return metadataList
+ }
+
+ let pos = 0
+ for (let i = 0; i < metadataList.length; ++i) {
+ if (metadataList[i].algo === algorithm) {
+ metadataList[pos++] = metadataList[i]
+ }
+ }
+
+ metadataList.length = pos
+
+ return metadataList
+}
+
+/**
+ * Compares two base64 strings, allowing for base64url
+ * in the second string.
+ *
+* @param {string} actualValue always base64
+ * @param {string} expectedValue base64 or base64url
+ * @returns {boolean}
+ */
+function compareBase64Mixed (actualValue, expectedValue) {
+ if (actualValue.length !== expectedValue.length) {
+ return false
+ }
+ for (let i = 0; i < actualValue.length; ++i) {
+ if (actualValue[i] !== expectedValue[i]) {
+ if (
+ (actualValue[i] === '+' && expectedValue[i] === '-') ||
+ (actualValue[i] === '/' && expectedValue[i] === '_')
+ ) {
+ continue
+ }
+ return false
+ }
+ }
+
+ return true
+}
+
// https://w3c.github.io/webappsec-upgrade-insecure-requests/#upgrade-request
function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
// TODO
@@ -1067,5 +1139,6 @@ module.exports = {
urlHasHttpsScheme,
urlIsHttpHttpsScheme,
readAllBytes,
- normalizeMethodRecord
+ normalizeMethodRecord,
+ parseMetadata
}
diff --git a/node_modules/undici/lib/handler/RedirectHandler.js b/node_modules/undici/lib/handler/RedirectHandler.js
index baca27e..933725f 100644
--- a/node_modules/undici/lib/handler/RedirectHandler.js
+++ b/node_modules/undici/lib/handler/RedirectHandler.js
@@ -184,12 +184,17 @@ function parseLocation (statusCode, headers) {
// https://tools.ietf.org/html/rfc7231#section-6.4.4
function shouldRemoveHeader (header, removeContent, unknownOrigin) {
- return (
- (header.length === 4 && header.toString().toLowerCase() === 'host') ||
- (removeContent && header.toString().toLowerCase().indexOf('content-') === 0) ||
- (unknownOrigin && header.length === 13 && header.toString().toLowerCase() === 'authorization') ||
- (unknownOrigin && header.length === 6 && header.toString().toLowerCase() === 'cookie')
- )
+ if (header.length === 4) {
+ return util.headerNameToString(header) === 'host'
+ }
+ if (removeContent && util.headerNameToString(header).startsWith('content-')) {
+ return true
+ }
+ if (unknownOrigin && (header.length === 13 || header.length === 6 || header.length === 19)) {
+ const name = util.headerNameToString(header)
+ return name === 'authorization' || name === 'cookie' || name === 'proxy-authorization'
+ }
+ return false
}
// https://tools.ietf.org/html/rfc7231#section-6.4
diff --git a/node_modules/undici/lib/pool.js b/node_modules/undici/lib/pool.js
index e3cd339..86b29d4 100644
--- a/node_modules/undici/lib/pool.js
+++ b/node_modules/undici/lib/pool.js
@@ -73,6 +73,20 @@ class Pool extends PoolBase {
? { ...options.interceptors }
: undefined
this[kFactory] = factory
+
+ this.on('connectionError', (origin, targets, error) => {
+ // If a connection error occurs, we remove the client from the pool,
+ // and emit a connectionError event. They will not be re-used.
+ // Fixes https://github.com/nodejs/undici/issues/3895
+ for (const target of targets) {
+ // Do not use kRemoveClient here, as it will close the client,
+ // but the client cannot be closed in this state.
+ const idx = this[kClients].indexOf(target)
+ if (idx !== -1) {
+ this[kClients].splice(idx, 1)
+ }
+ }
+ })
}
[kGetDispatcher] () {
diff --git a/node_modules/undici/package.json b/node_modules/undici/package.json
index 2b64daf..738688d 100644
--- a/node_modules/undici/package.json
+++ b/node_modules/undici/package.json
@@ -1,6 +1,6 @@
{
"name": "undici",
- "version": "5.28.2",
+ "version": "5.29.0",
"description": "An HTTP/1.1 client, written from scratch for Node.js",
"homepage": "https://undici.nodejs.org",
"bugs": {
@@ -110,7 +110,7 @@
"dns-packet": "^5.4.0",
"docsify-cli": "^4.4.3",
"form-data": "^4.0.0",
- "formdata-node": "^6.0.3",
+ "formdata-node": "^4.3.1",
"https-pem": "^3.0.0",
"husky": "^8.0.1",
"import-fresh": "^3.3.0",