Secret Memory Leakage Due to Extensive Cloning #979
Labels
No labels
DB & Storage
Deployment
Error Handling & Logging
Maintenance
Payment Backend
backport
backport v0.13.x
backport v0.14.x
backport v0.15.x
bindings
blocked
bug
cdk-sql
ci
cli
deps
documentation
duplicate
enhancement
good first issue
help wanted
invalid
keep-open
ldk-node-ui
migrations
mint
mutation-testing
needs rebase
needs review
new nut
nut change
question
ready
rust-version
rustfmt
stacked hold
stale
testing
wallet
weekly-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cashubtc/cdk#979
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Description
The CDK codebase has a fundamental security issue where cryptographic secrets are copied throughout memory without proper cleanup. The
Secrettype implementsClone, which creates copies that persist in memory even when the original secret goes out of scope.Current State Analysis
Secret Cloning Hotspots
The
Secrettype is cloned extensively throughout the codebase:The Fundamental Issue
Secret::generate()creates a secretProofstructs via.clone()ProofV3 ↔ ProofV4 ↔ Proof) clone secrets againsecrets()clone all secrets in a collectionResult: Secret data scattered throughout memory in multiple uncleared copies.
Security Impact
Proposed Solution: Reference-Counted Secure Secrets
Implement an
Arc<SecretBox>approach where all "clones" share the same underlying secret data.Implementation
All existing trait implementations work the same way.
Benefits
Clonecalls continue to workArcprovides safe sharing across threadsTrade-offs
Arcreference counting adds minimal performance costMigration Strategy
SecureSecrettype alongside existingSecretSecureSecrettype Secret = SecureSecret;alias in major versionAlternative Approaches Considered
Request for Feedback
Would the maintainers be open to:
Arcreference counting?This represents a meaningful security improvement without breaking existing APIs.
In the cdk call we determined that we can skip most of the example code and replace it with a manual drop impl that zeroizes the memory before releasing it. It was also suggested to start with the seed phrase, although I see no reason to skip this safety measure for other secrets.