Skip to content

iOS: passphrase is interpolated unescaped into PRAGMA key / ATTACH ... KEY, and the stored passphrase uses the default Keychain accessibility #703

In review

Description

@im-diego-ec

In 8.1.1 (iOS), the passphrase is interpolated directly into SQL string literals:

  • UtilsSQLCipher.swift: PRAGMA key = '\(password)'; and PRAGMA rekey = '\(newpassword)';
  • UtilsEncryption.swift: ATTACH DATABASE ... AS encrypted KEY '\(password)'; and
    PRAGMA key = '\(password)';

A passphrase containing a single quote breaks the literal — notably SQLCipher's raw-key form
x'<64 hex>', which is the recommended way to pass a key derived elsewhere. Escaping ' as ''
(password.replacingOccurrences(of: "'", with: "''")) in those four statements fixes it.

Separately, KeychainServices.swift stores the passphrase without kSecAttrAccessible, so it gets
the default (kSecAttrAccessibleWhenUnlocked), which is included in encrypted device backups and
migrates to a new device. For a database key, kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
(set on add and on update, so existing items migrate) keeps it on the device.

We run both as a local patch; Android already uses EncryptedSharedPreferences over the Keystore and
needs no change. Happy to open a PR.

Activity

  1. added
    bug/fix
    platform: ios
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/fixplatform: ios

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions