cloudflare / cloudflare/workerd
🐛 `crypto.randomBytes` errors for values above 65536
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
With the following worker and `nodejs_compat`, you'll receive an error:
```ts
import crypto from 'node:crypto';
export default {
async fetch(request, env, ctx): Promise {
const random = crypto.randomBytes(65537).toString('hex');
return new Response(random);
},
} satisfies ExportedHandler;
```
errors with ` QuotaExceededError: getRandomValues() only accepts buffers of size <= 64K but provided 65537 bytes.`.
VS in Node.js where this works fine:
```ts
import crypto from 'node:crypto';
const random = crypto.randomBytes(65537).toString('hex');
console.log(random);
```
I discovered this entirely by accident when passing the wrong variable to `randomBytes`, but figured it was worth reporting for Node.js compat conformance.
Contributor guide
Assessment
This issue has not been assessed yet.