Skip to content

Commit

Permalink
feat(remix-node): use Web Crypto API in createFileSessionStorage (#…
Browse files Browse the repository at this point in the history
…7203)

Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
MichaelDeBoey and brophdawg11 authored Aug 30, 2023
1 parent 00d1f39 commit 10d95f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/node-web-crypto.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/node": patch
---

Switch from `crypto.randomBytes` to `crypto.webcrypto.getRandomValues` for file session storage ID generation
2 changes: 1 addition & 1 deletion packages/remix-node/sessions/fileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createFileSessionStorage<Data = SessionData, FlashData = Data>({
while (true) {
// TODO: Once Node v19 is supported we should use the globally provided
// Web Crypto API's crypto.getRandomValues() function here instead.
let randomBytes = crypto.randomBytes(8);
let randomBytes = crypto.webcrypto.getRandomValues(new Uint8Array(8));
// This storage manages an id space of 2^64 ids, which is far greater
// than the maximum number of files allowed on an NTFS or ext4 volume
// (2^32). However, the larger id space should help to avoid collisions
Expand Down

0 comments on commit 10d95f0

Please sign in to comment.