Swift Sensitive Data In External Storage
Description
Identifies instances where sensitive data might be insecurely written to external storage in Swift applications. Writing sensitive information to external storage without proper encryption or protection mechanisms can expose confidential data to unauthorized access.
Detection Strategy
• Check if the Foundation framework is imported in the Swift code
• Look for method calls ending with '.write' that perform write operations
• Verify the write operation is performed using unsafe methods or insecure file handling functions
• Confirm the write function matches known patterns for file system operations
Vulnerable code example
import Foundation
import UIKit
func savePassword(passwordField: UITextField) {
let password = passwordField.text ?? ""
let filePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
.appending(path: "password.txt", directoryHint: .notDirectory)
...✅ Secure code example
import Foundation
import UIKit
import Security
func savePassword(passwordField: UITextField) {
let password = passwordField.text ?? ""
// Store password securely in Keychain instead of plaintext file...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.