Skip to content
Crypto Disclosed report Advanced

Missing AES-GCM Authentication Tag Validation and Improper Deprecation Handling

Node.js's createDecipheriv does not enforce the documented default 16-byte authentication tag length for AES-GCM, allowing truncated tags of 4 to 15 bytes to be accepted. An attacker could brute-force a truncated tag after modifying a ciphertext, potentially recovering key material to forge further tags offline.

sideni Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Disclosed after 6 days

Summary: In Node.js' crypto module, the createDecipheriv states that "the authTagLength option defaults to 16 bytes and must be set to a different value if a different length is used." (here) The authentication tag's length is however not validated against that default value and can be truncated down to either 4, 8, 12, 13, 14, or 15 bytes. (here) This allows an attacker to brute force an authentication tag after modifying a ciphertext and recover the key material to compute more authentication tags offline afterwards.

Description: These authenticated encryption schemes are frequently used to protect some session or some token. An attacker could exploit this flaw by changing a valid ciphertext and by bruteforcing the new authentication tag on the server (with at most 12,884,902,656 requests : (2**32) * 3 + 2 * 256) to gain a valid session/token. This also results in a nonce reuse with AES-GCM which leaks the key needed to compute any further authentication tags (see this blogpost). Note that 12 billion requests are not necessarily needed as one could use the truncated tag to recover the needed key (see this cryptopals challenge).

With the key needed to compute arbitrary authentication tags, an attacker can manipulate a ciphertext to decrypt it and to forge a new one.

I understand implicit shorter tag lengths have been deprecated with this PR, the deprecation warning however is only emitted when the tag is actually shorter than 16 bytes. For people using the function as documented (i.e. expecting the authTagLength option to default to 16 bytes), the warning is never shown unless an attack is on the way.

Steps To Reproduce:

The following script shows how the default authTagLength of 16 bytes is not enforced and allows for implicit shorter tags. It also shows that the deprecation warning is only shown when an attacker truncates the authentication tag (or when it's explicitly truncated, but that's not the scenario where people are in unknown danger).

JavaScript
const {
    createCipheriv,
    createDecipheriv
} = require('crypto');

const key = 'key0123456789key';
const nonce = '123456789012';

var algo = 'aes-128-gcm';
const cipher = createCipheriv(algo, key, nonce);
const plaintext = 'This is some plaintext';

const ciphertext = cipher.update(plaintext, 'utf8');
cipher.final();
const tag = cipher.getAuthTag();


var decipher = createDecipheriv(algo, key, nonce);
decipher.setAuthTag(tag);
var decryptedPlaintext = decipher.update(ciphertext, null, 'utf8') + decipher.final();

console.log('Decrypted with full tag: ' + decryptedPlaintext);

console.log('---------------------------------');

decipher = createDecipheriv(algo, key, nonce);
// Truncating the authentication tag
decipher.setAuthTag(tag.subarray(0, 4));
decryptedPlaintext = decipher.update(ciphertext, null, 'utf8') + decipher.final();
console.log('Decrypted with truncated tag: ' + decryptedPlaintext);

Observe how the deprecation warning message is only shown for the latter and how a truncated authentication tag successfully allowed decryption (even if "the authTagLength option defaults to 16 bytes and must be set to a different value if a different length is used.)

Screenshot_from_2025-12-13_11-17-31.png
Screenshot_from_2025-12-13_11-17-31.png From the original on HackerOne

###For code references: The deprecation warning message is emitted here. The auth tag is set with setAuthTag in which the tag length taken here is set implicitly here.

Impact

  • Ciphertexts can be modified to decrypt to an arbitrary value
  • Ciphertexts can be decrypted by observing parsing differences
    • For example, if the decrypted data is expected to be JSON, it's possible to observe valid/invalid JSON parsing to decrypt the ciphertext just like with padding oracles
  • The GCM internal GHASH key can be recovered (to compute more arbitrary authentication tags without need for bruteforce)
    • Requires rotation of the encryption keys

Considering how the createDecipheriv function is documented, this completely breaks the integrity and confidentiality of the encryption scheme that people expect from this API.

The original report as published on HackerOne, by sideni. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could modify ciphertexts to decrypt to arbitrary values, decrypt ciphertexts by observing parsing differences, and recover the GCM internal GHASH key, requiring rotation of encryption keys.

What the attacker needed

Ability to modify ciphertext and submit tags; server uses AES-GCM with default tag length

The fix

The tag length should be validated against the documented 16-byte default, and the deprecation warning should appear whenever a shorter tag is used.

How it was found

  1. Create a cipher with AES-128-GCM and a key and nonce, encrypt a plaintext, and obtain the authentication tag.
  2. Create a decipher with the same key and nonce, set the full authentication tag, and decrypt successfully.
  3. Create another decipher, truncate the authentication tag to 4 bytes, set it, and observe that decryption still succeeds.
  4. Note that the deprecation warning is only shown for the truncated tag case, not for the full tag case.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

AES-GCM is a way to encrypt data that also adds a short 'tag' to prove the data has not been changed. Node.js says this tag should be 16 bytes by default, but it actually accepts much shorter tags, which are far easier to guess. If an attacker can guess a short tag, they may be able to tamper with encrypted data or even work out the secret key.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.