Skip to content

Commit 711e207

Browse files
committed
Backport of c2d78cd
Signed-off-by: Matteo Collina <[email protected]>
1 parent fb98306 commit 711e207

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/fetch/body.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ const { isUint8Array, isArrayBuffer } = require('util/types')
2222
const { File: UndiciFile } = require('./file')
2323
const { parseMIMEType, serializeAMimeType } = require('./dataURL')
2424

25+
let random
26+
try {
27+
const crypto = require('node:crypto')
28+
random = (max) => crypto.randomInt(0, max)
29+
} catch {
30+
random = (max) => Math.floor(Math.random(max))
31+
}
32+
2533
let ReadableStream = globalThis.ReadableStream
2634

2735
/** @type {globalThis['File']} */
@@ -107,7 +115,7 @@ function extractBody (object, keepalive = false) {
107115
// Set source to a copy of the bytes held by object.
108116
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
109117
} else if (util.isFormDataLike(object)) {
110-
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
118+
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
111119
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
112120

113121
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */

0 commit comments

Comments
 (0)