Skip to content

Commit

Permalink
Patches an in-the-wild attack vector that doesn't yield a vulnerabili…
Browse files Browse the repository at this point in the history
…ty, but throws an error.

"strpos() expects parameter 1 to be string, int given"

Somehow, it is possible for $_COOKIE to return an integer type as key.
  • Loading branch information
Saeven committed Mar 9, 2023
1 parent d147c16 commit f7f7145
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Service/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use function hash_equals;
use function hash_hmac;
use function is_numeric;
use function is_scalar;
use function password_hash;
use function password_needs_rehash;
use function password_verify;
Expand Down Expand Up @@ -498,14 +499,15 @@ private function purgeHashCookies(?string $skipCookie = null)
$sp = session_get_cookie_params();
$killTime = time() - 3600;
foreach ($_COOKIE as $cookieName => $value) {
if ($cookieName !== $skipCookie && strpos($cookieName, self::COOKIE_HASH_PREFIX) !== false) {
if ($cookieName !== $skipCookie && is_scalar($cookieName) && strpos((string) $cookieName, self::COOKIE_HASH_PREFIX) !== false) {
setcookie($cookieName, '', $killTime, '/', $sp['domain'], false, true);
}
}
}

/**
* @param User $user Used by some password checkers to provide better checking
*
* @throws WeakPasswordException
*/
private function enforcePasswordStrength(string $password, User $user)
Expand All @@ -521,6 +523,7 @@ private function enforcePasswordStrength(string $password, User $user)
*
* @param User $user The user to whom this password gets assigned
* @param string $newPassword Cleartext password that's being hashed
*
* @throws NoSuchUserException
* @throws WeakPasswordException
*/
Expand All @@ -544,6 +547,7 @@ public function resetPassword(User $user, string $newPassword)
*
* @param User $user The user to validate password for
* @param string $password Cleartext password that'w will be verified
*
* @throws PersistedUserRequiredException
* @throws UserWithoutAuthenticationRecordException
*/
Expand Down

0 comments on commit f7f7145

Please sign in to comment.