Skip to content

Commit ce8c3ab

Browse files
fix: Potential fix for code scanning alert no. 22: Slice memory allocation with excessive size value (#6)
* Potential fix for code scanning alert no. 22: Slice memory allocation with excessive size value Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: use maxRandomPasswordLength constant in error message instead of hardcoded 4096 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent a9e2f31 commit ce8c3ab

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/services/secretsmanager/provider.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,16 @@ func (p *Provider) cancelRotateSecret(params map[string]any) (*plugin.Response,
426426
// allowedChars is the default character pool for random passwords.
427427
const allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?"
428428

429+
// maxRandomPasswordLength caps user-controlled password length to prevent
430+
// excessive memory allocation from untrusted input.
431+
const maxRandomPasswordLength = 4096
432+
429433
func (p *Provider) getRandomPassword(params map[string]any) (*plugin.Response, error) {
430434
length := 32
431-
if l, ok := params["PasswordLength"].(float64); ok && l > 0 {
435+
if l, ok := params["PasswordLength"].(float64); ok {
436+
if l <= 0 || l > maxRandomPasswordLength {
437+
return smError("InvalidParameterException", fmt.Sprintf("PasswordLength must be between 1 and %d", maxRandomPasswordLength), http.StatusBadRequest), nil
438+
}
432439
length = int(l)
433440
}
434441
excludeChars, _ := params["ExcludeCharacters"].(string)

0 commit comments

Comments
 (0)