Skip to content

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

Merged
ashwaniarya-adyen merged 2 commits into
Adyen:mainfrom
ratomirjovanovic:fix/hmac-key-in-exception-message
Nov 17, 2026
Merged

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

Conversation

@ratomirjovanovic

Copy link
Copy Markdown
Contributor

HmacSignature and Sha256Signature throw Invalid HMAC key: $hmacKey when the key isn't hex. The usual reason a key fails that check is a config mistake like quotes or a stray character around the real key, so the message ends up carrying the secret into logs and error trackers. The deprecated validateHMAC prints $hmacKey too, which there is actually the signature argument because of the swapped parameter names.

This changes the five messages to Invalid HMAC key: it must be a hexadecimal string. The Invalid HMAC key prefix stays, so code that matches on it keeps working.

Tests: added testInvalidHmacKeyIsNotInExceptionMessage (quoted key through validateHMACSignature, validateHMAC, calculateHmacSignature and calculateNotificationHMAC, checks the message doesn't contain the key) and updated the expected message in Sha256SignatureTest.

Ran vendor/bin/phpunit --testsuite=unit (966 tests pass, the two above fail without the change) and vendor/bin/phpcs --exclude=Generic.Files.LineLength on the changed files, PHP 8.4.

For reference, the new key check in Adyen/adyen-node-api-library#1817 also leaves the key out of its message.

The Invalid HMAC key exceptions in HmacSignature and Sha256Signature
included the rejected key. A key usually fails the hex check because of
quotes or a stray character around the real key, so the message carried
the secret into logs. Keep the Invalid HMAC key prefix and drop the key.
@ratomirjovanovic
ratomirjovanovic requested a review from a team as a code owner October 29, 2026 12:48

@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 updates the HmacSignature and Sha256Signature utilities to prevent the invalid HMAC key from being included in exception messages, thereby avoiding the risk of logging sensitive or malformed keys. The exception messages now generically state that the key must be a hexadecimal string. Unit tests have been added and updated to verify this behavior. I have no feedback to provide.

@sonarqubecloud

Copy link
Copy Markdown

@ashwaniarya-adyen
ashwaniarya-adyen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into Adyen:main with commit 5bde839 Nov 17, 2026
7 checks passed
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.

2 participants