Where a materialized entry may land: inside `dir`, and nowhere else. An entry's path arrives over a transport, and the pointer that chose `dir` is itself a file in the tree the sandbox was handed — so a path that climbs out, or names the pointer or the cache, would let whatever sent it rewrite the sandbox's trust anchor or write somewhere it was never given. Only plain relative components pass (n
(dir: &Path, path: &str)
| 201 | /// relative components pass (no `..`, no root, no empty or `.`), and none may |
| 202 | /// be `.atomic`, the pointer or the cache directory. |
| 203 | fn sandbox_entry_path(dir: &Path, path: &str) -> Result<std::path::PathBuf, RepositoryError> { |
| 204 | let refuse = |why: &str| RepositoryError::InvalidOperation { |
| 205 | message: format!("refusing materialized entry {path:?}: {why}"), |
| 206 | }; |
| 207 | let relative = Path::new(path); |
| 208 | if relative.as_os_str().is_empty() { |
| 209 | return Err(refuse("empty path")); |
| 210 | } |
| 211 | if !relative.is_relative() { |
| 212 | return Err(refuse("not a relative path")); |
| 213 | } |
| 214 | for part in relative.components() { |
| 215 | let std::path::Component::Normal(name) = part else { |
| 216 | return Err(refuse("not a plain relative path")); |
| 217 | }; |
| 218 | if name == crate::DOT_DIR |
| 219 | || name == super::SANDBOX_POINTER |
| 220 | || name == super::SANDBOX_CACHE_DIR |
| 221 | { |
| 222 | return Err(refuse("names the sandbox's own bookkeeping")); |
| 223 | } |
| 224 | } |
| 225 | Ok(dir.join(relative)) |
| 226 | } |
| 227 | |
| 228 | /// The parent a write lands in, checked to still be inside `dir` after the |
| 229 | /// filesystem has resolved symlinks — a parts check cannot see a parent that |