Skip to content

Commit

Permalink
add size check of user-supplied challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
connerdouglass committed Aug 11, 2023
1 parent 013a3d7 commit f710048
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions authenticate_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (w *webauthn) VerifyAuthentication(ctx context.Context, user User, res *Aut
if err != nil {
return nil, errutil.Wrapf(err, "decoding challenge")
}
if len(challengeBytesSlice) != spec.ChallengeSize {
return nil, errutil.Wrap(ErrInvalidChallenge)
}
challengeBytes := Challenge(challengeBytesSlice)
ok, err := w.options.Challenges.HasChallenge(ctx, user, challengeBytes)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var (
ErrCredentialNotFound = errors.New("credential not found")
ErrNoCredentials = errors.New("user has no credential")
ErrUnrecognizedChallenge = errors.New("unrecognized challenge")
ErrInvalidChallenge = errors.New("invalid challenge size")
)
3 changes: 3 additions & 0 deletions register_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (w *webauthn) VerifyRegistration(ctx context.Context, user User, res *Regis
if err != nil {
return nil, errutil.Wrapf(err, "decoding challenge")
}
if len(challengeBytesSlice) != spec.ChallengeSize {
return nil, errutil.Wrap(ErrInvalidChallenge)
}
challengeBytes := Challenge(challengeBytesSlice)
ok, err := w.options.Challenges.HasChallenge(ctx, user, challengeBytes)
if err != nil {
Expand Down

0 comments on commit f710048

Please sign in to comment.