-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Don't invalidate the user when the password was not stored in the session #59539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… in the session
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Tests\Authentication\Token\Fixtures; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
final class CustomUser implements UserInterface | ||
{ | ||
/** @var string */ | ||
private $username; | ||
/** @var array */ | ||
private $roles; | ||
|
||
public function __construct(string $username, array $roles) | ||
{ | ||
$this->username = $username; | ||
$this->roles = $roles; | ||
public function __construct( | ||
private string $username, | ||
private array $roles, | ||
) { | ||
} | ||
|
||
public function getUserIdentifier(): string | ||
|
@@ -27,16 +31,6 @@ public function getRoles(): array | |
return $this->roles; | ||
} | ||
|
||
public function getPassword(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getSalt(): ?string | ||
{ | ||
return null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legacy stuff |
||
|
||
public function eraseCredentials(): void | ||
{ | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,7 @@ public function onKernelResponse(ResponseEvent $event): void | |
* | ||
* @throws \RuntimeException | ||
*/ | ||
protected function refreshUser(TokenInterface $token): ?TokenInterface | ||
private function refreshUser(TokenInterface $token): ?TokenInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the class is |
||
{ | ||
$user = $token->getUser(); | ||
|
||
|
@@ -292,7 +292,10 @@ private static function hasUserChanged(UserInterface $originalUser, TokenInterfa | |
} | ||
|
||
if ($originalUser instanceof PasswordAuthenticatedUserInterface || $refreshedUser instanceof PasswordAuthenticatedUserInterface) { | ||
if (!$originalUser instanceof PasswordAuthenticatedUserInterface || !$refreshedUser instanceof PasswordAuthenticatedUserInterface || $originalUser->getPassword() !== $refreshedUser->getPassword()) { | ||
if (!$originalUser instanceof PasswordAuthenticatedUserInterface | ||
|| !$refreshedUser instanceof PasswordAuthenticatedUserInterface | ||
|| $refreshedUser->getPassword() !== ($originalUser->getPassword() ?? $refreshedUser->getPassword()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the meat of this PR: ignore null passwords from the session storage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this also mean that you lose the ability to detect that the user changed the password? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely. See the main thread of this PR for some thoughts on the topic. |
||
) { | ||
return true; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,7 @@ public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess() | |
->willReturn([['foo' => 'bar'], null]) | ||
; | ||
|
||
$token = new class extends AbstractToken { | ||
public function getCredentials(): mixed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legacy stuff also |
||
{ | ||
} | ||
}; | ||
$token = new class extends AbstractToken {}; | ||
|
||
$tokenStorage = $this->createMock(TokenStorageInterface::class); | ||
$tokenStorage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Http\Tests\Fixtures; | ||
|
||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
final class CustomUser implements UserInterface, PasswordAuthenticatedUserInterface | ||
{ | ||
public function __construct( | ||
private string $username, | ||
private array $roles, | ||
private ?string $password = null, | ||
) { | ||
} | ||
|
||
public function getUserIdentifier(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function getRoles(): array | ||
{ | ||
return $this->roles; | ||
} | ||
|
||
public function getPassword(): ?string | ||
{ | ||
return $this->password ?? null; | ||
} | ||
|
||
public function eraseCredentials(): void | ||
{ | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return [\sprintf("\0%s\0username", self::class) => $this->username]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CPP FTW