-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
chore: Enable G404 rule for gosec #13095
Conversation
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.
github.com/chanxuehong/rand
Why use this over using "crypto/rand" directly? I realize this is a small addition, but if we can do it without yet another dependency I would prefer that.
@powersj And this is API of crypto/rand: This library provides almost the same API as Alternatively we can write our own wrapper... |
I am aware of the larger API. My question is in order to justify the addition of a dependency that has not been updated in 2 years with what appears to be near zero usage can you report how many of those functions we would need to wrap instead? |
|
@powersj Alternatively, we can just copy these 4-5 files to our repo, review correctness of algorithms (eg. compare with current implementation of |
Thanks for looking into how many functions we actually use. With only 5 functions I would prefer we have our own copys in internal and not add the external dependency please. I don't think we should wholesale copy that project, but instead just write replacements for those 5 functions. Thanks again |
@powersj
|
these two are for random sleep and random duration, probably not something that needs to be cryptographically secure, can ignore
example plugin, don't care about this other than maybe removing it from the example as a bad practice?
used for generating random, non-critical data, can ignore
used to set up socket file with random-ish name, can ignore
both pick random index, can ignore |
@powersj Do you propose we should not enable this rule at all or we should enable it and ignore all tests occurences (in |
I'd like to hear from @srebhan if he agrees with my assessment above first. However, I am leaning towards not enabling. |
@srebhan A penny for your thoughts :) |
@zak-pawel usually I'm paid in beer... ;-P In my opinion we should enable G404 to make us aware about weak RNGs during review. Otherwise I would silence the following occurrences without any code change:
For the following occurrences I suggest modifying the code as follows:
Does that help? |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 🥳 This pull request decreases the Telegraf binary size by -2.33 % for linux amd64 (new size: 168.8 MB, nightly size 172.8 MB) 📦 Click here to get additional PR build artifactsArtifact URLs |
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.
Nice. Thanks @zak-pawel!
(cherry picked from commit 30b6036)
PR:
math/rand
, except that it prefers to usecrypto/rand
to implement functions.gosec:G404
rule.gosec G404: Use of weak random number generator (math/rand instead of crypto/rand)
for production code.resolves: #12949