Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hash_equals when validating webhook signature #42

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

thinkverse
Copy link
Contributor

The use of !== over hash_equals was bothering me, not sure if the validation needs a timing-safe string comparison but better safe than sorry. It is also the way Lemon Squeezy uses in their example:

$secret    = '[SIGNING_SECRET]'; // from your webhook settings
$payload   = file_get_contents('php://input');
$hash      = hash_hmac('sha256', $payload, $secret);
$signature = $_SERVER['HTTP_X_SIGNATURE'] ?? '';

if (!hash_equals($hash, $signature)) {
    throw new Exception('Invalid signature.');
}

@driesvints
Copy link
Collaborator

Thanks! I think I took the example as it was presented in the docs at the time. They've probably changed since.

@driesvints driesvints merged commit d5a7265 into lmsqueezy:main Aug 14, 2023
@thinkverse thinkverse deleted the use_hash_equals branch August 14, 2023 13:39
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