Security rules

NGB089: Truncated authentication tag

Reports authenticated encryption (AES-GCM, AES-CCM, OCB, ChaCha20-Poly1305) configured with an authentication tag shorter than 128 bits: Web Crypto encrypt / decrypt with tagLength < 128, Node createCipheriv / createDecipheriv with authTagLength < 16 bytes, and GCM decryption that accepts a tag of any length (setAuthTag() without authTagLength and without a visible length check)..

Property Value
Rule ID NGB089
Category Cryptography
Default severity medium
CWE CWE-326, CWE-347
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports authenticated encryption (AES-GCM, AES-CCM, OCB, ChaCha20-Poly1305) configured with an authentication tag shorter than 128 bits: Web Crypto encrypt / decrypt with tagLength < 128, Node createCipheriv / createDecipheriv with authTagLength < 16 bytes, and GCM decryption that accepts a tag of any length (setAuthTag() without authTagLength and without a visible length check).

Why it matters

The tag is what makes AES-GCM tamper-proof. Its forgery resistance shrinks with its length: a 32-bit tag can be forged after a few billion attempts, and with GCM every successful forgery also reveals information about the authentication key. Node accepts GCM tags from 4 to 16 bytes unless authTagLength is fixed, so a decryptor that takes the tag from the message lets an attacker submit a 4-byte tag and brute-force a forgery.

Detection behavior and supported patterns

  • crypto.subtle.encrypt/decrypt({ name: 'AES-GCM', tagLength }, …) with a constant tagLength < 128 (< 96: medium severity, 96–120: low)
  • createCipheriv / createDecipheriv for *-gcm, *-ccm, *-ocb, chacha20-poly1305 with { authTagLength } < 16 bytes
  • createDecipheriv('aes-…-gcm', key, iv) without authTagLength whose result's setAuthTag(tag) is not dominated by a check of the tag's length

Example

TypeScript
await crypto.subtle.encrypt({ name: 'AES-GCM', iv, tagLength: 64 }, key, data);

Safer alternative

TypeScript
await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, data); // 128-bit tag

Remediation

Use the default 128-bit tag (omit tagLength, or pass 128). In Node, pass { authTagLength: 16 } to createDecipheriv() for GCM, or reject tags whose length !== 16 before setAuthTag().

False-positive considerations

  • Protocols that mandate a short tag (some IoT / constrained formats) are reported; document an exception.

Known limitations

  • Tag lengths read from configuration at runtime are not assessed.
  • Length validation in a caller or a helper function is not seen; the decryptor finding is reported with medium confidence.
  • Libraries other than Web Crypto and Node crypto (node-forge, sjcl, libsodium wrappers) are not analyzed.

References

Run it

Shell
ngbastion explain NGB089