- changed status to open
Incorrect validation of secret length for MACVerifier
Issue #563
resolved
I am aware of issue #454…
However, the secret length validation is done very minimalisticly. If the intention is to validate the correct secret length for the provided algorithm, the check should reflect the algorithm selected, not just check for:
if (secret.length < 32) {
throw new KeyLengthException("The secret length must be at least 256 bits");
} else {
this.secret = secret;
this.secretKey = null;
}
IMO, this check is redundant altogether. Auth0 can live without it, as authenticating the MAC token with, i.e., 16B is quite sufficient…
Comments (3)
-
-
reporter The point is that you do a correct check for 256 bits but not for all other algorithms… For HS512, your check is incorrect…
-
- changed status to resolved
MACVerifier must enforce a minimum secret key length of 384 bits for HS384 and of 512 bits for HS512: bda30fd8144282b092bab3cfd04634803375fd29
- Log in to comment
It's true that the Mac can be initialised with shorter keys. Like you I have observed that some libs will not check the key length or accept shorter lengths. The JWA spec is clear about the security properties of the HSxxx family of algs.
https://datatracker.ietf.org/doc/html/rfc7518#section-3.2
If a lib issues a token with HS256 but the key happens to be shorter, this isn't technically HS256, it's something else.