Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

random string with CSPRNG #24

Open
ericelliott opened this issue Dec 9, 2015 · 6 comments
Open

random string with CSPRNG #24

ericelliott opened this issue Dec 9, 2015 · 6 comments

Comments

@ericelliott
Copy link
Contributor

A CSPRNG random string generator with a CLI would be very useful for things like generating the cookie secret, etc...

Is something like that already available?

The current Math.random() implementation is quite weak, cryptographically speaking, and should not be used for those purposes.

@morenoh149
Copy link

@ericelliott
Copy link
Contributor Author

Cool. Should we replace our random string util with this? Maybe our generators should also offer to generate the cookie secret? =)

@morenoh149
Copy link

Do the generators already generate a cookie secret? looks like https://github.com/keystonejs/generator-keystone/search?utf8=%E2%9C%93&q=cookieSecret&type=Code this.cookieSecret is defined and then placed in the .env file. Or is that not working?

@morenoh149 morenoh149 self-assigned this Dec 9, 2015
@morenoh149
Copy link

@JedWatson does keystone-utils have to work in the browser as well? this affects the solution

@ericelliott
Copy link
Contributor Author

Yes, but it uses Math.random() to do it, which is not safe for this purpose. It should use a CSPRNG like crypto.randomBytes() (used in node-csprng).

I believe it's safe to use crypto.randomBytes() in the browser using browserify and Webpack.

@morenoh149
Copy link

https://github.com/keystonejs/generator-keystone/blob/89419a6fb41b0cd744937f441c2d46229b775a30/app/index.js#L284 uses utils.randomString and that's implemented using jed's own randomkey package https://github.com/keystonejs/keystone-utils/blob/master/lib/index.js#L232 maybe the randomkey package should be augmented to provide a CSPRNG option.

I'm inclined to simply use crypto.randomBytes in the generator instead of changing the utils too much.

@morenoh149 morenoh149 removed their assignment Dec 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants