diff --git a/crates/automation/src/server.rs b/crates/automation/src/server.rs
index 7165636afb..66efd5d3b5 100644
--- a/crates/automation/src/server.rs
+++ b/crates/automation/src/server.rs
@@ -48,7 +48,7 @@ pub struct DocIndex {
#[derive(Debug, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OpenParams {
- /// Forward-slash relative path beneath the configured automation read root.
+ /// Path beneath the configured automation read root: relative (forward slashes) or absolute.
pub path: String,
}
@@ -75,7 +75,7 @@ pub struct NewParams {
#[derive(Debug, Default, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SaveParams {
- /// Forward-slash relative target beneath the configured automation write root.
+ /// Target beneath the configured automation write root: relative (forward slashes) or absolute.
/// The extension selects the format. Omit to write back to the document's own file, which
/// works only for a PSD, PSB or .pcraft file kept in its own format; any other save needs
/// `path`, so a flattened or converted copy never replaces the opened file.
diff --git a/crates/automation/src/workspace.rs b/crates/automation/src/workspace.rs
index 1e13eef0b3..930e26f57e 100644
--- a/crates/automation/src/workspace.rs
+++ b/crates/automation/src/workspace.rs
@@ -1,7 +1,7 @@
//! Capability-based filesystem policy for untrusted automation paths.
use std::io::Write;
-use std::path::{Path, PathBuf};
+use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
use cap_std::ambient_authority;
@@ -16,14 +16,19 @@ const DENIED: &str = "automation filesystem access is not granted";
#[derive(Clone)]
struct RootCapability {
dir: Arc
,
+ /// The root as an absolute path (trusted launch configuration), to recognise absolute request
+ /// paths that name a file beneath it.
+ path: PathBuf,
}
/// Separate directory capabilities for automation reads and writes.
///
/// Root paths are trusted launch-time configuration. Request paths are always
/// untrusted, forward-slash relative paths resolved by `cap-std` beneath the
-/// held directory handle. Absolute paths, parent traversal, alternate
-/// separators, Windows prefixes and empty components are rejected before I/O.
+/// held directory handle, or absolute paths whose text lies beneath the root
+/// (translated to relative ones, see [`request_path`]). Parent traversal,
+/// alternate separators, Windows prefixes and empty components are rejected
+/// before I/O.
#[derive(Clone, Default)]
pub struct AuthorizedWorkspace {
read: Option,
@@ -39,7 +44,7 @@ impl AuthorizedWorkspace {
/// Read one regular file below the configured read root.
pub fn read(&self, path: &str) -> Result, AutomationError> {
- let relative = relative_path(path)?;
+ let relative = request_path(path, self.read.as_ref())?;
let root = self.read.as_ref().ok_or_else(|| AutomationError::BadRequest(format!("{DENIED}: read authority is absent")))?;
let mut file = root.dir.open(&relative).map_err(|e| file_error("read", path, e))?;
let metadata = file.metadata().map_err(|e| file_error("read", path, e))?;
@@ -59,7 +64,7 @@ impl AuthorizedWorkspace {
/// resolution and file creation relative to the held directory handle, so
/// a non-existent final target is supported without ambient path access.
pub fn write(&self, path: &str, bytes: &[u8]) -> Result<(), AutomationError> {
- let relative = relative_path(path)?;
+ let relative = request_path(path, self.write.as_ref())?;
let root = self.write.as_ref().ok_or_else(|| AutomationError::BadRequest(format!("{DENIED}: write authority is absent")))?;
let leaf = relative.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
let parent = relative.parent().map(Path::to_path_buf).unwrap_or_default();
@@ -95,7 +100,33 @@ fn open_root(path: Option<&Path>, authority: &str) -> Result