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

fix security flaw in generateRandomBytes #14

Closed
wants to merge 1 commit into from
Closed

fix security flaw in generateRandomBytes #14

wants to merge 1 commit into from

Conversation

s0rg
Copy link

@s0rg s0rg commented Aug 2, 2022

You need to use io.ReadFull instead of rand.Read.
Please see this issue: satori/go.uuid#73

@alexedwards
Copy link
Owner

Please double-check my understanding of this, but as far as I can see this package uses the crypto/rand package from the standard library and calls rand.Read() to generate the random bytes.

The documentation for rand.Read() says:

Read is a helper function that calls Reader.Read using io.ReadFull. On return, n == len(b) if and only if err == nil.

Looking at the source code for rand.Read() confirms that it uses io.ReadFull behind the scenes. See https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/crypto/rand/rand.go;l=24.

In the issue you linked to in the description, it looks like rand did not reference the crypto/rand package, but rather a struct field with the type io.Reader, which is what led to the problem for that package.

As far as I can see, that's not the case here, and a full read is already ensured by using rand.Read() from crypto/rand.

@s0rg
Copy link
Author

s0rg commented Aug 4, 2022

I missed this fix in crypto/rand thank you.

Youre code is correct )

@s0rg s0rg closed this Aug 4, 2022
@s0rg s0rg deleted the feature/fix_random_bytes branch August 4, 2022 07:25
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 this pull request may close these issues.

2 participants