Skip to content

Restore eraseCredentials() for Symfony 7.3 compatibility (until Symfony 8.0) and clear plainPassword manually #2186

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

Merged
merged 1 commit into from
Aug 20, 2025

Conversation

kdefarge
Copy link
Contributor

This PR updates the user authentication example to ensure compatibility with Symfony 7.3 and apply current security best practices:

  • Restores the eraseCredentials() method in the User entity:
    Although deprecated since Symfony 7.1, the method is still required by the UserInterface in Symfony 7.3.
    It will be removed in Symfony 8.0, but must remain for now to avoid runtime errors.

  • Manually clears the plainPassword field in the processor after hashing:
    Since eraseCredentials() is no longer called automatically, it's now the developer’s responsibility to ensure sensitive data is cleared.
    This avoids leaving passwords in memory or exposing them via logs, exceptions, or debug tools.

These changes make the example code functional and secure across current Symfony versions.

… 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.
@soyuka soyuka merged commit 8aa8def into api-platform:4.1 Aug 20, 2025
1 check passed
@soyuka
Copy link
Member

soyuka commented Aug 20, 2025

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants