Skip to content

iOS: databases are stored in the Documents directory, which can be exposed to users via the Files app #289

Description

@NicolasBonet

Problem

On iOS, when no App Group is configured, the library stores databases in the app's Documents directory:

https://github.com/margelo/react-native-nitro-sqlite/blob/main/packages/react-native-nitro-sqlite/ios/OnLoad.mm

// Get iOS app's document directory (to safely store database .sqlite3 file)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
documentPath = [paths objectAtIndex:0];

The Documents directory is exposed to users via the Files app (and iTunes/Finder file sharing) whenever the app enables UIFileSharingEnabled + LSSupportsOpeningDocumentsInPlace. That means users can see, share, modify, or delete the raw SQLite database (and its -wal/-shm journals) from outside the app — which is both a data-integrity and a data-exposure problem.

Apple's File System Programming Guide is explicit that Documents is for user-visible documents, while app-internal data files belong in Library/Application Support (persistent, backed up, never user-visible).

Proposal

Store databases in Library/Application Support instead of Documents, and migrate existing databases out of Documents so current users don't lose data.

At Expensify we hit this in production and currently ship a patch that does exactly this (including a careful migration that moves the database together with its -wal/-shm files, and falls back to the old location if the move fails): Expensify/App#96531

Happy to upstream this — PR incoming.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions