Skip to content

Skip failed public key parse for HMAC string secrets - #1047

Open
Hashim1999164 wants to merge 1 commit into
auth0:masterfrom
Hashim1999164:fix/hs256-string-secret-key-parse
Open

Hashim1999164 wants to merge 1 commit into
auth0:masterfrom
Hashim1999164:fix/hs256-string-secret-key-parse

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Sep 18, 2026

Copy link
Copy Markdown

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

  • mocha (513 passing, 1 pending)
  • eslint on verify.js and the new tests
  • HS256 string secret verify still works
  • PEM public key plus HS256 token still fails with must be a symmetric key

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.
@Hashim1999164
Hashim1999164 requested a review from a team as a code owner September 18, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

verify() resolves a string secret by attempting createPublicKey() first, costing 4x-52x on the HS* path

1 participant