Skip to content

Commit 30a2e9e

Browse files
authored
Fix fatal error on expired fraud prevention token (#5167)
1 parent 6fc5bfe commit 30a2e9e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fix
3+
Comment: This change is adding an extra check for an existing method, which prevents fatal error caused by passing null to a string parameter type
4+
5+

includes/fraud-prevention/class-fraud-prevention-service.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ public function regenerate_token(): string {
117117
* @return bool
118118
*/
119119
public function verify_token( string $token = null ): bool {
120-
return null !== $token && hash_equals( $this->session->get( self::TOKEN_NAME ), $token );
120+
$session_token = $this->session->get( self::TOKEN_NAME );
121+
122+
// Check if the tokens are both strings.
123+
if ( ! is_string( $session_token ) || ! is_string( $token ) ) {
124+
return false;
125+
}
126+
// Compare the hashes to check request validity.
127+
return hash_equals( $session_token, $token );
121128
}
122129
}

0 commit comments

Comments
 (0)