File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
client_handler/auth_methods Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -743,6 +743,7 @@ defmodule Supavisor.ClientHandler do
743743 ## Internal functions
744744 defp handle_auth_success ( sock , final_secrets , data ) do
745745 Logger . info ( "ClientHandler: Connection authenticated" )
746+ cache_validated_password ( data , final_secrets )
746747
747748 if data . mode != :proxy do
748749 Supavisor.UpstreamAuthentication . put_upstream_auth_secrets ( data . id , final_secrets )
@@ -766,6 +767,19 @@ defmodule Supavisor.ClientHandler do
766767 }
767768 end
768769
770+ defp cache_validated_password ( % { tenant: tenant } , % Supavisor.Secrets.PasswordSecrets { } = secrets ) do
771+ case Supavisor.ClientAuthentication . get_validation_secrets ( tenant , secrets . user ) do
772+ { :ok , % { password_secrets: nil } = validation } ->
773+ updated = % { validation | password_secrets: secrets }
774+ Supavisor.ClientAuthentication . put_validation_secrets ( tenant , secrets . user , updated )
775+
776+ _ ->
777+ :ok
778+ end
779+ end
780+
781+ defp cache_validated_password ( _data , _secrets ) , do: :ok
782+
769783 defp handle_auth_failure ( exception , data ) do
770784 AuthMethods . handle_auth_failure ( data . auth_context , exception )
771785 Supavisor.CircuitBreaker . record_failure ( { data . tenant , data . peer_ip } , :auth_error )
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ defmodule Supavisor.ClientHandler.AuthMethods.Password do
8383 defp validate_password ( password , ctx ) do
8484 with { :ok , % { password_secrets: password_secrets , sasl_secrets: sasl_secrets } } <-
8585 ClientAuthentication . fetch_validation_secrets ( ctx . id , ctx . tenant , ctx . user ) do
86- if password_secrets && password == password_secrets . password do
86+ if password_secrets && Plug.Crypto . secure_compare ( password , password_secrets . password ) do
8787 :ok
8888 else
8989 salted_password =
You can’t perform that action at this time.
0 commit comments