Skip to content

Commit c3acc60

Browse files
committed
Merge commit from fork
* Use crypto.randomInt() Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]>
1 parent 2414bc9 commit c3acc60

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/web/fetch/body.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ const { isErrored, isDisturbed } = require('node:stream')
2020
const { isArrayBuffer } = require('node:util/types')
2121
const { serializeAMimeType } = require('./data-url')
2222
const { multipartFormDataParser } = require('./formdata-parser')
23+
let random
24+
25+
try {
26+
const crypto = require('node:crypto')
27+
random = (max) => crypto.randomInt(0, max)
28+
} catch {
29+
random = (max) => Math.floor(Math.random(max))
30+
}
2331

2432
const textEncoder = new TextEncoder()
2533
function noop () {}
@@ -113,7 +121,7 @@ function extractBody (object, keepalive = false) {
113121
// Set source to a copy of the bytes held by object.
114122
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
115123
} else if (util.isFormDataLike(object)) {
116-
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
124+
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
117125
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
118126

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

0 commit comments

Comments
 (0)