Uh oh!
There was an error while loading. Please reload this page.
fix(sec): randomString bias - #2492
Conversation
| } | ||
| // https://tip.golang.org/doc/go1.19#:~:text=Read%20no%20longer%20buffers%20random%20data%20obtained%20from%20the%20operating%20system%20between%20calls | ||
| var randomReaderPool = sync.Pool{New: func() interface{} { |
There was a problem hiding this comment.
bufio.Reader is not thread-safe and sync.Pool perf better than mutex.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@## master #2492 +/- ##
==========================================
+ Coverage 92.77% 92.81% +0.03%
==========================================
Files 39 39 Lines 4635 4646 +11 ==========================================
+ Hits 4300 4312 +12 + Misses 243 242 -1
Partials 92 92
☔ View full report in Codecov by Sentry. |
allright, people like me should not do security related things. @trim21 did not explain what we did before. Previously we had Thank you @trim21 |
@trim21 would you like to add another PR that adds (doc)comment to PRs and their threads on Github are detached from the code and read rarely but library actual code is read more often - so it would be a great place to teach people not to be so security naive. |
trim21
commented
Jul 22, 2023
I'm not very good at English... |
security issue added by #2490
len("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")==52, and256 = 52 * 4 + 48, so the possibility of each characters generated byrandomStringis not equal.A-Za-v: 5/256
wxyz: 4/256
also perfermance improve, in newer (>=1.19) go version,
rand.Readeris not buffered any more, so it's suggested to wraprand.Readerwith bufio if the data read from reader is small.https://tip.golang.org/doc/go1.19#:~:text=Read%20no%20longer%20buffers%20random%20data%20obtained%20from%20the%20operating%20system%20between%20calls