This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new af7096dcef fix(services): validate URI hosts for RocksDB and
FoundationDB (#9101)
af7096dcef is described below
commit af7096dcefa7ef60aa8ff809b0c3042133c9c4ae
Author: Xuanwo <[email protected]>
AuthorDate: Thu Nov 26 04:17:59 2026 +0800
fix(services): validate URI hosts for RocksDB and FoundationDB (#9101)
---
core/services/foundationdb/src/config.rs | 69 +++++++++++++++++++++++++++-----
core/services/rocksdb/src/config.rs | 51 +++++++++++++++++++----
2 files changed, 101 insertions(+), 19 deletions(-)
diff --git a/core/services/foundationdb/src/config.rs
b/core/services/foundationdb/src/config.rs
index f3751c19a4..40a63f7e01 100644
--- a/core/services/foundationdb/src/config.rs
+++ b/core/services/foundationdb/src/config.rs
@@ -36,6 +36,18 @@ impl opendal_core::Configurator for FoundationdbConfig {
type Builder = FoundationdbBuilder;
fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self>
{
+ // With no URI path, the builder would open the default cluster.
+ if !uri.options().contains_key("config_path")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "foundationdb uri must not contain a host, use
foundationdb:///path",
+ )
+ .with_context("host", host));
+ }
+
let mut map = uri.options().clone();
if let Some(path) = uri.root()
@@ -57,21 +69,56 @@ impl opendal_core::Configurator for FoundationdbConfig {
mod tests {
use super::*;
use opendal_core::Configurator;
+ use opendal_core::ErrorKind;
use opendal_core::OperatorUri;
+ use opendal_core::Result;
#[test]
- fn from_uri_sets_config_path_and_root() {
- let uri = OperatorUri::new(
+ fn from_uri_sets_config_path_and_root() -> Result<()> {
+ for base in [
"foundationdb:///etc/foundationdb/fdb.cluster?root=data",
- Vec::<(String, String)>::new(),
- )
- .unwrap();
+ "foundationdb://LOCALHOST/etc/foundationdb/fdb.cluster?root=data",
+ ] {
+ let uri = OperatorUri::new(base, [])?;
+ let cfg = FoundationdbConfig::from_uri(&uri)?;
+ assert_eq!(
+ cfg.config_path.as_deref(),
+ Some("/etc/foundationdb/fdb.cluster")
+ );
+ assert_eq!(cfg.root.as_deref(), Some("data"));
+ }
+ Ok(())
+ }
- let cfg = FoundationdbConfig::from_uri(&uri).unwrap();
- assert_eq!(
- cfg.config_path.as_deref(),
- Some("/etc/foundationdb/fdb.cluster")
- );
- assert_eq!(cfg.root.as_deref(), Some("data"));
+ #[test]
+ fn from_uri_rejects_host_without_config_path_option() -> Result<()> {
+ for base in [
+
"foundationdb://remote.example/etc/foundationdb/fdb.cluster?root=data",
+ "foundationdb://remote.example?root=data",
+ ] {
+ let uri = OperatorUri::new(base, [])?;
+ let err = FoundationdbConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::ConfigInvalid, "{base}");
+ }
+ Ok(())
+ }
+
+ #[test]
+ fn from_uri_preserves_explicit_config_path() -> Result<()> {
+ for (base, expected) in [
+ (
+
"foundationdb://remote.example/uri.cluster?config_path=/explicit.cluster",
+ Some("/explicit.cluster"),
+ ),
+ (
+ "foundationdb://remote.example/uri.cluster?config_path=",
+ None,
+ ),
+ ] {
+ let uri = OperatorUri::new(base, [])?;
+ let cfg = FoundationdbConfig::from_uri(&uri)?;
+ assert_eq!(cfg.config_path.as_deref(), expected);
+ }
+ Ok(())
}
}
diff --git a/core/services/rocksdb/src/config.rs
b/core/services/rocksdb/src/config.rs
index ec5d47e0e8..ba2bb66ea7 100644
--- a/core/services/rocksdb/src/config.rs
+++ b/core/services/rocksdb/src/config.rs
@@ -42,9 +42,19 @@ impl Configurator for RocksdbConfig {
if let Some(path) = uri.root()
&& !path.is_empty()
+ && !map.contains_key("datadir")
{
- map.entry("datadir".to_string())
- .or_insert_with(|| format!("/{path}"));
+ if let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(Error::new(
+ ErrorKind::ConfigInvalid,
+ "rocksdb uri must not contain a host, use rocksdb:///path",
+ )
+ .with_context("host", host));
+ }
+
+ map.insert("datadir".to_string(), format!("/{path}"));
}
Self::from_iter(map)
@@ -61,14 +71,39 @@ mod tests {
#[test]
fn from_uri_sets_datadir_and_root() -> Result<()> {
- let uri = OperatorUri::new(
+ for base in [
"rocksdb:///var/db?root=namespace",
- Vec::<(String, String)>::new(),
- )?;
+ "rocksdb://LOCALHOST/var/db?root=namespace",
+ ] {
+ let uri = OperatorUri::new(base, [])?;
+ let cfg = RocksdbConfig::from_uri(&uri)?;
+ assert_eq!(cfg.datadir.as_deref(), Some("/var/db"));
+ assert_eq!(cfg.root.as_deref(), Some("namespace"));
+ }
+ Ok(())
+ }
+
+ #[test]
+ fn from_uri_rejects_host_when_using_uri_path() -> Result<()> {
+ let uri =
OperatorUri::new("rocksdb://remote.example/var/db?root=namespace", [])?;
+ let err = RocksdbConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::ConfigInvalid);
+ Ok(())
+ }
- let cfg = RocksdbConfig::from_uri(&uri)?;
- assert_eq!(cfg.datadir.as_deref(), Some("/var/db"));
- assert_eq!(cfg.root.as_deref(), Some("namespace"));
+ #[test]
+ fn from_uri_preserves_explicit_datadir() -> Result<()> {
+ for (base, expected) in [
+ (
+ "rocksdb://remote.example/var/db?datadir=/explicit",
+ Some("/explicit"),
+ ),
+ ("rocksdb://remote.example/var/db?datadir=", None),
+ ] {
+ let uri = OperatorUri::new(base, [])?;
+ let cfg = RocksdbConfig::from_uri(&uri)?;
+ assert_eq!(cfg.datadir.as_deref(), expected);
+ }
Ok(())
}
}