[PM-22034] (fix): incomplete zeroization after conversion to ordinary buffers#1379
Merged
Conversation
Issue: midnightntwrk/midnight-security#53 Signed-off-by: Mike Clay <mike.clay@shielded.io> Made-with: Cursor
2cb178e to
bc38557
Compare
Add zeroize dependency and use it to clear intermediate buffers and hex-encoded signing key strings in execute_deploy and execute_maintain to prevent sensitive material from lingering in memory. - Add zeroize = "1" to util/toolkit/Cargo.toml - Import zeroize::Zeroize in toolkit_js/mod.rs - Add zeroize_string helper for heap-allocated Strings - Zeroize raw signing key bytes after hex encoding in deploy - Zeroize hex signing key after toolkit-js execution in deploy - Zeroize new_authority hex after toolkit-js execution in maintain Refs: #53 Signed-off-by: Mike Clay <mike.clay@shielded.io> Made-with: Cursor
…oization - Replace custom zeroize_string helper with direct String::zeroize() from the zeroize crate, eliminating local unsafe. - Fix error-path zeroization gap by zeroizing strings before propagating execute_js errors via ? operator. Signed-off-by: Mike Clay <mike.clay@shielded.io> Made-with: Cursor
Reordered imports to satisfy cargo fmt Signed-off-by: Mike Clay <mike.clay@shielded.io> Made-with: Cursor
Signed-off-by: Mike Clay <mike.clay@shielded.io> Made-with: Cursor
LGLO
reviewed
Apr 23, 2026
LGLO
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incomplete zeroization of intermediate secret buffers in the midnight-node toolkit, ensuring wallet seeds and signing keys are erased from heap memory after use. This addresses audit finding A2 (Low severity) from the Least Authority Node DIFF Audit.
🎫 PM-22034 📐 Engineering
Motivation
The toolkit's signing key type zeroizes on drop, but secret values are converted into ordinary
StringandVec<u8>buffers for CLI argument passing. These containers lack wipe-on-drop guarantees, leaving sensitive material in process memory until the OS reclaims the pages. An attacker with memory read access could recover these secrets long after they should have been erased.This change explicitly zeroizes the intermediate buffers after they are no longer needed, closing the gap identified in the security audit.
Changes
Implementation:
zeroizeimport and azeroize_stringhelper toutil/toolkit/src/toolkit_js/mod.rsVec<u8>serialization buffer inexecute_deployafter hex encodingexecute_deployafterexecute_jsreturnsexecute_maintainafterexecute_jsreturnscargo check), tests (cargo test), and lint (cargo clippy) pass🧪 QA Note — Zeroization Testing
Zeroization correctness (ensuring heap buffers are actually overwritten with zeros before drop) cannot be validated by standard Rust unit tests because the memory is freed immediately afterward and the borrow checker prevents inspecting it. The
zeroizecrate provides this guarantee via volatile writes and compiler fences, and its own upstream tests cover the correctness of the zeroization primitives.For this PR, validation is limited to:
cargo check/cargo clippy)cargo test)zeroizeis called on the correct buffers at the correct pointsIf QA requires dedicated zeroization verification (e.g., Miri runs, custom allocator tests, or manual memory inspection), please flag this before merge and we can add the appropriate test infrastructure.
📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging