Skip to content

Commit aefc5a4

Browse files
Rewrite counter check to conform with specification (#58)
The WebAuthn specification mandates that the counter check should be performed if either of the counters are non-zero.
1 parent 2e520ee commit aefc5a4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/WebAuthn.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,20 @@ public function processGet($clientDataJSON, $authenticatorData, $signature, $cre
451451
throw new WebAuthnException('invalid signature', WebAuthnException::INVALID_SIGNATURE);
452452
}
453453

454-
// 17. If the signature counter value authData.signCount is nonzero,
455-
// if less than or equal to the signature counter value stored,
456-
// is a signal that the authenticator may be cloned
457454
$signatureCounter = $authenticatorObj->getSignCount();
458-
if ($signatureCounter > 0) {
455+
if ($signatureCounter !== 0) {
459456
$this->_signatureCounter = $signatureCounter;
460-
if ($prevSignatureCnt !== null && $prevSignatureCnt >= $signatureCounter) {
461-
throw new WebAuthnException('signature counter not valid', WebAuthnException::SIGNATURE_COUNTER);
457+
}
458+
459+
// 17. If either of the signature counter value authData.signCount or
460+
// previous signature count is nonzero, and if authData.signCount
461+
// less than or equal to previous signature count, it's a signal
462+
// that the authenticator may be cloned
463+
if ($prevSignatureCnt !== null) {
464+
if ($signatureCounter !== 0 || $prevSignatureCnt !== 0) {
465+
if ($prevSignatureCnt >= $signatureCounter) {
466+
throw new WebAuthnException('signature counter not valid', WebAuthnException::SIGNATURE_COUNTER);
467+
}
462468
}
463469
}
464470

0 commit comments

Comments
 (0)