Skip to content

Commit eb3e4cc

Browse files
committed
fix: catch PinRequiredError instead of bare ValueError
The fido2 library raises PinRequiredError when a PIN is needed. Catching ValueError swallowed unrelated errors (bad challenges, malformed credentials) and silently misinterpreted them as PIN prompts.
1 parent 574af8b commit eb3e4cc

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

fido2client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import cbor2 as cbor
1313
import requests
14-
from fido2.client import Fido2Client
14+
from fido2.client import Fido2Client, PinRequiredError
1515
from fido2.hid import CtapHidDevice
1616

1717
from .exceptions import (
@@ -224,7 +224,7 @@ def _complete(
224224
assertions, client_data = fido2_client.get_assertion(
225225
begin_data.rp_id, challenge, allow_list
226226
)
227-
except ValueError:
227+
except PinRequiredError:
228228
assertions, client_data = fido2_client.get_assertion(
229229
begin_data.rp_id,
230230
challenge,

tests/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cbor2
77
import pytest
88
import requests
9+
from fido2.client import PinRequiredError
910

1011
from fido2client import Fido2HttpClient
1112
from fido2client.exceptions import (
@@ -223,7 +224,7 @@ def test_pin_fallback(mock_device):
223224
with patch("fido2client.client.Fido2Client") as MockFido2Client:
224225
instance = MockFido2Client.return_value
225226
instance.get_assertion.side_effect = [
226-
ValueError("PIN required"),
227+
PinRequiredError(),
227228
([assertion], client_data),
228229
]
229230

0 commit comments

Comments
 (0)