Skip failed public key parse for HMAC string secrets - #1047
Hashim1999164 wants to merge 2 commits into
Conversation
verify() always called createPublicKey first. For a normal HMAC string secret that throws, which dominated verify time. Try createSecretKey first for strings that are not PEM, SSH, or JWK, and keep PEM public keys on the public-key path so HS256 cannot treat them as HMAC secrets.
|
Thanks for the fix. One gap: looksLikeAsymmetricKey() only matches -----BEGIN at the start of the string, but OpenSSL skips any text before a PEM header. So a PEM public key preceded by, for example, a comment line now takes the secret-first path, and an HS256 token HMACed with the key text is accepted when algorithms is not set. 9.0.3 rejects the same token with "invalid algorithm". Minimal Repro: Searching for the header anywhere in the string closes it:
|
|
pem with text before the header was still taking the hmac path. begin is matched anywhere in the key now, and that case is in the tests. |
By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct.
Description
verify() currently tries createPublicKey first for every non KeyObject secret. For a normal HMAC string secret that call always throws, and that throw dominates verify time.
String secrets that do not look like PEM, SSH, or JWK now go through createSecretKey first. PEM public keys still go through createPublicKey first, so an HS256 token cannot treat an RSA public key as an HMAC secret.
References
Fixes #1046
Testing