In the zip crate (<= 9.0.3), AES password verification in src/aes.rs:187 uses Rust's standard slice inequality operator (!=) instead of constant-time comparison. While constant_time_eq is already a declared dependency in Cargo.toml and is properly utilized elsewhere in the crate for HMAC verification (line 319), its omission during the password verification check creates an observable timing side-channel. An attacker able to measure response latencies or execution times can exploit this short-circuiting comparison to deduce valid password verification bytes, significantly reducing the search space required to decrypt encrypted ZIP entries.
In WinZip AES encryption, the key derivation process derives an encryption key, an authentication key, and a 2-byte password verification value (pwd_verify) using PBKDF2 with HMAC-SHA1.
In src/aes.rs:L186-L190:
// the last 2 bytes should equal the password verification value
if pwd_verification_value != pwd_verify {
// wrong password
return Err(ZipError::InvalidPassword);
}The operator != on byte slices (&[u8]) short-circuits immediately upon encountering the first non-matching byte:
false after inspecting only byte 0.false.
In contrast, lines 318-321 of the exact same file (src/aes.rs) demonstrate that constant-time comparison was intended and implemented for HMAC authentication:// use constant time comparison to mitigate timing attacks
if !constant_time_eq(computed_auth_code, &read_auth_code) {
return Err(auth_error());
}Omitting constant_time_eq at line 187 breaks cryptographic defense-in-depth and exposes password verification to byte-by-byte timing discrepancy attacks.
Update src/aes.rs:187 to use constant_time_eq:
use constant_time_eq::constant_time_eq;
// the last 2 bytes should equal the password verification value (constant-time)
if !constant_time_eq(&pwd_verification_value, pwd_verify) {
// wrong password
return Err(ZipError::InvalidPassword);
}The following unit test demonstrates the vulnerability and verifies that constant_time_eq eliminates the short-circuiting discrepancy:
use constant_time_eq::constant_time_eq;
#[test]
fn test_aes_password_verification_constant_time() {
let expected = [0xAA, 0xBB];
let mismatch_first_byte = [0x00, 0xBB];
let mismatch_second_byte = [0xAA, 0x00];
let matching = [0xAA, 0xBB];
// Standard inequality short-circuits on byte 0 for mismatch_first_byte,
// but inspects byte 1 for mismatch_second_byte.
assert_ne!(mismatch_first_byte, expected);
assert_ne!(mismatch_second_byte, expected);
// Constant-time verification guarantees fixed-duration comparison:
assert!(!constant_time_eq(&mismatch_first_byte, &expected));
assert!(!constant_time_eq(&mismatch_second_byte, &expected));
assert!(constant_time_eq(&matching, &expected));
}Vulnerability Class: Observable Timing Discrepancy (CWE-208) / Covert Timing Channel (CWE-385). Who is Impacted:
소스: NVD
무료 취약점 평가
9개 보안 영역에서 클라우드 보안 관행을 평가하여 위험 수준을 벤치마킹하고 방어의 허점을 파악하세요.
맞춤형 데모를 받아보세요
"내가 본 최고의 사용자 경험은 클라우드 워크로드에 대한 완전한 가시성을 제공합니다."
"Wiz는 클라우드 환경에서 무슨 일이 일어나고 있는지 볼 수 있는 단일 창을 제공합니다."
"우리는 Wiz가 무언가를 중요한 것으로 식별하면 실제로 중요하다는 것을 알고 있습니다."