Skip to content

fix(hmac): don't include the HMAC key in the invalid key exception - #2100

Open
ratomirjovanovic wants to merge 1 commit into
Adyen:mainfrom
ratomirjovanovic:fix/hmac-key-in-exception-message
Open

ratomirjovanovic wants to merge 1 commit into
Adyen:mainfrom
ratomirjovanovic:fix/hmac-key-in-exception-message

Conversation

@ratomirjovanovic

Copy link
Copy Markdown

HMACValidator.calculateHMAC throws Invalid Hex HMAC key: <key> when the key isn't valid hex. A key usually fails that check because of quotes or a stray character around the real key, so the message carries the secret into logs and error trackers.

This replaces it with Invalid Hex HMAC key: it must be a hexadecimal string with an even number of characters. The prefix stays the same.

Tests: updated testCalculateHMACInvalidKeyFormat for the new message and added testCalculateHMACInvalidKeyIsNotInMessage (a quoted key, checks the message doesn't contain it). Ran mvn clean test on JDK 21 (661 tests pass) and spotless:check, which is clean for the changed files.

Same change for PHP in Adyen/adyen-php-api-library#976.

calculateHMAC put the rejected key into the IllegalArgumentException
message. A key usually fails hex decoding because of quotes or a stray
character around the real key, so the message carried the secret into
logs. Describe the expected format instead.
@ratomirjovanovic
ratomirjovanovic requested a review from a team as a code owner October 29, 2026 13:12

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves security by ensuring that the HMAC key is not leaked in exception messages when a DecoderException occurs during HMAC calculation. The exception message now uses a generic error description instead of appending the invalid key. Corresponding unit tests have been updated and added to verify this behavior. I have no further feedback to provide as the changes are correct and well-tested.

This branch has not been deployed

No deployments
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.

1 participant