Skip to content

Commit c2d78cd

Browse files
authored
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 fa1d840 commit c2d78cd

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
@@ -17,6 +17,14 @@ const { isErrored, isDisturbed } = require('node:stream')
1717
const { isArrayBuffer } = require('node:util/types')
1818
const { serializeAMimeType } = require('./data-url')
1919
const { multipartFormDataParser } = require('./formdata-parser')
20+
let random
21+
22+
try {
23+
const crypto = require('node:crypto')
24+
random = (max) => crypto.randomInt(0, max)
25+
} catch {
26+
random = (max) => Math.floor(Math.random(max))
27+
}
2028

2129
const textEncoder = new TextEncoder()
2230
function noop () {}
@@ -110,7 +118,7 @@ function extractBody (object, keepalive = false) {
110118
// Set source to a copy of the bytes held by object.
111119
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
112120
} else if (webidl.is.FormData(object)) {
113-
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
121+
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
114122
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
115123

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

0 commit comments

Comments
 (0)