You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whilst investigating Spring Boot startup time regressions it became apparent that BCrypt.encode is a hot method.
Actual Behavior
DaoAuthenticationProvider currently generates an encoded password in doAfterPropertiesSet. This encoded password is decoded when a UsernameNotFoundException is throw in order to prevent timing attacks (a user that isn't found takes about the same time to process as one that is).
Expected Behavior
It would be nice to remove the encode call from the application startup critical-path so that application startup times are not increased. One possible option might be to make userNotFoundEncodedPassword late binding and to calculate it on the first call to retrieveUser.
I believe (although I'm by no means an expert here) that this should allow faster startup without being susceptible to timing attacks. The first call to retrieveUser would be a little slower, but this will be constant regardless of if a user is ultimately found or not. Subsequent call will have the same behavior as the current implementation.
Configuration
Spring Boot 2.0.M7 running spring-boot-sample-actuator-ui.
Update `DaoAuthenticationProvider` so that `userNotFoundEncodedPassword`
is lazily initialized on the first call to `retrieveUser`, rather than
in `doAfterPropertiesSet`.
Since some `PasswordEncoder` implementations can be slow, this change
can help to improve application startup times and the expense of some
delay with the first login.
Note that `userNotFoundEncodedPassword` creation occurs on the first
user retrieval, regardless of whether the user is ultimately found. This
ensures consistent processing times, regardless of the outcome.
First Call:
Found = encode(userNotFound) + decode(supplied)
Not-Found = encode(userNotFound) + decode(userNotFound)
Subsequent Call:
Found = decode(supplied)
Not-Found = decode(userNotFound)
Fixesspring-projectsgh-4915
Summary
Whilst investigating Spring Boot startup time regressions it became apparent that
BCrypt.encode
is a hot method.Actual Behavior
DaoAuthenticationProvider
currently generates an encoded password indoAfterPropertiesSet
. This encoded password is decoded when aUsernameNotFoundException
is throw in order to prevent timing attacks (a user that isn't found takes about the same time to process as one that is).Expected Behavior
It would be nice to remove the
encode
call from the application startup critical-path so that application startup times are not increased. One possible option might be to makeuserNotFoundEncodedPassword
late binding and to calculate it on the first call toretrieveUser
.I believe (although I'm by no means an expert here) that this should allow faster startup without being susceptible to timing attacks. The first call to
retrieveUser
would be a little slower, but this will be constant regardless of if a user is ultimately found or not. Subsequent call will have the same behavior as the current implementation.Configuration
Spring Boot 2.0.M7 running
spring-boot-sample-actuator-ui
.Version
5.0.0.RELEASE
Sample
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-actuator-ui
The text was updated successfully, but these errors were encountered: