Skip to content

Commit

Permalink
Merge pull request #107 from Saeven/feature/strpos-defense
Browse files Browse the repository at this point in the history
Patches an in-the-wild attack vector that doesn't yield a vulnerabili…
  • Loading branch information
Saeven authored Mar 9, 2023
2 parents 87255d8 + f7f7145 commit 0793a9d
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 0793a9d

Please sign in to comment.