Skip to content

Commit aeedfa6

Browse files
committed
Add lock to avoid infinite loops when querying
1 parent fc8ba60 commit aeedfa6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

inc/authentication/namespace.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ function get_token_from_request() {
8181
* @return \WP_User|int|\WP_Error
8282
*/
8383
function attempt_authentication( $user = null ) {
84-
if ( ! empty( $user ) ) {
84+
// Lock against infinite loops when querying the token itself.
85+
static $is_querying_token = false;
86+
87+
if ( ! empty( $user ) || $is_querying_token ) {
8588
return $user;
8689
}
8790

@@ -93,7 +96,10 @@ function attempt_authentication( $user = null ) {
9396
}
9497

9598
// Attempt to find the token.
99+
$is_querying_token = true;
96100
$token = Tokens\get_by_id( $token_value );
101+
$is_querying_token = false;
102+
97103
if ( empty( $token ) ) {
98104
return create_invalid_token_error( $token );
99105
}

0 commit comments

Comments
 (0)