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
class Sealer {
private final Aead aead;
Sealer(byte[] key, int tagLen) {
// tagLen is unchecked
this.aead = new Aead(key, tagLen * 8);
}
}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);
}
}Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
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
- Give AEAD wrappers a constant minimum tag length instead of a caller-chosen one.
- Default an omitted tag length to 128 bits.
- Add a test asserting a four-byte tag request is rejected.