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 4194ca06cf fix(services): reject URI hosts for local path services
(#9085)
4194ca06cf is described below
commit 4194ca06cff4e514ab79fc068ad84274f67be91c
Author: mola <[email protected]>
AuthorDate: Thu Nov 26 03:13:35 2026 +0800
fix(services): reject URI hosts for local path services (#9085)
* fix(services): reject URI hosts for local path services
cacache, compfs, monoiofs, persy, redb, sled and hf3fs build a local
path from the URI path and ignored the URI host, so `sled://tmp/data`
silently used `/data`. #9042 fixed the same problem for fs.
Reject a host other than `localhost` with ConfigInvalid unless the
caller passes the path option explicitly, matching fs. compfs and
monoiofs also let the URI path override an explicit `root` option; keep
the explicit option instead, as fs does.
* fix(services/compfs,monoiofs): keep the URI path ahead of an explicit root
Restore the behavior verified in #9044: a nonempty URI path wins over a
conflicting explicit `root` option, so `compfs:///a?root=/b` keeps using
`/a`. Because the path wins, a host next to a path is still dropped and
is rejected; a host is only ignored when the URI has no path and the
explicit `root` is used.
* chore: resynchronize pull request #9085
---------
Co-authored-by: Mola-maker <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
---
core/services/cacache/src/config.rs | 39 ++++++++++++++++++++++++++
core/services/compfs/src/config.rs | 54 ++++++++++++++++++++++++++++++++++--
core/services/hf3fs/src/config.rs | 46 ++++++++++++++++++++++++++++++
core/services/monoiofs/src/config.rs | 54 ++++++++++++++++++++++++++++++++++--
core/services/persy/src/config.rs | 39 ++++++++++++++++++++++++++
core/services/redb/src/config.rs | 39 ++++++++++++++++++++++++++
core/services/sled/src/config.rs | 39 ++++++++++++++++++++++++++
7 files changed, 304 insertions(+), 6 deletions(-)
diff --git a/core/services/cacache/src/config.rs
b/core/services/cacache/src/config.rs
index ff7d68bc0d..a7130af34e 100644
--- a/core/services/cacache/src/config.rs
+++ b/core/services/cacache/src/config.rs
@@ -39,6 +39,20 @@ impl opendal_core::Configurator for CacacheConfig {
.or_insert_with(|| format!("/{root}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // datadir: `cacache://tmp/data` would become `/data`. An explicit
+ // `datadir` option takes precedence, as for fs.
+ if !uri.options().contains_key("datadir")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "cacache uri must not contain a host, use cacache:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -72,4 +86,29 @@ mod tests {
let cfg = CacacheConfig::from_uri(&uri).unwrap();
assert_eq!(cfg.datadir.as_deref(), Some("/tmp/cache"));
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("cacache://tmp/data", no_opts()).unwrap();
+ let err = CacacheConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("cacache://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ CacacheConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/data")
+ );
+
+ // An explicit `datadir` option takes precedence over the host.
+ let uri = OperatorUri::new(
+ "cacache://tmp/data",
+ [("datadir".to_string(), "/explicit".to_string())],
+ )
+ .unwrap();
+ assert_eq!(
+ CacacheConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/explicit")
+ );
+ }
}
diff --git a/core/services/compfs/src/config.rs
b/core/services/compfs/src/config.rs
index 275048e50d..2da9837cdb 100644
--- a/core/services/compfs/src/config.rs
+++ b/core/services/compfs/src/config.rs
@@ -35,12 +35,26 @@ impl opendal_core::Configurator for CompfsConfig {
fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self>
{
let mut map = uri.options().clone();
- if let Some(root) = uri.root()
- && !root.is_empty()
- {
+ let uri_path = uri.root().filter(|root| !root.is_empty());
+ if let Some(root) = uri_path {
map.insert("root".to_string(), uri_path_to_root(root));
}
+ // A local path has no host. Ignoring one would silently move the
+ // root: `compfs://tmp/data` would become `/data`. The URI path wins
+ // over an explicit `root` option, so a host is only ignored when the
+ // URI has no path and the explicit `root` is used.
+ if (uri_path.is_some() || !uri.options().contains_key("root"))
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "compfs uri must not contain a host, use compfs:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -99,4 +113,38 @@ mod tests {
let expected = if cfg!(windows) { "C:/" } else { "/C:" };
assert_eq!(cfg.root.as_deref(), Some(expected));
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("compfs://tmp/data", no_opts()).unwrap();
+ let err = CompfsConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("compfs://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ CompfsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/data")
+ );
+
+ // The URI path wins over an explicit `root`, so a host next to a path
+ // is still dropped and rejected. It is only ignored when the URI has
+ // no path and the explicit `root` is used.
+ let explicit_root = || [("root".to_string(), "/explicit".to_string())];
+ let uri = OperatorUri::new("compfs://tmp/data",
explicit_root()).unwrap();
+ assert!(CompfsConfig::from_uri(&uri).is_err());
+ let uri = OperatorUri::new("compfs://tmp", explicit_root()).unwrap();
+ assert_eq!(
+ CompfsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/explicit")
+ );
+
+ // Without a host, a nonempty URI path still wins over a conflicting
+ // explicit `root`, as verified in #9044.
+ let uri = OperatorUri::new("compfs:///a?root=/b", no_opts()).unwrap();
+ assert_eq!(
+ CompfsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/a")
+ );
+ }
}
diff --git a/core/services/hf3fs/src/config.rs
b/core/services/hf3fs/src/config.rs
index 1dc55406ed..f03436a8a0 100644
--- a/core/services/hf3fs/src/config.rs
+++ b/core/services/hf3fs/src/config.rs
@@ -46,6 +46,20 @@ impl Configurator for Hf3fsConfig {
.entry("root".into())
.or_insert_with(|| format!("/{root}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // root: `hf3fs://tmp/data` would become `/data`. An explicit
+ // `root` option takes precedence, as for fs.
+ if !uri.options().contains_key("root")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "hf3fs uri must not contain a host, use hf3fs:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(options)
}
@@ -53,3 +67,35 @@ impl Configurator for Hf3fsConfig {
Hf3fs { config: self }
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use opendal_core::Configurator;
+ use opendal_core::OperatorUri;
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("hf3fs://tmp/data", no_opts()).unwrap();
+ let err = Hf3fsConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("hf3fs://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ Hf3fsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/data")
+ );
+
+ // An explicit `root` option takes precedence over the host.
+ let uri = OperatorUri::new(
+ "hf3fs://tmp/data",
+ [("root".to_string(), "/explicit".to_string())],
+ )
+ .unwrap();
+ assert_eq!(
+ Hf3fsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/explicit")
+ );
+ }
+}
diff --git a/core/services/monoiofs/src/config.rs
b/core/services/monoiofs/src/config.rs
index 6cb6765d12..15f10ad582 100644
--- a/core/services/monoiofs/src/config.rs
+++ b/core/services/monoiofs/src/config.rs
@@ -40,12 +40,26 @@ impl Configurator for MonoiofsConfig {
fn from_uri(uri: &OperatorUri) -> Result<Self> {
let mut map = uri.options().clone();
- if let Some(root) = uri.root()
- && !root.is_empty()
- {
+ let uri_path = uri.root().filter(|root| !root.is_empty());
+ if let Some(root) = uri_path {
map.insert("root".to_string(), format!("/{root}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // root: `monoiofs://tmp/data` would become `/data`. The URI path wins
+ // over an explicit `root` option, so a host is only ignored when the
+ // URI has no path and the explicit `root` is used.
+ if (uri_path.is_some() || !uri.options().contains_key("root"))
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "monoiofs uri must not contain a host, use monoiofs:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -66,4 +80,38 @@ mod tests {
assert_eq!(cfg.root.as_deref(), Some("/tmp"));
Ok(())
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("monoiofs://tmp/data", no_opts()).unwrap();
+ let err = MonoiofsConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("monoiofs://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ MonoiofsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/data")
+ );
+
+ // The URI path wins over an explicit `root`, so a host next to a path
+ // is still dropped and rejected. It is only ignored when the URI has
+ // no path and the explicit `root` is used.
+ let explicit_root = || [("root".to_string(), "/explicit".to_string())];
+ let uri = OperatorUri::new("monoiofs://tmp/data",
explicit_root()).unwrap();
+ assert!(MonoiofsConfig::from_uri(&uri).is_err());
+ let uri = OperatorUri::new("monoiofs://tmp", explicit_root()).unwrap();
+ assert_eq!(
+ MonoiofsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/explicit")
+ );
+
+ // Without a host, a nonempty URI path still wins over a conflicting
+ // explicit `root`, as verified in #9044.
+ let uri = OperatorUri::new("monoiofs:///a?root=/b",
no_opts()).unwrap();
+ assert_eq!(
+ MonoiofsConfig::from_uri(&uri).unwrap().root.as_deref(),
+ Some("/a")
+ );
+ }
}
diff --git a/core/services/persy/src/config.rs
b/core/services/persy/src/config.rs
index 53d47b2f59..027378cdd0 100644
--- a/core/services/persy/src/config.rs
+++ b/core/services/persy/src/config.rs
@@ -46,6 +46,20 @@ impl opendal_core::Configurator for PersyConfig {
.or_insert_with(|| format!("/{path}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // datafile: `persy://tmp/data` would become `/data`. An explicit
+ // `datafile` option takes precedence, as for fs.
+ if !uri.options().contains_key("datafile")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "persy uri must not contain a host, use persy:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -73,4 +87,29 @@ mod tests {
assert_eq!(cfg.segment.as_deref(), Some("segment"));
assert_eq!(cfg.index.as_deref(), Some("index"));
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("persy://tmp/data", no_opts()).unwrap();
+ let err = PersyConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("persy://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ PersyConfig::from_uri(&uri).unwrap().datafile.as_deref(),
+ Some("/data")
+ );
+
+ // An explicit `datafile` option takes precedence over the host.
+ let uri = OperatorUri::new(
+ "persy://tmp/data",
+ [("datafile".to_string(), "/explicit".to_string())],
+ )
+ .unwrap();
+ assert_eq!(
+ PersyConfig::from_uri(&uri).unwrap().datafile.as_deref(),
+ Some("/explicit")
+ );
+ }
}
diff --git a/core/services/redb/src/config.rs b/core/services/redb/src/config.rs
index 3135668470..a5c35a3fb9 100644
--- a/core/services/redb/src/config.rs
+++ b/core/services/redb/src/config.rs
@@ -46,6 +46,20 @@ impl opendal_core::Configurator for RedbConfig {
.or_insert_with(|| format!("/{path}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // datadir: `redb://tmp/data` would become `/data`. An explicit
+ // `datadir` option takes precedence, as for fs.
+ if !uri.options().contains_key("datadir")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "redb uri must not contain a host, use redb:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -76,4 +90,29 @@ mod tests {
assert_eq!(cfg.table.as_deref(), Some("op_table"));
assert_eq!(cfg.root.as_deref(), Some("cache"));
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("redb://tmp/data", no_opts()).unwrap();
+ let err = RedbConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("redb://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ RedbConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/data")
+ );
+
+ // An explicit `datadir` option takes precedence over the host.
+ let uri = OperatorUri::new(
+ "redb://tmp/data",
+ [("datadir".to_string(), "/explicit".to_string())],
+ )
+ .unwrap();
+ assert_eq!(
+ RedbConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/explicit")
+ );
+ }
}
diff --git a/core/services/sled/src/config.rs b/core/services/sled/src/config.rs
index 6ea2d662cb..0ebeb6401f 100644
--- a/core/services/sled/src/config.rs
+++ b/core/services/sled/src/config.rs
@@ -57,6 +57,20 @@ impl opendal_core::Configurator for SledConfig {
.or_insert_with(|| format!("/{path}"));
}
+ // A local path has no host. Ignoring one would silently move the
+ // datadir: `sled://tmp/data` would become `/data`. An explicit
+ // `datadir` option takes precedence, as for fs.
+ if !uri.options().contains_key("datadir")
+ && let Some(host) = uri.name()
+ && !host.eq_ignore_ascii_case("localhost")
+ {
+ return Err(opendal_core::Error::new(
+ opendal_core::ErrorKind::ConfigInvalid,
+ "sled uri must not contain a host, use sled:///path",
+ )
+ .with_context("host", host));
+ }
+
Self::from_iter(map)
}
@@ -84,4 +98,29 @@ mod tests {
assert_eq!(cfg.tree.as_deref(), Some("cache"));
assert_eq!(cfg.root.as_deref(), Some("items"));
}
+
+ #[test]
+ fn from_uri_rejects_host() {
+ let no_opts = Vec::<(String, String)>::new;
+ let uri = OperatorUri::new("sled://tmp/data", no_opts()).unwrap();
+ let err = SledConfig::from_uri(&uri).unwrap_err();
+ assert_eq!(err.kind(), opendal_core::ErrorKind::ConfigInvalid);
+
+ let uri = OperatorUri::new("sled://localhost/data",
no_opts()).unwrap();
+ assert_eq!(
+ SledConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/data")
+ );
+
+ // An explicit `datadir` option takes precedence over the host.
+ let uri = OperatorUri::new(
+ "sled://tmp/data",
+ [("datadir".to_string(), "/explicit".to_string())],
+ )
+ .unwrap();
+ assert_eq!(
+ SledConfig::from_uri(&uri).unwrap().datadir.as_deref(),
+ Some("/explicit")
+ );
+ }
}