Repository navigation
fix(hmac): don't include the HMAC key in exception messages - #976
Merged
ashwaniarya-adyen merged 2 commits intoNov 17, 2026
Merged
ashwaniarya-adyen merged 2 commits into
ashwaniarya-adyen merged 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
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.
ashwaniarya-adyen
self-requested a review
November 12, 2026 10:03
ashwaniarya-adyen
approved these changes
Nov 17, 2026
|
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



HmacSignature and Sha256Signature throw
Invalid HMAC key: $hmacKeywhen 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 deprecatedvalidateHMACprints$hmacKeytoo, 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. TheInvalid HMAC keyprefix stays, so code that matches on it keeps working.Tests: added
testInvalidHmacKeyIsNotInExceptionMessage(quoted key throughvalidateHMACSignature,validateHMAC,calculateHmacSignatureandcalculateNotificationHMAC, checks the message doesn't contain the key) and updated the expected message inSha256SignatureTest.Ran
vendor/bin/phpunit --testsuite=unit(966 tests pass, the two above fail without the change) andvendor/bin/phpcs --exclude=Generic.Files.LineLengthon 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.