Skip to content

fix(webauthn): login validates attestation format #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions protocol/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,28 @@ func (a *AttestationObject) VerifyAttestation(clientDataHash []byte, mds metadat
return nil
}

formatHandler, valid := attestationRegistry[AttestationFormat(a.Format)]
if !valid {
var (
handler attestationFormatValidationHandler
valid bool
)

if handler, valid = attestationRegistry[AttestationFormat(a.Format)]; !valid {
return ErrAttestationFormat.WithInfo(fmt.Sprintf("Attestation format %s is unsupported", a.Format))
}

var (
aaguid uuid.UUID
attestationType string
x5cs []any
)

// Step 14. Verify that attStmt is a correct attestation statement, conveying a valid attestation signature, by using
// the attestation statement format fmt’s verification procedure given attStmt, authData and the hash of the serialized
// client data computed in step 7.
attestationType, x5cs, err := formatHandler(*a, clientDataHash, mds)
if err != nil {
if attestationType, x5cs, err = handler(*a, clientDataHash, mds); err != nil {
return err.(*Error).WithInfo(attestationType)
}

var (
aaguid uuid.UUID
)

if len(a.AuthData.AttData.AAGUID) != 0 {
if aaguid, err = uuid.FromBytes(a.AuthData.AttData.AAGUID); err != nil {
return ErrInvalidAttestation.WithInfo("Error occurred parsing AAGUID during attestation validation").WithDetails(err.Error()).WithError(err)
Expand Down
2 changes: 1 addition & 1 deletion protocol/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ValidateMetadata(ctx context.Context, mds metadata.Provider, aaguid uuid.UU
return nil
}

if mds.GetValidateAttestationTypes(ctx) {
if mds.GetValidateAttestationTypes(ctx) && attestationType != "" {
found := false

for _, atype := range entry.MetadataStatement.AttestationTypes {
Expand Down
2 changes: 1 addition & 1 deletion webauthn/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (webauthn *WebAuthn) validateLogin(user User, session SessionData, parsedRe

var protoErr *protocol.Error

if protoErr = protocol.ValidateMetadata(context.Background(), webauthn.Config.MDS, aaguid, credential.AttestationType, nil); protoErr != nil {
if protoErr = protocol.ValidateMetadata(context.Background(), webauthn.Config.MDS, aaguid, "", nil); protoErr != nil {
return nil, protocol.ErrBadRequest.WithDetails("Failed to validate credential record metadata").WithInfo(protoErr.DevInfo).WithError(protoErr)
}
}
Expand Down
Loading