Blog / A02:2021 Cryptographic Failures
A02:2021 · Cryptographic Failures

Let callers set the tag length and they'll set it short

An AEAD wrapper accepted any tag length and passed it to the cipher unchanged. At the call site the safe values and the weak ones looked identical.

the caller passesany tag lengththe wrapperforwards it…a short length issilently acceptedthe tag spaceshrinksforgery becomesfeasibleATTACKER INPUTIMPACToutput is predictable
Attack path · the caller passes any tag length → the wrapper forwards it to the AEAD parameters → a short length is silently accepted → the tag space shrinks → forgery becomes feasible

An AEAD wrapper accepted any tag length and passed it to the cipher unchanged. At the call site the safe values and the weak ones looked identical.

What goes wrong

An unconstrained integer parameter reads as configurable, and configurable knobs drift toward whatever value once made a test go green. That is how a tag length ends up at four bytes in production without anyone deciding it should be.

The tag is the integrity half of AEAD. Shrink it and you keep confidentiality while giving away the guarantee that ciphertext wasn't tampered with. This wrapper took the length as-is and handed it to the cipher parameters, so a caller anywhere in the codebase could weaken every message that path encrypts. It is a Medium and worth fixing calmly, but the fix is not subtle. Put a floor in the type and default the value when it's omitted.

The pattern

Vulnerable
class Sealer {
  private final Aead aead;
  Sealer(byte[] key, int tagLen) {
    // tagLen is unchecked
    this.aead = new Aead(key, tagLen * 8);
  }
}
Hardened
class Sealer {
  private static final int MIN_TAG = 16;  // 128 bits
  Sealer(byte[] key, int tagLen) {
    if (tagLen < MIN_TAG)
      throw new IllegalArgumentException("weak tag length rejected");
    this.aead = new Aead(key, tagLen * 8);
  }
}
How the pipeline adjudicated itPROVEN
ABCDEFGH

Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

A parameter that can be safe or dangerous with no visible difference is a bug the reviewer will miss and the next engineer will trip on. The safest API is the one that cannot express the weak choice.

Bake the minimum into the constructor and give the length a sane default. Then the only way to get a strong tag is the only way there is.

Check your own code