Add walking up parent directories when loading dotenv files by revolter · Pull Request #4147 · sqlitebrowser/sqlitebrowser · GitHub
Skip to content

Add walking up parent directories when loading dotenv files#4147

Merged
mgrojo merged 9 commits into
sqlitebrowser:masterfrom
revolter:feature/sqlcipher-passwords-walk-parents
Jun 21, 2026
Merged

Add walking up parent directories when loading dotenv files#4147
mgrojo merged 9 commits into
sqlitebrowser:masterfrom
revolter:feature/sqlcipher-passwords-walk-parents

Conversation

@revolter

@revolter revolter commented Jun 6, 2026

Copy link
Copy Markdown
Member

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 (#1404).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 QSettings include to support reading .env files.
  • Replace single-directory .env lookup 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.

Comment thread src/sqlitedb.cpp Outdated
@mgrojo

mgrojo commented Jun 8, 2026

Copy link
Copy Markdown
Member

@revolter

revolter commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Hi @mgrojo,

I assume your use case is that you have several database files in subdirectories, and a single .env file applicable to all of them in the parent directory or in the project root.

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 ~/Library, and it also changes on every subsequent run. As such, I want to place the .env file in the root folder to be picked up regardless.

But what happens if we load in memory a .env file which wasn't for us and contains other secrets.

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).

At least, I think this behaviour should be opt-in through a setting in the preferences' dialog.

Makes sense!

But, with the above, what do you think of searching for .db4s.env outside the current folder, and for .env OR .db4s.env? This way, whenever you see a dotenv file with NO database next to it, you know what's it about, we don't risk clashes with other software, and we could deprecate the non-specific file name in the future.

@FriedrichFroebel

Copy link
Copy Markdown
Contributor

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 .env file into environment variables and allowing DB4S to read them (I am not sure whether this might already be supported) seems like the most straightforward approach where each user can choose the preferred way to achieve the loading.

@revolter

Copy link
Copy Markdown
Member Author

Hi @FriedrichFroebel,

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.

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?

For this use case, it seems like letting the environment load the .env file into environment variables and allowing DB4S to read them (I am not sure whether this might already be supported) seems like the most straightforward approach where each user can choose the preferred way to achieve the loading.

This is not supported at the moment, as we're not actually reading from the environment itself, but we actually manually load the .env file and read from it.

But, even if we did, it wouldn't help with the use case of the user simply double-clicking an encrypted database file, right?

revolter and others added 9 commits June 12, 2026 09:26
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>
@revolter revolter force-pushed the feature/sqlcipher-passwords-walk-parents branch from 70f0f22 to 23806c6 Compare June 12, 2026 06:26
@revolter

Copy link
Copy Markdown
Member Author

@mgrojo, @FriedrichFroebel, would you please re-review this following the recent changes I (we 😅) made? 🙏🏻

@FriedrichFroebel

Copy link
Copy Markdown
Contributor

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?
[...]
But, even if we did, it wouldn't help with the use case of the user simply double-clicking an encrypted database file, right?

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.

would you please re-review this following the recent changes

I will leave this up to Manuel, as he is much more experienced with the actual code then I am.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/sqlitedb.cpp
@revolter

Copy link
Copy Markdown
Member Author

@mgrojo, would you some some time to review the latest changes? 🙏🏻

@mgrojo

mgrojo commented Jun 21, 2026

Copy link
Copy Markdown
Member

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?

@mgrojo mgrojo merged commit 7b8a109 into sqlitebrowser:master Jun 21, 2026
23 checks passed
@revolter

Copy link
Copy Markdown
Member Author

@revolter revolter deleted the feature/sqlcipher-passwords-walk-parents branch June 21, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants