Skip to content

Commit

Permalink
fix(webauthn): SessionData empty values through json
Browse files Browse the repository at this point in the history
Using the candidate json/v2 encoder
https://github.com/go-json-experiment/json SessionData doesn't
roundtrip properly through json as an empty []byte is encoded as "".
Mark compatible fields as omitempty, and use len(field) == 0 instead of
nil checks to be more resilient.
  • Loading branch information
seankhliao committed Nov 9, 2024
1 parent 865f160 commit 7fbd1ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions webauthn/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ func (webauthn *WebAuthn) ValidateDiscoverableLogin(handler DiscoverableUserHand

// ValidatePasskeyLogin is an overloaded version of ValidateLogin that allows for passkey credentials.
func (webauthn *WebAuthn) ValidatePasskeyLogin(handler DiscoverableUserHandler, session SessionData, parsedResponse *protocol.ParsedCredentialAssertionData) (user User, credential *Credential, err error) {
if session.UserID != nil {
if len(session.UserID) != 0 {
return nil, nil, protocol.ErrBadRequest.WithDetails("Session was not initiated as a client-side discoverable login")
}

if parsedResponse.Response.UserHandle == nil {
if len(parsedResponse.Response.UserHandle) == 0 {
return nil, nil, protocol.ErrBadRequest.WithDetails("Client-side Discoverable Assertion was attempted with a blank User Handle")
}

Expand Down
6 changes: 3 additions & 3 deletions webauthn/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ type User interface {
// SessionData is the data that should be stored by the Relying Party for the duration of the web authentication
// ceremony.
type SessionData struct {
Challenge string `json:"challenge"`
RelyingPartyID string `json:"rpId"`
UserID []byte `json:"user_id"`
Challenge string `json:"challenge,omitempty"`
RelyingPartyID string `json:"rpId,omitempty"`
UserID []byte `json:"user_id,omitempty"`
AllowedCredentialIDs [][]byte `json:"allowed_credentials,omitempty"`
Expires time.Time `json:"expires"`

Expand Down

0 comments on commit 7fbd1ee

Please sign in to comment.