Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security issue - Usage of a predictable RNG #2

Open
gargakshit opened this issue Jul 5, 2021 · 0 comments · May be fixed by #3
Open

Security issue - Usage of a predictable RNG #2

gargakshit opened this issue Jul 5, 2021 · 0 comments · May be fixed by #3

Comments

@gargakshit
Copy link

gargakshit commented Jul 5, 2021

This uses JavaScript's Math.random which is not a cryptographically secure random number generator. Therefore the generated numbers are not totally random, and predictable.

password += chars.charAt(Math.floor(Math.random() * chars.length))

This means the generated passwords can be predicted. Using this to generate passwords is a huge security flaw.

A quick fix would be to use crypto.randomBytes(number) from node's crypto module, or Crypto.getRandomValues() in a (relatively modern) browser.

Edit: Crypto.getRandomValues() seems to be implemented in node 15.0.0+, so it should be a universal solution for node 15+ and browsers

@danBamikiya danBamikiya linked a pull request Jul 5, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant