Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36389dc

Browse files
committed
Hide plain password from stack trace with SensitiveParameter annotation
1 parent 7a21a57 commit 36389dc

12 files changed

+30
-22
lines changed

src/Symfony/Component/PasswordHasher/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
CHANGELOG
2+
=========
3+
4+
6.2
5+
---
6+
7+
* Hide sensitive information from stack traces with `SensitiveParameter` attribute
8+
19
5.3
210
---
311

src/Symfony/Component/PasswordHasher/Hasher/CheckPasswordLengthTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
trait CheckPasswordLengthTrait
2020
{
21-
private function isPasswordTooLong(string $password): bool
21+
private function isPasswordTooLong(#[\SensitiveParameter] string $password): bool
2222
{
2323
return PasswordHasherInterface::MAX_PASSWORD_LENGTH < \strlen($password);
2424
}

src/Symfony/Component/PasswordHasher/Hasher/MessageDigestPasswordHasher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase
4848
$this->iterations = $iterations;
4949
}
5050

51-
public function hash(string $plainPassword, string $salt = null): string
51+
public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string
5252
{
5353
if ($this->isPasswordTooLong($plainPassword)) {
5454
throw new InvalidPasswordException();
@@ -69,7 +69,7 @@ public function hash(string $plainPassword, string $salt = null): string
6969
return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
7070
}
7171

72-
public function verify(string $hashedPassword, string $plainPassword, string $salt = null): bool
72+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool
7373
{
7474
if (\strlen($hashedPassword) !== $this->hashLength || str_contains($hashedPassword, '$')) {
7575
return false;
@@ -83,7 +83,7 @@ public function needsRehash(string $hashedPassword): bool
8383
return false;
8484
}
8585

86-
private function mergePasswordAndSalt(string $password, ?string $salt): string
86+
private function mergePasswordAndSalt(#[\SensitiveParameter] string $password, ?string $salt): string
8787
{
8888
if (!$salt) {
8989
return $password;

src/Symfony/Component/PasswordHasher/Hasher/MigratingPasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function __construct(PasswordHasherInterface $bestHasher, PasswordHasherI
3333
$this->extraHashers = $extraHashers;
3434
}
3535

36-
public function hash(string $plainPassword, string $salt = null): string
36+
public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string
3737
{
3838
return $this->bestHasher->hash($plainPassword, $salt);
3939
}
4040

41-
public function verify(string $hashedPassword, string $plainPassword, string $salt = null): bool
41+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool
4242
{
4343
if ($this->bestHasher->verify($hashedPassword, $plainPassword, $salt)) {
4444
return true;

src/Symfony/Component/PasswordHasher/Hasher/NativePasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(int $opsLimit = null, int $memLimit = null, int $cos
7171
];
7272
}
7373

74-
public function hash(string $plainPassword): string
74+
public function hash(#[\SensitiveParameter] string $plainPassword): string
7575
{
7676
if ($this->isPasswordTooLong($plainPassword)) {
7777
throw new InvalidPasswordException();
@@ -84,7 +84,7 @@ public function hash(string $plainPassword): string
8484
return password_hash($plainPassword, $this->algorithm, $this->options);
8585
}
8686

87-
public function verify(string $hashedPassword, string $plainPassword): bool
87+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword): bool
8888
{
8989
if ('' === $plainPassword || $this->isPasswordTooLong($plainPassword)) {
9090
return false;

src/Symfony/Component/PasswordHasher/Hasher/Pbkdf2PasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase
5959
$this->iterations = $iterations;
6060
}
6161

62-
public function hash(string $plainPassword, string $salt = null): string
62+
public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string
6363
{
6464
if ($this->isPasswordTooLong($plainPassword)) {
6565
throw new InvalidPasswordException();
@@ -74,7 +74,7 @@ public function hash(string $plainPassword, string $salt = null): string
7474
return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
7575
}
7676

77-
public function verify(string $hashedPassword, string $plainPassword, string $salt = null): bool
77+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool
7878
{
7979
if (\strlen($hashedPassword) !== $this->encodedLength || str_contains($hashedPassword, '$')) {
8080
return false;

src/Symfony/Component/PasswordHasher/Hasher/PlaintextPasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(bool $ignorePasswordCase = false)
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function hash(string $plainPassword, string $salt = null): string
41+
public function hash(#[\SensitiveParameter] string $plainPassword, string $salt = null): string
4242
{
4343
if ($this->isPasswordTooLong($plainPassword)) {
4444
throw new InvalidPasswordException();
@@ -47,7 +47,7 @@ public function hash(string $plainPassword, string $salt = null): string
4747
return $this->mergePasswordAndSalt($plainPassword, $salt);
4848
}
4949

50-
public function verify(string $hashedPassword, string $plainPassword, string $salt = null): bool
50+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword, string $salt = null): bool
5151
{
5252
if ($this->isPasswordTooLong($plainPassword)) {
5353
return false;

src/Symfony/Component/PasswordHasher/Hasher/SodiumPasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function isSupported(): bool
5252
return version_compare(\extension_loaded('sodium') ? \SODIUM_LIBRARY_VERSION : phpversion('libsodium'), '1.0.14', '>=');
5353
}
5454

55-
public function hash(string $plainPassword): string
55+
public function hash(#[\SensitiveParameter] string $plainPassword): string
5656
{
5757
if ($this->isPasswordTooLong($plainPassword)) {
5858
throw new InvalidPasswordException();
@@ -69,7 +69,7 @@ public function hash(string $plainPassword): string
6969
throw new LogicException('Libsodium is not available. You should either install the sodium extension or use a different password hasher.');
7070
}
7171

72-
public function verify(string $hashedPassword, string $plainPassword): bool
72+
public function verify(string $hashedPassword, #[\SensitiveParameter] string $plainPassword): bool
7373
{
7474
if ('' === $plainPassword) {
7575
return false;

src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(PasswordHasherFactoryInterface $hasherFactory)
3030
$this->hasherFactory = $hasherFactory;
3131
}
3232

33-
public function hashPassword(PasswordAuthenticatedUserInterface $user, string $plainPassword): string
33+
public function hashPassword(PasswordAuthenticatedUserInterface $user, #[\SensitiveParameter] string $plainPassword): string
3434
{
3535
$salt = null;
3636
if ($user instanceof LegacyPasswordAuthenticatedUserInterface) {
@@ -42,7 +42,7 @@ public function hashPassword(PasswordAuthenticatedUserInterface $user, string $p
4242
return $hasher->hash($plainPassword, $salt);
4343
}
4444

45-
public function isPasswordValid(PasswordAuthenticatedUserInterface $user, string $plainPassword): bool
45+
public function isPasswordValid(PasswordAuthenticatedUserInterface $user, #[\SensitiveParameter] string $plainPassword): bool
4646
{
4747
$salt = null;
4848
if ($user instanceof LegacyPasswordAuthenticatedUserInterface) {

src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasherInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ interface UserPasswordHasherInterface
2323
/**
2424
* Hashes the plain password for the given user.
2525
*/
26-
public function hashPassword(PasswordAuthenticatedUserInterface $user, string $plainPassword): string;
26+
public function hashPassword(PasswordAuthenticatedUserInterface $user, #[\SensitiveParameter] string $plainPassword): string;
2727

2828
/**
2929
* Checks if the plaintext password matches the user's password.
3030
*/
31-
public function isPasswordValid(PasswordAuthenticatedUserInterface $user, string $plainPassword): bool;
31+
public function isPasswordValid(PasswordAuthenticatedUserInterface $user, #[\SensitiveParameter] string $plainPassword): bool;
3232

3333
/**
3434
* Checks if an encoded password would benefit from rehashing.

0 commit comments

Comments
 (0)