Skip to content

Commit c6cbfe3

Browse files
committed
fix(ios): run SecItemCopyMatching on main thread and refine auth cancel handling
- Replace direct SecItemCopyMatching calls with performCopyMatching that ensures the Sec API is invoked on the main thread. - Stop treating errSecInteractionNotAllowed as a user cancellation; only errSecUserCanceled is considered a cancellation. chore(package): update/normalize keywords in package.json
1 parent 7f358bd commit c6cbfe3

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

ios/HybridSensitiveInfo.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ final class HybridSensitiveInfo: HybridSensitiveInfoSpec {
267267

268268
private func copyMatching(query: [String: Any], prompt: AuthenticationPrompt?) throws -> AnyObject? {
269269
var result: CFTypeRef?
270-
var status = SecItemCopyMatching(query as CFDictionary, &result)
270+
var status = performCopyMatching(query as CFDictionary, result: &result)
271271

272272
if status == errSecInteractionNotAllowed || status == errSecAuthFailed {
273273
var authQuery = query
274274
authQuery[kSecUseOperationPrompt as String] = prompt?.title ?? "Authenticate to access sensitive data"
275275
let context = makeLAContext(prompt: prompt)
276276
authQuery[kSecUseAuthenticationContext as String] = context
277-
status = SecItemCopyMatching(authQuery as CFDictionary, &result)
277+
status = performCopyMatching(authQuery as CFDictionary, result: &result)
278278
}
279279

280280
switch status {
@@ -387,10 +387,22 @@ final class HybridSensitiveInfo: HybridSensitiveInfoSpec {
387387

388388
private func isAuthenticationCanceled(status: OSStatus) -> Bool {
389389
switch status {
390-
case errSecUserCanceled, errSecInteractionNotAllowed:
390+
case errSecUserCanceled:
391391
return true
392392
default:
393393
return false
394394
}
395395
}
396+
397+
private func performCopyMatching(_ query: CFDictionary, result: inout CFTypeRef?) -> OSStatus {
398+
if Thread.isMainThread {
399+
return SecItemCopyMatching(query, &result)
400+
}
401+
402+
var status: OSStatus = errSecSuccess
403+
DispatchQueue.main.sync {
404+
status = SecItemCopyMatching(query, &result)
405+
}
406+
return status
407+
}
396408
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
},
1919
"keywords": [
2020
"react-native",
21-
"react-native-sensitive-info"
21+
"secure-storage",
22+
"biometrics",
23+
"keychain",
24+
"strongbox",
25+
"nitro-modules",
26+
"sensitive-info"
2227
],
2328
"files": [
2429
"src",

0 commit comments

Comments
 (0)