Add PepperPasswordEncoder#19269
Open
KoreaNirsa wants to merge 1 commit into
Open
Conversation
Signed-off-by: KoreaNirsa <islandtim@naver.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
PepperPasswordEncoder, aPasswordEncoderdecorator that appends a server-side pepper to the raw password before delegating to anotherPasswordEncoder.The goal is to let applications add a pepper without replacing, subclassing, or manually wrapping their existing password encoder configuration.
Unlike a per-password salt, the pepper is not stored with the encoded password. It must be stored separately from the password database, for example in an environment variable or secret manager.
The delegate remains responsible for:
upgradeEncodingdecisionsFor example:
The delegated input is equivalent to:
This PR also adds unit tests and password storage documentation for
PepperPasswordEncoder.Related #18299.
Design Note
This PR currently appends the pepper to the raw password before delegating:
I also considered an HMAC-SHA256-based approach, where the pepper is used as the HMAC key before delegating to the configured PasswordEncoder. That could avoid delegate input-length limits, such as BCrypt's 72-byte limit.
I kept this implementation as a simple decorator so that the delegate's behavior remains as close as possible to existing PasswordEncoder behavior, with only the pepper added. I am happy to adjust this if the team prefers the HMAC-based design.