We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
randomString
1 parent b3ec8e0 commit e6b96f8Copy full SHA for e6b96f8
middleware/util.go
@@ -74,6 +74,12 @@ func randomString(length uint8) string {
74
r := make([]byte, length+(length/4)) // perf: avoid read from rand.Reader many times
75
var i uint8 = 0
76
77
+ // security note:
78
+ // we can't just simply do b[i]=randomStringCharset[rb%len(randomStringCharset)],
79
+ // len(len(randomStringCharset)) is 52, and rb is [0, 255], 256 = 52 * 4 + 48.
80
+ // make the first 48 characters more possibly to be generated then others.
81
+ // So we have to skip bytes when rb > randomStringMaxByte
82
+
83
for {
84
_, err := io.ReadFull(reader, r)
85
if err != nil {
0 commit comments