Keep temporary data in memory unless SQLITE_TEMP_STORE is set - #271
Conversation
Temporary files are not encrypted (see utelle#148), so the documentation recommends SQLITE_TEMP_STORE=2 or 3. The build files set it to 2, but the source didn't, so builds of the amalgamation with other build scripts got SQLite's default 1, which writes temporary data to disk in plaintext. Define SQLITE_TEMP_STORE as 2 before including SQLite if it is not set. An explicit value is kept, and PRAGMA temp_store works as before.
|
Hi Markus,
Correct. Unfortunately, I haven't found a (reasonable) way to force encryption for temporary SQLite files in case of an encrypted main database.
I fully agree that this is anything but ideal. And unfortunately, few people read the documentation. So, it seems one has to force people to be happy sometimes.
Good idea. And it should have been applied much earlier. But better late than never.
Yes, absolutely.
If the option was set intentionally, it should be respected.
No, I think it is a good thing to set However, I would prefer to have these preprocessor statements further up in the source file |
Settings that deviate from SQLite's defaults should be easy to find, so the block now follows the file header. The comment also explains the possible values.
|
Hi Ulrich, thanks! I moved the block to the beginning of Best regards, |
|
Hi Markus,
Perfect! Thanks! |
Hi Ulrich,
a small follow-up to #148.
Type: Enhancement (security hardening)
The problem
Temporary files (temporary tables, sorter files, transient databases) are not encrypted, as discussed in #148. The documentation therefore strongly recommends
SQLITE_TEMP_STORE=2or3.The build files of SQLite3 Multiple Ciphers set
SQLITE_TEMP_STORE=2, but the source itself doesn't define it. So the setting doesn't apply when the amalgamation (orsrc/sqlite3mc.c) is compiled with other build scripts, as many packages do. Without the flag, SQLite's default1applies, and temporary data is written to disk in plaintext. Of ten projects I looked at that compile SQLite3 Multiple Ciphers themselves, four don't set it; one of them setsPRAGMA temp_store=MEMORYat runtime instead.The change
If
SQLITE_TEMP_STOREis not defined,sqlite3mc.cnow defines it as2before including SQLite. The amalgamation then behaves the same as the builds from the build files, whatever it is built with. An explicit value, including1, is kept, andPRAGMA temp_storeworks as before.What do you think?
Would this be a good idea for you? SQLCipher goes further: since March 2025 its build stops unless
SQLITE_TEMP_STOREis2or3. I chose the softer default so that builds that set1on purpose keep working. If you'd rather have an error like that, or prefer to leave this to the build files as before, that's fine with me too.How I tested it
I built the shell from
src/sqlite3mc.cwithout settingSQLITE_TEMP_STORE, filled a temporary table with a marker and searched the open temporary files of the process for it (Linux,/proc/<pid>/fd):TEMP_STOREmain(8392d70), no flag-DSQLITE_TEMP_STORE=1-DSQLITE_TEMP_STORE=3scripts/amalgamate.pywith this change, no flagThe build files already set
SQLITE_TEMP_STORE=2, so builds made with them don't change.Best regards,
Markus