Skip to content

fix: zero AWS KMS plaintext keys from memory after use - #41

Open
lakshyaog wants to merge 1 commit into
Swapso-App:mainfrom
lakshyaog:lakshyaog03
Open

fix: zero AWS KMS plaintext keys from memory after use#41
lakshyaog wants to merge 1 commit into
Swapso-App:mainfrom
lakshyaog:lakshyaog03

Conversation

@lakshyaog

Copy link
Copy Markdown

Security Fix:

  • Added immediate key zeroing in encryptMnemonic() after encryption
  • Added immediate key zeroing in decryptMnemonic() after decryption
  • Prevents memory dump attacks by destroying sensitive cryptographic material
  • Keys are now zeroed using Buffer.fill(0) immediately after use

Issue:
AWS KMS plaintext data keys were persisting in RAM after encryption/ decryption operations. If an attacker gained access to process memory (via memory dump, debugging, or system compromise), they could extract these keys and decrypt any mnemonic encrypted with them, leading to complete wallet compromise.

Solution:
The fix ensures plaintext keys are overwritten with zeros immediately after cryptographic operations, following security best practices for handling sensitive key material. This matches the existing security patterns used in btc-controller for private key handling.

Testing:

  • Added test-key-zeroing.js to verify basic key zeroing functionality
  • Added test-actual-fix.ts to verify encryption/decryption with zeroing
  • Added SECURITY-FIX-VERIFICATION.md with complete documentation
  • All tests pass successfully

Impact:

  • Eliminates memory-based key extraction vulnerability
  • Provides production-grade security for wallet operations
  • No breaking changes to existing API

Security Fix:
- Added immediate key zeroing in encryptMnemonic() after encryption
- Added immediate key zeroing in decryptMnemonic() after decryption
- Prevents memory dump attacks by destroying sensitive cryptographic material
- Keys are now zeroed using Buffer.fill(0) immediately after use

Issue:
AWS KMS plaintext data keys were persisting in RAM after encryption/
decryption operations. If an attacker gained access to process memory
(via memory dump, debugging, or system compromise), they could extract
these keys and decrypt any mnemonic encrypted with them, leading to
complete wallet compromise.

Solution:
The fix ensures plaintext keys are overwritten with zeros immediately
after cryptographic operations, following security best practices for
handling sensitive key material. This matches the existing security
patterns used in btc-controller for private key handling.

Testing:
- Added test-key-zeroing.js to verify basic key zeroing functionality
- Added test-actual-fix.ts to verify encryption/decryption with zeroing
- Added SECURITY-FIX-VERIFICATION.md with complete documentation
- All tests pass successfully

Impact:
- Eliminates memory-based key extraction vulnerability
- Provides production-grade security for wallet operations
- No breaking changes to existing API
@lakshyaog

Copy link
Copy Markdown
Author

Title: fix: zero AWS KMS plaintext keys from memory after use
Description: Use the content from PR-DESCRIPTION.md (I wrote it for you!)

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.

1 participant