Skip to content

Commit cde0761

Browse files
authored
chore: upper limits on argon hash params (#2458)
## What kind of change does this PR introduce? chore ## What is the current behavior? Argon parameters are unbound ## What is the new behavior? Binds the argon hash parameters to sane limits
1 parent c17e1f5 commit cde0761

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

internal/crypto/password.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,25 @@ func ParseArgon2Hash(hash string) (*Argon2HashInput, error) {
193193
if err != nil {
194194
return nil, fmt.Errorf("crypto: argon2 hash has invalid m parameter %q %w", m, err)
195195
}
196+
if memory > 1024*1024 { // 1 GiB in KiB
197+
return nil, fmt.Errorf("crypto: argon2 hash has m parameter %d exceeds memory limit", memory)
198+
}
196199

197200
time, err := strconv.ParseUint(t, 10, 32)
198201
if err != nil {
199202
return nil, fmt.Errorf("crypto: argon2 hash has invalid t parameter %q %w", t, err)
200203
}
204+
if time > 20 {
205+
return nil, fmt.Errorf("crypto: argon2 hash has t parameter %d exceeds time limit", time)
206+
}
201207

202208
threads, err := strconv.ParseUint(p, 10, 8)
203209
if err != nil {
204210
return nil, fmt.Errorf("crypto: argon2 hash has invalid p parameter %q %w", p, err)
205211
}
212+
if threads > 16 {
213+
return nil, fmt.Errorf("crypto: argon2 hash has p parameter %d exceeds thread limit", threads)
214+
}
206215

207216
rawHash, err := base64.RawStdEncoding.DecodeString(hashB64)
208217
if err != nil {

0 commit comments

Comments
 (0)