@@ -76,8 +76,17 @@ func WebAuthnPasskeyLogin(ctx *context.Context) {
76
76
}()
77
77
78
78
// Validate the parsed response.
79
+
80
+ // ParseCredentialRequestResponse+ValidateDiscoverableLogin equals to FinishDiscoverableLogin, but we need to ParseCredentialRequestResponse first to get flags
79
81
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 ) {
81
90
userID , n := binary .Varint (userHandle )
82
91
if n <= 0 {
83
92
return nil , errors .New ("invalid rawID" )
@@ -89,8 +98,8 @@ func WebAuthnPasskeyLogin(ctx *context.Context) {
89
98
return nil , err
90
99
}
91
100
92
- return ( * wa .User )( user ), nil
93
- }, * sessionData , ctx . Req )
101
+ return wa .NewWebAuthnUser ( ctx , user , parsedResponse . Response . AuthenticatorData . Flags ), nil
102
+ }, * sessionData , parsedResponse )
94
103
if err != nil {
95
104
// Failed authentication attempt.
96
105
log .Info ("Failed authentication attempt for passkey from %s: %v" , ctx .RemoteAddr (), err )
@@ -171,7 +180,8 @@ func WebAuthnLoginAssertion(ctx *context.Context) {
171
180
return
172
181
}
173
182
174
- assertion , sessionData , err := wa .WebAuthn .BeginLogin ((* wa .User )(user ))
183
+ webAuthnUser := wa .NewWebAuthnUser (ctx , user )
184
+ assertion , sessionData , err := wa .WebAuthn .BeginLogin (webAuthnUser )
175
185
if err != nil {
176
186
ctx .ServerError ("webauthn.BeginLogin" , err )
177
187
return
@@ -216,7 +226,8 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
216
226
}
217
227
218
228
// 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 )
220
231
if err != nil {
221
232
// Failed authentication attempt.
222
233
log .Info ("Failed authentication attempt for %s from %s: %v" , user .Name , ctx .RemoteAddr (), err )
0 commit comments