-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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(sec): randomString
bias
#2492
Conversation
@@ -55,17 +57,38 @@ func matchSubdomain(domain, pattern string) bool { | |||
return false | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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 byrandomString
is not equal.A-Za-v: 5/256
wxyz: 4/256
also perfermance improve, in newer (>=1.19) go version,
rand.Reader
is not buffered any more, so it's suggested to wraprand.Reader
with 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