Add walking up parent directories when loading dotenv files#4147
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the SQLCipher “dotenv” auto-unlock flow by extending the .env lookup beyond the database’s directory: it now walks up parent directories until it finds a matching password entry for the database filename. This builds on the earlier dotenv-based encrypted DB opening work referenced in PR #1404.
Changes:
- Add
QSettingsinclude to support reading.envfiles. - Replace single-directory
.envlookup with a parent-directory search loop, stopping once a matching password entry is found.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @mgrojo,
Ish. I have some encrypted databases in an iOS app, and running it in the Simulator places the databases in a deeply nested location under
True, good catch! I now realize that other tools with a similar feature have their own custom naming for these files (they're also configs, not secret holders).
Makes sense! But, with the above, what do you think of searching for |
|
While I understand the use case here as well, I do not think that this is the right approach. Especially with deeply nested file hierarchies, this is some unnecessary overhead, apart from the fact that at some level the permissions might not even be available anymore. For this use case, it seems like letting the environment load the |
Hmm, true 🤔 What about using @mgrojo's suggestion and add a new user preference for enabling this traversal, which would be turned off by default?
This is not supported at the moment, as we're not actually reading from the environment itself, but we actually manually load the But, even if we did, it wouldn't help with the use case of the user simply double-clicking an encrypted database file, right? |
It is used to load the dotenv file.
Previously, only a `.env` file next to the database was checked. Now parent directories are searched until a matching password entry is found. Related-to: 3cdc65a Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Use a local .db4s.env when present, otherwise preserve legacy local .env lookup before walking parents for .db4s.env. Co-authored-by: Cursor <cursoragent@cursor.com>
Expose an opt-in setting for walking parent folders when searching for DB4S SQLCipher dotenv files. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep parent .db4s.env searching opt-in so encrypted database opens avoid unnecessary directory walking by default. Co-authored-by: Cursor <cursoragent@cursor.com>
70f0f22 to
23806c6
Compare
|
@mgrojo, @FriedrichFroebel, would you please re-review this following the recent changes I (we 😅) made? 🙏🏻 |
I guess it depends on the environment how these variables might be passed around, but I agree that double-clicking might not work then. Using a setting can work, yes.
I will leave this up to Manuel, as he is much more experienced with the actual code then I am. |
|
@mgrojo, would you some some time to review the latest changes? 🙏🏻 |
|
It looks good to me. Merging. @revolter, would you mind updating https://github.com/sqlitebrowser/sqlitebrowser/wiki/Encrypted-Databases#bypass-the-password-prompt-using-a-dotenv-file with the changes? |

Previously, only a
.envfile next to the database was checked.Now parent directories are searched until a matching password entry
is found.
Related-to: 3cdc65a (#1404).