{"id":"GHSA-xg2h-wx96-xgxr","summary":"RandomAlphaNumeric and CryptoRandomAlphaNumeric are not as random as they should be","details":"### Impact\n\nA security-sensitive bug was discovered by Open Source Developer *Erik Sundell of Sundell Open Source Consulting AB*.\n\nThe functions `RandomAlphaNumeric(int)` and `CryptoRandomAlphaNumeric(int)` are not as random as they should be. Small values of `int` in the functions above will return a smaller subset of results than they should. For example, `RandomAlphaNumeric(1)` will always return a digit in the 0-9 range, while `RandomAlphaNumeric(4)` will return around ~7 million of the ~13M possible permutations.\n\nThis is considered a security release because programs that rely upon random generators for passwords are at an increased risk of brute force-style password guessing. There is also a higher probability of collision.\n\nThe problem was the result of a mistaken regular expression that only accepted random strings if they contained a digit from `[0-9]`. That restriction has been removed.\n\n### Patches\n\nThis issue has been corrected in v1.1.1.\n\n### Workarounds\n\nIf you cannot upgrade to v1.1.1, you can work around the issue by calling `RandomAlphaNumericCustom(N, true, true)`|`CryptoRandomAlphaNumericCustom(N, true, true)`  instead. (Where `N` is the desired length, and `true` is the literal boolean `true`.)","aliases":["CVE-2021-4238","GHSA-3839-6r69-m497","GO-2022-0411"],"modified":"2026-07-17T21:15:28.656947609Z","published":"2021-05-21T16:26:06Z","database_specific":{"nvd_published_at":null,"cwe_ids":["CWE-331"],"severity":"LOW","github_reviewed":true,"github_reviewed_at":"2021-05-21T14:36:56Z"},"references":[{"type":"WEB","url":"https://github.com/Masterminds/goutils/security/advisories/GHSA-xg2h-wx96-xgxr"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-4238"},{"type":"WEB","url":"https://github.com/Masterminds/goutils/commit/869801f20f9f1e7ecdbdb6422049d8241270d5e1"},{"type":"WEB","url":"https://github.com/Masterminds/goutils/commit/f1923532a168b8203bfe956d8cd3b17ebece5982"},{"type":"PACKAGE","url":"https://github.com/Masterminds/goutils"},{"type":"WEB","url":"https://github.com/Masterminds/goutils/releases/tag/v1.1.1"},{"type":"WEB","url":"https://pkg.go.dev/vuln/GO-2022-0411"}],"affected":[{"package":{"name":"github.com/Masterminds/goutils","ecosystem":"Go","purl":"pkg:golang/github.com/Masterminds/goutils"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"1.1.1"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2021/05/GHSA-xg2h-wx96-xgxr/GHSA-xg2h-wx96-xgxr.json"}}],"schema_version":"1.9.0"}