mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-07-15 18:12:14 -05:00
[PR #7061] [MERGED] Reject unrecognised DATABASE_URL instead of silent SQLite fallback #26085
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/dani-garcia/vaultwarden/pull/7061
Author: @mfw78
Created: 4/7/2026
Status: ✅ Merged
Merged: 5/16/2026
Merged by: @BlackDex
Base:
main← Head:fix/sqlite-fallback-panic📝 Commits (3)
32907bdPanic on unrecognised DATABASE_URL instead of silent SQLite fallbacke159210Use err!() instead of panic!() for unrecognised DATABASE_URLb68fb30Use 'scheme' instead of 'prefix' in DATABASE_URL messages📊 Changes
3 files changed (+44 additions, -20 deletions)
View changed files
📝
.env.template(+5 -4)📝
src/config.rs(+12 -9)📝
src/db/mod.rs(+27 -7)📄 Description
Summary
When
DATABASE_URLdoes not matchmysql:orpostgresql:, vaultwarden silently treats it as a SQLite file path. Any misconfiguration (typo, quoting issue, garbage value) quietly creates an empty SQLite database instead of erroring. In containerised environments this means data loss on restart, which has bitten me personally and others (#2835, #1910, #860).The partial fix in #2873 catches some cases by checking the parent directory, but does not help when the path resolves within an existing directory.
The core issue is that SQLite selection is implicit. Database selection for a secrets manager should be explicit, not a fallback. An operator who misconfigures their database URL should get a clear error, not a silent downgrade to a different database engine entirely.
Changes
DbConnType::from_urlnow recognises an explicitsqlite:scheme. URLs without any recognised scheme are still accepted as bare-path SQLite for backwards compatibility, but only if the file already exists. Otherwise the process panics with a clear message.DATABASE_URLchanged tosqlite://{data_folder}/db.sqlite3so new deployments use the explicit scheme.backup_sqliteandvalidate_configupdated to handle thesqlite://prefix..env.templateupdated accordingly.Test plan
DATABASE_URL=data/db.sqlite3(file exists) still worksfoobar) panics with a helpful messagesqlite://prefixFixes #7062
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.