Skip to content

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

Merged
ashwaniarya-adyen merged 1 commit into
Adyen:mainfrom
ratomirjovanovic:fix/hmac-key-in-exception-message
Nov 3, 2026
Merged

ashwaniarya-adyen merged 1 commit into
Adyen:mainfrom
ratomirjovanovic:fix/hmac-key-in-exception-message

Conversation

@ratomirjovanovic

Copy link
Copy Markdown
Contributor

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.

@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.

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.
@ashwaniarya-adyen
ashwaniarya-adyen force-pushed the fix/hmac-key-in-exception-message branch from ed45e19 to 06dc5d9 Compare November 2, 2026 13:33
@ashwaniarya-adyen ashwaniarya-adyen self-assigned this Nov 3, 2026
@ashwaniarya-adyen ashwaniarya-adyen added the Fix Indicates a bug fix label Nov 3, 2026
@ashwaniarya-adyen
ashwaniarya-adyen added this pull request to the merge queue Nov 3, 2026
Merged via the queue into Adyen:main with commit 08bed0a Nov 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Indicates a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants