You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Security improvements needed for password handling.
While the basic password handling and zeroization are good, several security enhancements are recommended:
Add password strength validation
Consider whether trimming passwords is appropriate for security
Use constant-time comparison for password matching
Add validation for empty or whitespace-only passwords
Here's a suggested implementation:
fn get_zeroizing_pw_vec(input: Option<String>) -> Result<Zeroizing<Vec<u8>>> {
if let Some(mut pw_str) = input {
+ if pw_str.trim().is_empty() {+ pw_str.zeroize();+ return Err(anyhow::anyhow!("Password cannot be empty"));+ }+ validate_password_strength(&pw_str)?;
let pw = Zeroizing::new(pw_str.trim().as_bytes().to_owned());
pw_str.zeroize();
return Ok(pw);
}
// First password entry
let mut pw_str = prompt_password("\n\nPlease enter a new password: ")?;
+ if pw_str.trim().is_empty() {+ pw_str.zeroize();+ return Err(anyhow::anyhow!("Password cannot be empty"));+ }+ validate_password_strength(&pw_str)?;
// Second password entry for confirmation
let mut confirm_pw_str = prompt_password("Please confirm your password: ")?;
// Check if passwords match using constant-time comparison
- if pw_str.trim() != confirm_pw_str.trim() {+ if !constant_time_eq(pw_str.trim().as_bytes(), confirm_pw_str.trim().as_bytes()) {
// Clean up sensitive data
pw_str.zeroize();
confirm_pw_str.zeroize();
return Err(anyhow::anyhow!("Passwords do not match"));
}
Add these helper functions:
use constant_time_eq::constant_time_eq;fnvalidate_password_strength(password:&str) -> Result<()>{if password.len() < 12{returnErr(anyhow::anyhow!("Password must be at least 12 characters long"));}let has_uppercase = password.chars().any(|c| c.is_uppercase());let has_lowercase = password.chars().any(|c| c.is_lowercase());let has_digit = password.chars().any(|c| c.is_digit(10));let has_special = password.chars().any(|c| !c.is_alphanumeric());if !(has_uppercase && has_lowercase && has_digit && has_special){returnErr(anyhow::anyhow!("Password must contain uppercase, lowercase, numbers, and special characters"));}Ok(())}
Security improvements needed for password handling.
While the basic password handling and zeroization are good, several security enhancements are recommended:
Here's a suggested implementation:
Add these helper functions:
Originally posted by @coderabbitai[bot] in #156 (comment)
The text was updated successfully, but these errors were encountered: