Skip to content

Commit 726a9b1

Browse files
committed
Version 2.1.0
1 parent b64282e commit 726a9b1

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

includes/class-paystack-deprecated.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,19 @@ public function verify_paystack_transaction() {
386386
*/
387387
public function process_webhooks() {
388388

389-
if ( ( strtoupper( $_SERVER['REQUEST_METHOD'] ) != 'POST' ) || ! array_key_exists( 'HTTP_X_PAYSTACK_SIGNATURE', $_SERVER ) ) {
389+
if ( ( strtoupper( $_SERVER['REQUEST_METHOD'] ) != 'POST' ) || ! array_key_exists('HTTP_X_PAYSTACK_SIGNATURE', $_SERVER) ) {
390390
exit;
391391
}
392392

393-
http_response_code(200);
394-
395393
$json = file_get_contents( "php://input" );
396394

395+
// validate event do all at once to avoid timing attack
396+
if( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $json, $this->secret_key ) ) {
397+
exit;
398+
}
399+
400+
http_response_code(200);
401+
397402
$event = json_decode( $json );
398403

399404
if( 'charge.success' == $event->event ) {

includes/class-paystack.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,15 @@ public function process_webhooks() {
560560
exit;
561561
}
562562

563-
http_response_code(200);
564-
565563
$json = file_get_contents( "php://input" );
566564

565+
// validate event do all at once to avoid timing attack
566+
if( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $json, $this->secret_key ) ) {
567+
exit;
568+
}
569+
570+
http_response_code(200);
571+
567572
$event = json_decode( $json );
568573

569574
if( 'charge.success' == $event->event ) {

0 commit comments

Comments
 (0)