-
Notifications
You must be signed in to change notification settings - Fork 121
Description
iOS NFC Double Engagement Bug: Race Condition Causes Failed Verifications
Problem Description
iOS applications using multipaz for NFC-based mDL verification experience a race condition where a second NFC engagement occurs during BLE data exchange, causing verification to fail. The wallet receives two separate engagements with different ephemeral keys, leading to connection failure.
Root Cause
In NfcTagReader.ios.kt, there's a timing window between successful NFC engagement completion and NFC session invalidation. During this window (approximately 2-3 seconds), a second NFC tag detection can trigger another complete handover sequence before the session is properly closed.
Evidence from Logs
To replicate the error we used an Android wallet and the problem appears everytime we attempt an nfc verification. With QR + BLE verification the problem doesn't appear. These logs are a summary of the log we see from the bluetooth components on the device.
2026-01-08 17:24:16.468 - First engagement: DeviceEngagement with key "79e2a7795d..."
2026-01-08 17:24:17.592 - BLE connection established
2026-01-08 17:24:19.449 - DeviceRequest received over BLE
2026-01-08 17:24:19.456 - SECOND engagement: NEW DeviceEngagement with key "7575240b..." (different!)
2026-01-08 17:24:19.492 - Second SELECT APPLICATION APDU sent
Impact
- Verification fails after successful NFC engagement and BLE connection
- Wallet receives duplicate/conflicting engagement data
- Poor user experience with intermittent failures
- Particularly problematic for iOS where NFC session handling differs from Android
Proposed Fix
Add guard flag and immediate session invalidation to prevent second tag detection during the race window:
- Add
interactionCompletedflag toIosTagReaderclass - Guard against second tag detection in
didDetectTagscallback - Invalidate NFC session immediately after successful engagement for BLE transport
- Update session handling logic in
beginSessionmethod
Code Location
File: multipaz/src/iosMain/kotlin/org/multipaz/nfc/NfcTagReader.ios.kt
This affects the iOS NFC implementation in multipaz library and should be prioritized for the next release to fix NFC verification reliability issues.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status