Modernize Rust code and Fixes (#7971)

* Modernize Rust code and fix input handling

- Adopt newer std APIs, reduce allocations, and consolidate caching on Moka.
- Update the Rust toolchain and most dependencies, tighten lints, and expand test coverage.
- Fix favicon ranking for URLs with query strings or fragments, and try the next icon when SVG sanitization fails.
- Prevent panics when masking 2FA email addresses containing Unicode or missing an @.
- Prevent panics on Unicode database paths and recognize short postgres: URLs.
- Treat whitespace-only collection and member external IDs as absent and avoid redundant membership updates.
- Align stable builds’ global IP classification with Rust’s standard library.

Signed-off-by: BlackDex <black.dex@gmail.com>

* Update crates and some fixes

- Bump Rocket, rocket_ws, Diesel, SQLite bindings, and html5gum.
- Reuse WebSocket payload buffers and detect upgrades from the response.
- Match favicon rel tokens case-insensitively, honor the first base href,
  and stop scanning at the end of the head or the start of the body.

Signed-off-by: BlackDex <black.dex@gmail.com>

---------

Signed-off-by: BlackDex <black.dex@gmail.com>
This commit is contained in:
Mathijs van Veluw authored and GitHub committed 2026-11-18 22:33:23 +01:00
1 parent 4051a4d3a6
commit 4a0acc3314
51 files changed
+1219 -1569

No files matched your search

+17 -11
View File
@@ -1,7 +1,6 @@
mod query_logger;
use std::{
future::Future,
sync::{
Arc, OnceLock,
atomic::{AtomicBool, Ordering},
@@ -237,7 +236,7 @@ impl DbPool {
error!("Tried to set the active database connection type more than once.");
}
Ok(DbPool {
Ok(Self {
pool: Some(pool),
semaphore: Arc::new(Semaphore::new(max_conns as usize)),
})
@@ -268,25 +267,25 @@ impl DbPool {
impl DbConnType {
pub fn from_url(url: &str) -> Result<Self, Error> {
// Mysql
if url.len() > 6 && &url[..6] == "mysql:" {
if url.starts_with("mysql:") {
#[cfg(mysql)]
return Ok(DbConnType::Mysql);
return Ok(Self::Mysql);
#[cfg(not(mysql))]
err!("`DATABASE_URL` is a MySQL URL, but the 'mysql' feature is not enabled")
// Postgresql
} else if url.len() > 11 && (&url[..11] == "postgresql:" || &url[..9] == "postgres:") {
} else if url.starts_with("postgresql:") || url.starts_with("postgres:") {
#[cfg(postgresql)]
return Ok(DbConnType::Postgresql);
return Ok(Self::Postgresql);
#[cfg(not(postgresql))]
err!("`DATABASE_URL` is a PostgreSQL URL, but the 'postgresql' feature is not enabled")
// Sqlite (explicit)
} else if url.len() > 7 && &url[..7] == "sqlite:" {
} else if url.starts_with("sqlite:") {
#[cfg(sqlite)]
return Ok(DbConnType::Sqlite);
return Ok(Self::Sqlite);
#[cfg(not(sqlite))]
err!("`DATABASE_URL` is a SQLite URL, but the 'sqlite' feature is not enabled")
@@ -297,7 +296,7 @@ impl DbConnType {
#[cfg(sqlite)]
{
if std::path::Path::new(url).exists() {
return Ok(DbConnType::Sqlite);
return Ok(Self::Sqlite);
}
err!(format!(
"`DATABASE_URL` does not match any known database scheme (mysql://, postgresql://, sqlite://) \
@@ -438,8 +437,6 @@ pub mod models;
/// MySQL/MariaDB and PostgreSQL are not supported.
#[cfg(sqlite)]
pub fn backup_sqlite() -> Result<String, Error> {
use diesel::Connection;
let db_url = CONFIG.database_url();
if DbConnType::from_url(&CONFIG.database_url()).is_ok_and(|t| t == DbConnType::Sqlite) {
// Strip the sqlite:// prefix if present to get the raw file path
@@ -614,6 +611,15 @@ pub mod test_db {
.args(["--exact", std::thread::current().name().unwrap(), "--nocapture"])
.env("VAULTWARDEN_ISOLATED_CONFIG_TEST", "1")
.env("DATABASE_URL", "sqlite://:memory:")
// Keep a local `.env` out of the tests, such as SMTP settings that would send mail
.env(
"ENV_FILE",
if cfg!(windows) {
"NUL"
} else {
"/dev/null"
},
)
.output()
.unwrap();
assert!(