Description
.noFileProtection, FileProtectionType.none and NSFileProtectionNone still encrypt the file using the device UID. Access does not depend on the user's passcode or lock state, so the file may be accessible while the device is locked or just after startup.
Potential impact
- Exposure of stored sensitive information.
- Data disclosure through backup or device extraction paths.
- Increased risk of file access on a lost or stolen device.
Remediation
- Write sensitive files with
.completeFileProtection. Avoid disabling protection withFileProtectionType.noneorNSFileProtectionNoneinFileManager.setAttributes. - If a background task needs the file while the device is locked, choose the most restrictive class that allows that access. Store secret values in Keychain.
Examples
Before
swift
try data.write(to: url, options: .noFileProtection)
After
swift
try data.write(to: url, options: .completeFileProtection)
With .completeFileProtection, the file becomes unreadable once the device discards the protection key after locking. It becomes readable again when the user unlocks the device.