Skip to content

Commit e509e3a

Browse files
committed
fix(passkeys): sign_count should be uint32
1 parent 9868df6 commit e509e3a

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

internal/api/apierrors/errorcode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ const (
118118
ErrorCodeTooManyPasskeys ErrorCode = "too_many_passkeys"
119119

120120
// WebAuthn protocol-level errors (shared between passkeys and MFA WebAuthn)
121-
ErrorCodeWebAuthnCredentialNotFound ErrorCode = "webauthn_credential_not_found"
121+
ErrorCodeWebAuthnCredentialNotFound ErrorCode = "webauthn_credential_not_found" // #nosec G101 -- not a credential
122122
ErrorCodeWebAuthnChallengeNotFound ErrorCode = "webauthn_challenge_not_found"
123123
ErrorCodeWebAuthnChallengeExpired ErrorCode = "webauthn_challenge_expired"
124124
ErrorCodeWebAuthnVerificationFailed ErrorCode = "webauthn_verification_failed"
125-
ErrorCodeWebAuthnCredentialExists ErrorCode = "webauthn_credential_exists"
125+
ErrorCodeWebAuthnCredentialExists ErrorCode = "webauthn_credential_exists" // #nosec G101 -- not a credential
126126
)

internal/api/passkey_virtual_authenticator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (va *virtualAuthenticator) buildAuthData(credentialID []byte, privKey *ecds
103103
// attestedCredentialData: aaguid (16) || credIdLen (2) || credId || coseKey
104104
aaguid := make([]byte, 16) // all zeros
105105
credIDLen := make([]byte, 2)
106-
binary.BigEndian.PutUint16(credIDLen, uint16(len(credentialID)))
106+
binary.BigEndian.PutUint16(credIDLen, uint16(len(credentialID))) //#nosec G115 — we control the length and ensure it's within bounds
107107

108108
var authData []byte
109109
authData = append(authData, rpIDHash[:]...)

internal/models/webauthn_credential.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type WebAuthnCredential struct {
5353
PublicKey []byte `json:"-" db:"public_key"`
5454
AttestationType string `json:"attestation_type" db:"attestation_type"`
5555
AAGUID *uuid.UUID `json:"aaguid,omitempty" db:"aaguid"`
56-
SignCount int64 `json:"sign_count" db:"sign_count"`
56+
SignCount uint32 `json:"sign_count" db:"sign_count"`
5757
Transports WebAuthnTransports `json:"transports" db:"transports"`
5858
BackupEligible bool `json:"backup_eligible" db:"backup_eligible"`
5959
BackedUp bool `json:"backed_up" db:"backed_up"`
@@ -76,7 +76,7 @@ func NewWebAuthnCredential(userID uuid.UUID, cred *webauthn.Credential, friendly
7676
CredentialID: cred.ID,
7777
PublicKey: cred.PublicKey,
7878
AttestationType: cred.AttestationType,
79-
SignCount: int64(cred.Authenticator.SignCount),
79+
SignCount: cred.Authenticator.SignCount,
8080
Transports: WebAuthnTransports(cred.Transport),
8181
BackupEligible: cred.Flags.BackupEligible,
8282
BackedUp: cred.Flags.BackupState,
@@ -105,7 +105,7 @@ func (pc *WebAuthnCredential) ToWebAuthnCredential() webauthn.Credential {
105105
BackupState: pc.BackedUp,
106106
},
107107
Authenticator: webauthn.Authenticator{
108-
SignCount: uint32(pc.SignCount),
108+
SignCount: pc.SignCount,
109109
},
110110
}
111111

@@ -154,7 +154,7 @@ func CountWebAuthnCredentialsByUserID(conn *storage.Connection, userID uuid.UUID
154154
return count, nil
155155
}
156156

157-
func (pc *WebAuthnCredential) UpdateSignCount(tx *storage.Connection, signCount int64) error {
157+
func (pc *WebAuthnCredential) UpdateSignCount(tx *storage.Connection, signCount uint32) error {
158158
pc.SignCount = signCount
159159
return tx.UpdateOnly(pc, "sign_count", "updated_at")
160160
}

internal/models/webauthn_credential_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ func (ts *WebAuthnCredentialTestSuite) TestUpdateSignCount() {
112112
pc := ts.createTestCredential("sign-count-test", false)
113113

114114
require.NoError(ts.T(), pc.UpdateSignCount(ts.db, 42))
115-
require.Equal(ts.T(), int64(42), pc.SignCount)
115+
require.Equal(ts.T(), uint32(42), pc.SignCount)
116116

117117
found, err := FindWebAuthnCredentialByID(ts.db, pc.ID)
118118
require.NoError(ts.T(), err)
119-
require.Equal(ts.T(), int64(42), found.SignCount)
119+
require.Equal(ts.T(), uint32(42), found.SignCount)
120120
}
121121

122122
func (ts *WebAuthnCredentialTestSuite) TestUpdateLastUsedAt() {

0 commit comments

Comments
 (0)