docs: use crypto.randomBytes for custom filename example (#1386)#1392
Open
SAY-5 wants to merge 1 commit intoexpressjs:mainfrom
Open
docs: use crypto.randomBytes for custom filename example (#1386)#1392SAY-5 wants to merge 1 commit intoexpressjs:mainfrom
SAY-5 wants to merge 1 commit intoexpressjs:mainfrom
Conversation
) The custom `diskStorage` example in the README used `Date.now() + Math.round(Math.random() * 1E9)` to build a unique filename suffix, which is exactly the pattern production apps copy when they need a custom `filename` (e.g. to preserve a file extension). `Math.random()` is not cryptographically secure — V8's xorshift128+ state can be recovered from a small sample of outputs — and combined with `Date.now()` the entropy is effectively ~30 bits, which is enumerable when uploads land in a web-accessible directory. Multer's built-in default already uses `crypto.randomBytes(16)` (`storage/disk.js:6-9`). Update the README to teach the same pattern so copy-paste users get the secure default by construction. No code changes. Docs only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1386.
The custom `diskStorage` example in the README uses `Date.now() + Math.round(Math.random() * 1E9)` to build the unique filename suffix. That's the pattern production apps copy when they need a custom `filename` to keep the file extension or add a field-based prefix, so the insecure form ends up in a lot of deployed code.
The issue is that:
Multer's own built-in default already uses `crypto.randomBytes(16)` (`storage/disk.js:6-9`). This PR just updates the README's custom-`filename` example to teach the same pattern so copy-paste users get the secure default by construction.
No code changes — docs only.