Skip to content

Commit 8507625

Browse files
authored
Restore eraseCredentials() for Symfony 7.3 compatibility and manually clear plainPassword after hashing
- Re-adds the eraseCredentials() method to the User entity, which is still required by the UserInterface in Symfony 7.3. Although deprecated since Symfony 7.1, it must remain until Symfony 8.0 for compatibility. - Adds a manual clearing of the plainPassword field in the password processor after hashing. Since eraseCredentials() is no longer called automatically, sensitive data must now be cleared explicitly to avoid leaving passwords in memory or logs.
1 parent 4f9136c commit 8507625

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

symfony/user.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
139139
{
140140
return (string) $this->email;
141141
}
142+
143+
/**
144+
* @see UserInterface
145+
*
146+
* Required until Symfony 8.0, where eraseCredentials() will be removed from the interface.
147+
* No-op since plainPassword is cleared manually in the password processor.
148+
*/
149+
public function eraseCredentials(): void
150+
{
151+
// Intentionally left blank
152+
}
142153
}
143154
```
144155

@@ -251,6 +262,9 @@ final readonly class UserPasswordHasher implements ProcessorInterface
251262
);
252263
$data->setPassword($hashedPassword);
253264

265+
// To avoid leaving sensitive data like the plain password in memory or logs, we manually clear it after hashing.
266+
$data->setPlainPassword(null);
267+
254268
return $this->processor->process($data, $operation, $uriVariables, $context);
255269
}
256270
}

0 commit comments

Comments
 (0)