This commit is contained in:
Mateusz Gruszczyński committed 2026-10-04 16:47:24 +02:00
1 parent 59ddabb72b
commit 174389e5b1
48 files changed
+688 -212

No files matched your search

+27 -4
View File
@@ -16,7 +16,7 @@ const BACKUP_MAGIC: &[u8; 8] = b"RPROXYB1";
const ARCHIVE_MAGIC: &[u8; 8] = b"RPROXYA1";
const KEY_MAGIC: &[u8; 4] = b"RPK1";
const FORMAT_VERSION: u32 = 1;
const ARCHIVE_VERSION: u32 = 1;
const ARCHIVE_VERSION: u32 = 2;
const CHUNK_SIZE: usize = 1024 * 1024;
const ARGON_MEMORY_KIB: u32 = 64 * 1024;
const ARGON_ITERATIONS: u32 = 3;
@@ -56,11 +56,29 @@ struct Manifest {
entries: Vec<ManifestEntry>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
enum EntryKind {
File,
Directory,
Symlink,
}
impl Default for EntryKind {
fn default() -> Self {
Self::File
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct ManifestEntry {
path: String,
size: u64,
sha256: String,
#[serde(default, skip_serializing_if = "is_file_entry")]
kind: EntryKind,
}
fn is_file_entry(kind: &EntryKind) -> bool {
*kind == EntryKind::File
}
enum EntrySource {
@@ -121,9 +139,14 @@ fn validate_backup_version(version: &str) -> Result<()> {
Ok(())
}
fn harden_tree(path: &Path) -> Result<()> {
fn harden_tree(root: &Path, path: &Path) -> Result<()> {
let metadata = fs::symlink_metadata(path)?;
ensure!(!metadata.file_type().is_symlink(), "restore staging contains a symlink");
if metadata.file_type().is_symlink() {
let resolved = fs::canonicalize(path).context("restored symlink target is missing")?;
let canonical_root = fs::canonicalize(root)?;
ensure!(resolved.starts_with(&canonical_root), "restored symlink escapes the data directory");
return Ok(());
}
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
@@ -132,7 +155,7 @@ fn harden_tree(path: &Path) -> Result<()> {
}
if metadata.is_dir() {
for entry in fs::read_dir(path)? {
harden_tree(&entry?.path())?;
harden_tree(root, &entry?.path())?;
}
}
Ok(())