fix(sqlite): isolate native SQLite symbols from host apps - #532
Draft
VanshKhanna wants to merge 1 commit into
Draft
fix(sqlite): isolate native SQLite symbols from host apps#532VanshKhanna wants to merge 1 commit into
VanshKhanna wants to merge 1 commit into
Conversation
This was referenced Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
WalletKit's native static library exports and references generic
sqlite3_*symbols. When an Apple host also links system SQLite, link order can select the host's unencrypted engine for WalletKit's calls. A synthetic native reproducer against unchanged 0.22.0 produces:The missing row is from
PRAGMA cipher: system SQLite does not implement it. Reversing link order selects sqlite3mc but can replace the host's SQLite too. Isolated Rust unit tests do not catch this.Removing cipher validation is not a fix: a disposable experiment without the check initialized successfully but wrote plaintext SQLite and accepted an incorrect key. No real wallet data was used or inspected.
What
walletkit_sqlite3_*wrappers and bind the existing native Rust FFI to those names. Handles and allocations stay with the engine that created them, independent of host link order.Test
Passed locally on this PR's source, with the pinned Rust 1.94.1 toolchain:
cargo test -p walletkit-sqlite -p walletkit-db --locked: 10 SQLite tests and 11 database tests pass.bash crates/walletkit-sqlite/examples/test_native_linking.sh: passes.bash crates/walletkit-sqlite/examples/test_native_linking.sh release: passes with the workspace's optimized/LTO profile.cargo clippy -p walletkit-sqlite --all-targets --all-features --locked -- -D warnings: passes.cargo fmt --all -- --check, ShellCheck, andgit diff --check: pass.make swiftlint-changed: no changed Swift files.The native tests inspect defined and undefined global archive symbols, link Apple's SQLite before and after WalletKit with dead stripping enabled, and check that the host retains its own engine. They verify encrypted persistence/reopening, wrong-key rejection, and byte preservation after failed wrong-key and plaintext-store opens. All data and keys are synthetic and temporary.
Additional supporting validation, on a separate 0.21.4 activity-backport candidate using the same isolation mechanism, not this PR head: all three release iOS archive slices built; the ARM simulator archive passed an engine-isolation probe in both link orders; a downstream World ID app build succeeded. This does not establish end-to-end account compatibility for this PR.
The local linker emits a nonfatal macOS deployment-target warning (26.5 archive versus 26.0 host); all probes pass. Linux/Android/browser CI and a full Swift build of this PR head remain to be checked.
Risk
Security-sensitive native storage/dependency change; keep this PR draft until deliberate review. Encryption parameters and serialization are not intentionally changed, but this changes which SQLite engine actually executes in host apps.