- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
",t};e.buildCustomizationMenuUi=t;function n(e){let t='
",t}function s(e){let n=e.filter.currentValue||e.filter.defaultValue,t='${e.filter.label}
`,e.filter.options.forEach(s=>{let o=s.id===n;t+=``}),t+="${e.filter.label}
`,t+=`ID: swift-security/weak-keychain
Language: Unknown
Severity: Warning
Category: Security
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.
class keychainController: keychainViewController {
func test() {
let token = "secret"
var query = [String : AnyObject]()
query[kSecClass as String] = kSecClassGenericPassword
query[kSecValueData as String] = token as AnyObject?
query[kSecAttrAccessible as String] = kSecAttrAccessibleAlwaysThisDeviceOnly
SecItemAdd(query as CFDictionary, nil)
}
}
class keychainController: keychainViewController {
func foo3() {
let token = "secret"
var query = [String : AnyObject]()
query[kSecClass as String] = kSecClassGenericPassword
query[kSecValueData as String] = token as AnyObject?
query[kSecAttrAccessible as String] = kSecAttrAccessibleAlways
SecItemAdd(query as CFDictionary, nil)
}
}
class keychainController: keychainViewController {
func test() {
var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
kSecAttrAccount as String: account,
kSecAttrServer as String: server,
kSecValueData as String: password,
kSecAttrAccessible as String: kSecAttrAccessibleAlways]
SecItemAdd(query,r)
}
}
class keychainController: keychainViewController {
func test() {
let keychainItemQuery = [
kSecValueData: "test123".data(using: .utf8)!,
kSecClass: kSecClassGenericPassword,
kSecAttrAccessible: kSecAttrAccessibleAlwaysThisDeviceOnly
] as CFDictionary
let status = SecItemAdd(keychainItemQuery, nil)
print("Operation finished with status: \(status)")
}
}
class keychainController: keychainViewController {
func test() {
let keychainItemQuery = [
kSecValueData: "test123".data(using: .utf8)!,
kSecClass: kSecClassGenericPassword
] as CFDictionary
let status = SecItemAdd(keychainItemQuery, nil)
print("Operation finished with status: \(status)")
}
}
class keychainController: keychainViewController {
func test() {
// ok: good keychain
let keychainItemQuery = [
kSecValueData: "test123".data(using: .utf8)!,
kSecClass: kSecClassGenericPassword,
kSecAttrAccessible: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
] as CFDictionary
let status = SecItemAdd(keychainItemQuery, nil)
print("Operation finished with status: \(status)")
}
}
class keychainController: keychainViewController {
func foo7(_ data: Data, forKey key: String) {
let query: [NSString: Any] = [
kSecClass: secClass,
kSecAttrAccount: key,
kSecAttrAccessGroup: accessGroup
]
let attributes: [NSString: Any] = [
kSecValueData: data,
kSecAttrAccessible: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
]
}
}