logo

Database

Swift Cloud Information Compromised

Description

Detects insecure storage of sensitive information in Apple's iCloud Key-Value Storage (NSUbiquitousKeyValueStore) in Swift applications using the Vapor framework. This vulnerability could lead to exposure of sensitive data if unencrypted or unsanitized data is synchronized to iCloud.

Weakness:

020 - Non-encrypted confidential information

Category: Information Collection

Detection Strategy

    • Check if the Vapor framework is imported in the code

    • Look for calls to NSUbiquitousKeyValueStore.default.set method

    • Verify if sensitive or unsanitized data is being stored by examining the arguments passed to the set method

    • Report a vulnerability if unsafe data is being synchronized to iCloud storage

Vulnerable code example

import Foundation

func storeCredentials(username: String, password: String) {
    let defaults = UserDefaults.standard
    // Vulnerable: Storing sensitive password in plaintext
    defaults.set(password, forKey: "userPassword")
    defaults.set(username, forKey: "userName")
}

✅ Secure code example

import Foundation
import CryptoKit

func storeCredentials(username: String, password: String) {
    let defaults = UserDefaults.standard
    
    // Generate encryption key if not exists
    let key: SymmetricKey = {...