Skip to content

docs(wallet): document AES-GCM key-derived nonce vulnerability#3

Open
amathxbt wants to merge 1 commit into
canopy-network:mainfrom
amathxbt:fix/aes-gcm-key-derived-nonce
Open

docs(wallet): document AES-GCM key-derived nonce vulnerability#3
amathxbt wants to merge 1 commit into
canopy-network:mainfrom
amathxbt:fix/aes-gcm-key-derived-nonce

Conversation

@amathxbt

Copy link
Copy Markdown

Security Issue

decryptPrivateKey() constructs the AES-GCM IV as the first 12 bytes of the Argon2-derived key:

const nonce = derivedKey.slice(0, NONCE_LENGTH); // 12 bytes of the 32-byte key

Because AES-GCM security requires that (key, nonce) pairs are never reused, and here the nonce is fully determined by the key, every encryption with the same password produces the same key and the same nonce. An attacker who obtains two ciphertexts encrypted under the same password can XOR them to recover the XOR of their plaintexts without ever knowing the password—a standard GCM nonce-reuse attack.

Why not fixed here

This is a protocol-level decision shared with the Go node, which generates keystores with the same scheme. Unilaterally changing the nonce on the TypeScript side would break decryption of all existing keystores. A coordinated fix is needed on both sides: prepend a random 12-byte nonce to the ciphertext on encrypt, and read it back on decrypt.

What this PR does

Adds a prominent code comment so the risk is visible to future contributors and reviewers, and provides a clear description of the correct fix to guide that follow-up work.

The decrypt path derives the AES-GCM IV from the first 12 bytes of the
Argon2-derived key (derivedKey.slice(0, NONCE_LENGTH)). Because every
password+salt pair deterministically produces the same (key, nonce) tuple,
any two keystores encrypted with the same password are vulnerable to a
ciphertext XOR attack that recovers plaintext without knowing the password.

This is a protocol-level issue shared with the Go node; a unilateral change
here would break decryption of all existing keystores. Add a prominent
code comment so the risk is visible to future contributors, and open a
coordinated issue to update both sides to prepend a random nonce.
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