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

[Linter] Flag usage of weak PRNG #4514

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ linters-settings:
go: "1.21.9"

gosec:
includes:
- G404 # Use of weak random number generator
excludes:
- G306 # Expect WriteFile permissions to be 0600 or less
- G404 # Use of weak random number generator
- G401 # Detect the usage of DES, RC4, MD5 or SHA1: Used in non-crypto contexts.
- G501 # Import blocklist: crypto/md5: Used in non-crypto contexts.
- G505 # Import blocklist: crypto/sha1: Used in non-crypto contexts.
10 changes: 10 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2817,3 +2817,13 @@ func getOtelDependencies() (*dependencies, error) {
Extensions: extensions,
}, nil
}

// TODO: remove after testing linter for https://github.com/elastic/elastic-agent/pull/4514
func RandomPassword(passwordLength int) string {
runes := []rune("abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*ABCDEFGHIJKLMNOPQRSTUVWXYZ")
var sb strings.Builder
for i := 0; i < passwordLength; i++ {
sb.WriteRune(runes[rand.Intn(len(runes))])
}
return sb.String()
}
Loading