@@ -76,8 +76,17 @@ func WebAuthnPasskeyLogin(ctx *context.Context) {
7676 }()
7777
7878 // Validate the parsed response.
79+
80+ // ParseCredentialRequestResponse+ValidateDiscoverableLogin equals to FinishDiscoverableLogin, but we need to ParseCredentialRequestResponse first to get flags
7981 var user * user_model.User
80- cred , err := wa .WebAuthn .FinishDiscoverableLogin (func (rawID , userHandle []byte ) (webauthn.User , error ) {
82+ parsedResponse , err := protocol .ParseCredentialRequestResponse (ctx .Req )
83+ if err != nil {
84+ // Failed authentication attempt.
85+ log .Info ("Failed authentication attempt for %s from %s: %v" , user .Name , ctx .RemoteAddr (), err )
86+ ctx .Status (http .StatusForbidden )
87+ return
88+ }
89+ cred , err := wa .WebAuthn .ValidateDiscoverableLogin (func (rawID , userHandle []byte ) (webauthn.User , error ) {
8190 userID , n := binary .Varint (userHandle )
8291 if n <= 0 {
8392 return nil , errors .New ("invalid rawID" )
@@ -89,8 +98,8 @@ func WebAuthnPasskeyLogin(ctx *context.Context) {
8998 return nil , err
9099 }
91100
92- return ( * wa .User )( user ), nil
93- }, * sessionData , ctx . Req )
101+ return wa .NewWebAuthnUser ( ctx , user , parsedResponse . Response . AuthenticatorData . Flags ), nil
102+ }, * sessionData , parsedResponse )
94103 if err != nil {
95104 // Failed authentication attempt.
96105 log .Info ("Failed authentication attempt for passkey from %s: %v" , ctx .RemoteAddr (), err )
@@ -171,7 +180,8 @@ func WebAuthnLoginAssertion(ctx *context.Context) {
171180 return
172181 }
173182
174- assertion , sessionData , err := wa .WebAuthn .BeginLogin ((* wa .User )(user ))
183+ webAuthnUser := wa .NewWebAuthnUser (ctx , user )
184+ assertion , sessionData , err := wa .WebAuthn .BeginLogin (webAuthnUser )
175185 if err != nil {
176186 ctx .ServerError ("webauthn.BeginLogin" , err )
177187 return
@@ -216,7 +226,8 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
216226 }
217227
218228 // Validate the parsed response.
219- cred , err := wa .WebAuthn .ValidateLogin ((* wa .User )(user ), * sessionData , parsedResponse )
229+ webAuthnUser := wa .NewWebAuthnUser (ctx , user , parsedResponse .Response .AuthenticatorData .Flags )
230+ cred , err := wa .WebAuthn .ValidateLogin (webAuthnUser , * sessionData , parsedResponse )
220231 if err != nil {
221232 // Failed authentication attempt.
222233 log .Info ("Failed authentication attempt for %s from %s: %v" , user .Name , ctx .RemoteAddr (), err )
0 commit comments