Ce produit n'est pas pris en charge pour le site Datadog que vous avez sélectionné. ().
Cette page n'est pas encore disponible en français. Nous travaillons sur sa traduction. Si vous avez des questions ou des commentaires concernant notre projet de traduction actuel, n'hésitez pas à nous contacter !
This rule detects the use of weak keychain accessibility settings that can expose sensitive data to attackers. Using overly permissive accessibility constants like kSecAttrAccessibleAlways or kSecAttrAccessibleAlwaysThisDeviceOnly allows keychain items to be accessed even when the device is locked or without user authentication, increasing the risk of unauthorized data retrieval.
It is important to protect secret data stored in the keychain by limiting access to when the device is unlocked and ensuring the highest possible security level. Weak accessibility settings can undermine the security guarantees that the keychain provides, making sensitive information vulnerable to compromise if the device is lost or stolen.
To comply with this rule, developers should use strong accessibility constants such as kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly or kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly. These settings enforce stricter access controls, requiring the device to be unlocked or a passcode to be set before keychain items can be accessed. For example, use kSecAttrAccessible: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly when adding or updating keychain items to ensure robust protection.
classkeychainController:keychainViewController{functest(){letkeychainItemQuery=[kSecValueData:"test123".data(using:.utf8)!,kSecClass:kSecClassGenericPassword,kSecAttrAccessible:kSecAttrAccessibleAlwaysThisDeviceOnly]asCFDictionaryletstatus=SecItemAdd(keychainItemQuery,nil)print("Operation finished with status: \(status)")}}
Compliant Code Examples
classkeychainController:keychainViewController{functest(){letkeychainItemQuery=[kSecValueData:"test123".data(using:.utf8)!,kSecClass:kSecClassGenericPassword]asCFDictionaryletstatus=SecItemAdd(keychainItemQuery,nil)print("Operation finished with status: \(status)")}}
classkeychainController:keychainViewController{functest(){// ok: good keychainletkeychainItemQuery=[kSecValueData:"test123".data(using:.utf8)!,kSecClass:kSecClassGenericPassword,kSecAttrAccessible:kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly]asCFDictionaryletstatus=SecItemAdd(keychainItemQuery,nil)print("Operation finished with status: \(status)")}}