Skip to content

fix: Zeroize derived_key when dropped, and suppress error details that may be sensitive#803

Merged
Pr0methean merged 5 commits intomasterfrom
ai-findings-autofix/src-aes.rs
May 3, 2026
Merged

fix: Zeroize derived_key when dropped, and suppress error details that may be sensitive#803
Pr0methean merged 5 commits intomasterfrom
ai-findings-autofix/src-aes.rs

Conversation

@Pr0methean
Copy link
Copy Markdown
Member

This PR applies 3/5 suggestions from code quality AI findings. 2 suggestions were skipped to avoid creating conflicts.

Pr0methean and others added 3 commits May 2, 2026 17:27
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this PR apply 3 code quality improvements to the AES implementation:

  1. Array size constants (lines 82, 84, 86): Replaces .salt_length() method calls with hardcoded constants for AES salt array sizes. This is correct and necessary for const array declarations.

  2. Memory security (lines 208-209): Wraps derived_key with Zeroizing to ensure sensitive cryptographic key material is securely erased from memory when dropped. This is a security improvement.

  3. Error handling (lines 225-226): Simplifies HMAC initialization error message and marks error variable as unused with _e prefix.

All changes are correct implementations that improve code quality without introducing defects.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/aes.rs Fixed
@Pr0methean Pr0methean changed the title Potential fixes for 3 code quality findings fix: Zeroize derived_key when dropped May 3, 2026
@Pr0methean Pr0methean changed the title fix: Zeroize derived_key when dropped fix: Zeroize derived_key when dropped, and suppress error details that may be sensitive May 3, 2026
@Pr0methean Pr0methean marked this pull request as ready for review May 3, 2026 00:30
@Pr0methean Pr0methean enabled auto-merge May 3, 2026 00:30
@Pr0methean Pr0methean added this to the 9.0.0 milestone May 3, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces security enhancements by using Zeroizing for derived keys and modifies salt length definitions and error handling. Feedback suggests avoiding hardcoded magic numbers for salt lengths by reverting to dynamic calculations and recommends retaining detailed error messages during HMAC initialization to aid debugging and ensure consistency.

I am having trouble creating individual review comments. Click here to see my feedback.

src/aes.rs (82-86)

medium

This change replaces the dynamic calculation of salt lengths with hardcoded magic numbers. The previous implementation using AesMode::AesXXX.salt_length() was more maintainable and less error-prone, as it derived the values from a single source of truth. Please consider reverting to the previous implementation. If the original code was causing compilation issues, it would be better to define local constants derived from AesMode to avoid magic numbers.

    Aes128([u8; AesMode::Aes128.salt_length()]),
    /// AES 192 salt
    Aes192([u8; AesMode::Aes192.salt_length()]),
    /// AES 256 salt
    Aes256([u8; AesMode::Aes256.salt_length()]),

src/aes.rs (225-227)

security-medium medium

This change removes the underlying error details when HMAC initialization fails, which can make debugging more difficult. The original error from new_from_slice is of type InvalidLength and its message "Invalid key length" does not leak sensitive information but provides valuable context. It would be better to retain this information.

Additionally, a similar error handling logic exists in AesWriter::new_with_options (line 379) which has not been changed, leading to inconsistency. It would be best to handle both cases consistently.

        let hmac = SimpleHmacReset::<Sha1>::new_from_slice(hmac_key).map_err(|e| {
            ZipError::Io(std::io::Error::other(format!("Failed to initialize HMAC: {e}")))
        })?;
References
  1. Ensure that sensitive information like passwords is not exposed in plain text through derived Debug implementations. Manually implement the Debug trait to redact such information.

Comment thread src/aes.rs Dismissed
@Pr0methean Pr0methean added this pull request to the merge queue May 3, 2026
Merged via the queue into master with commit 4f23a35 May 3, 2026
133 checks passed
@Pr0methean Pr0methean deleted the ai-findings-autofix/src-aes.rs branch May 3, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants