feat: add option --allow-hash to allow/disallow file hashing (#657)

This commit is contained in:
sigoden
2026-01-09 16:43:18 +08:00
committed by GitHub
parent ca18df1a36
commit 2b2c7bd5f7
4 changed files with 28 additions and 2 deletions

View File

@@ -148,6 +148,14 @@ pub fn build_cli() -> Command {
.action(ArgAction::SetTrue)
.help("Allow download folders as archive file"),
)
.arg(
Arg::new("allow-hash")
.env("DUFS_ALLOW_HASH")
.hide_env(true)
.long("allow-hash")
.action(ArgAction::SetTrue)
.help("Allow ?hash query to get file sha256 hash"),
)
.arg(
Arg::new("enable-cors")
.env("DUFS_ENABLE_CORS")
@@ -281,6 +289,7 @@ pub struct Args {
pub allow_search: bool,
pub allow_symlink: bool,
pub allow_archive: bool,
pub allow_hash: bool,
pub render_index: bool,
pub render_spa: bool,
pub render_try_index: bool,
@@ -375,6 +384,9 @@ impl Args {
if !args.allow_symlink {
args.allow_symlink = allow_all || matches.get_flag("allow-symlink");
}
if !args.allow_hash {
args.allow_hash = allow_all || matches.get_flag("allow-hash");
}
if !args.allow_archive {
args.allow_archive = allow_all || matches.get_flag("allow-archive");
}

View File

@@ -358,7 +358,11 @@ impl Server {
self.handle_edit_file(path, DataKind::View, head_only, user, &mut res)
.await?;
} else if has_query_flag(&query_params, "hash") {
self.handle_hash_file(path, head_only, &mut res).await?;
if self.args.allow_hash {
self.handle_hash_file(path, head_only, &mut res).await?;
} else {
status_forbid(&mut res);
}
} else {
self.handle_send_file(path, headers, head_only, &mut res)
.await?;